plot_cost_history

qctrlvisualizer.plot_cost_history(cost_histories: list, labels: Optional[list[str]] = None, y_axis_log: bool = False, initial_iteration: int = 1, *, figure: Optional[matplotlib.figure.Figure] = None)

Create a plot of the cost against iterations for either a single cost history or a set of cost histories.

Parameters
  • cost_histories (list) – The values of the cost histories. Must be either a list of a single cost history or a list of several cost histories, where each individual cost history is a list. For example, a single cost history can be passed (cost_histories = [0.1, 0.05, 0.02]) or multiple cost histories (cost_histories = [[0.1, 0.05, 0.02], [0.23, 0.2, 0.14, 0.1, 0.04, 0.015]]).

  • labels (list[str], optional) – The labels corresponding to the individual cost histories in cost_histories. If you provide this, it must be the same length as cost_histories.

  • y_axis_log (bool, optional) – Whether the y-axis is log-scale. Defaults to False.

  • initial_iteration (int, optional) – Where the iteration count on the x-axis starts from. This is useful if you want to include the initial cost—before optimization—at iteration 0 or if you pass cost histories that start at a later iteration. Defaults to 1.

  • figure (matplotlib.figure.Figure, optional) – A matplotlib Figure in which to place the plots. If passed, its dimensions and axes will be overridden.