qilisdk.analog.schedule
Attributes
Classes
Builds a set of time-dependent coefficients applied to a collection of Hamiltonians. |
Module Contents
- CoeffDict[font]
- InterpDict[font]
- class Schedule(hamiltonians: dict[str, qilisdk.analog.hamiltonian.Hamiltonian] | None = None, coefficients: InterpDict | CoeffDict | None = None, dt: float = _DEFAULT_DT, total_time: qilisdk.core.interpolator.PARAMETERIZED_NUMBER | None = None, interpolation: qilisdk.core.interpolator.Interpolation = Interpolation.LINEAR)[font]
Bases:
qilisdk.core.parameterizable.ParameterizableBuilds a set of time-dependent coefficients applied to a collection of Hamiltonians.
A Schedule defines the evolution of a system by associating time steps with a set of Hamiltonian coefficients. Coefficients can be provided directly, defined as functions of time, or specified over time intervals and interpolated (step or linear).
Exemple
import numpy as np from qilisdk.analog import Schedule, X, Z T, dt = 10.0, 1.0 h1 = X(0) + X(1) + X(2) h2 = -Z(0) - Z(1) - 2 * Z(2) + 3 * Z(0) * Z(1) schedule = Schedule( dt=dt, hamiltonians={"driver": h1, "problem": h2}, coefficients={ "driver": {(0, T): lambda t: 1 - t / T}, "problem": {(0, T): lambda t: t / T}, }, ) schedule.draw()Create a Schedule that assigns time-dependent coefficients to Hamiltonians.
- Paràmetres:
hamiltonians (
dict[str,Hamiltonian] | None) – Mapping of labels to Hamiltonian objects. If omitted, an empty schedule is created.coefficients (
InterpDict | CoeffDict | None) – Per-Hamiltonian time definitions. Keys are time points or intervals; values are coefficients or callables. If anInterpolatoris supplied, it is used directly.dt (
float) – Time resolution used for sampling callable/interval definitions and plotting. Must be positive.total_time (
float | Parameter | Term | None) – Optional maximum time that rescales all defined time points proportionally.interpolation (
Interpolation) – How to interpolate between provided time points (LINEARorSTEP).
- Llença:
ValueError – if the coefficients reference an undefined hamiltonian.
- iter_time_step = 0[font]
- classmethod polynomial(initial_hamiltonian: qilisdk.analog.hamiltonian.Hamiltonian, final_hamiltonian: qilisdk.analog.hamiltonian.Hamiltonian, total_time: float, dt: float = _DEFAULT_DT, degree: int = 3) Schedule[font]
Convenience constructor for a simple polynomial annealing schedule with two Hamiltonians.
- Paràmetres:
initial_hamiltonian (
Hamiltonian) – The «driver» Hamiltonian that is dominant at the start of the anneal.final_hamiltonian (
Hamiltonian) – The «problem» Hamiltonian that is dominant at the end of the anneal.total_time (
float) – Total annealing time.dt (
float) – Time resolution used for sampling callable/interval definitions and plotting. Must be positive.degree (
int) – Degree of the polynomial interpolation. Must be at least 1. Defaults to 3.
- Retorna:
A schedule instance with polynomially interpolated coefficients for the driver and problem Hamiltonians.
- Tipus de retorn:
- Llença:
ValueError – If the degree is less than 1.
- classmethod linear(initial_hamiltonian: qilisdk.analog.hamiltonian.Hamiltonian, final_hamiltonian: qilisdk.analog.hamiltonian.Hamiltonian, total_time: float, dt: float = _DEFAULT_DT) Schedule[font]
Convenience constructor for a simple linear annealing schedule with two Hamiltonians.
- Paràmetres:
initial_hamiltonian (
Hamiltonian) – The «driver» Hamiltonian that is dominant at the start of the anneal.final_hamiltonian (
Hamiltonian) – The «problem» Hamiltonian that is dominant at the end of the anneal.total_time (
float) – Total annealing time.dt (
float) – Time resolution used for sampling callable/interval definitions and plotting. Must be positive.
- Retorna:
A schedule instance with linearly interpolated coefficients for the driver and problem Hamiltonians.
- Tipus de retorn:
- classmethod quadratic(initial_hamiltonian: qilisdk.analog.hamiltonian.Hamiltonian, final_hamiltonian: qilisdk.analog.hamiltonian.Hamiltonian, total_time: float, dt: float = _DEFAULT_DT) Schedule[font]
Convenience constructor for a simple quadratic annealing schedule with two Hamiltonians.
- Paràmetres:
initial_hamiltonian (
Hamiltonian) – The «driver» Hamiltonian that is dominant at the start of the anneal.final_hamiltonian (
Hamiltonian) – The «problem» Hamiltonian that is dominant at the end of the anneal.total_time (
float) – Total annealing time.dt (
float) – Time resolution used for sampling callable/interval definitions and plotting. Must be positive.
- Retorna:
A schedule instance with quadratically interpolated coefficients for the driver and problem Hamiltonians.
- Tipus de retorn:
- classmethod sinusoidal(initial_hamiltonian: qilisdk.analog.hamiltonian.Hamiltonian, final_hamiltonian: qilisdk.analog.hamiltonian.Hamiltonian, total_time: float, dt: float = _DEFAULT_DT) Schedule[font]
Convenience constructor for a simple sinusoidal annealing schedule with two Hamiltonians.
- Paràmetres:
initial_hamiltonian (
Hamiltonian) – The «driver» Hamiltonian that is dominant at the start of the anneal.final_hamiltonian (
Hamiltonian) – The «problem» Hamiltonian that is dominant at the end of the anneal.total_time (
float) – Total annealing time.dt (
float) – Time resolution used for sampling callable/interval definitions and plotting. Must be positive.
- Retorna:
A schedule instance with sinusoidally interpolated coefficients for the driver and problem Hamiltonians.
- Tipus de retorn:
- property hamiltonians: dict[str, qilisdk.analog.hamiltonian.Hamiltonian][font]
Return the Hamiltonians managed by the schedule.
- Retorna:
Mapping of labels to Hamiltonian instances.
- Tipus de retorn:
dict[str, Hamiltonian]
- property coefficients_dict: dict[str, dict[qilisdk.core.interpolator.PARAMETERIZED_NUMBER, qilisdk.core.interpolator.PARAMETERIZED_NUMBER]][font]
- property coefficients: dict[str, qilisdk.core.interpolator.Interpolator][font]
- property T: float[font]
Total annealing time of the schedule.
- property tlist: list[float][font]
- property dt: float[font]
- set_dt(dt: float) None[font]
Set the time resolution
dtused for sampling callable/interval definitions and plotting.- Paràmetres:
dt (
float) – New time resolution. Must be positive.- Llença:
ValueError – If
dtis not a positive float.
- property nqubits: int[font]
Maximum number of qubits affected by Hamiltonians contained in the schedule.
- scale_max_time(max_time: qilisdk.core.interpolator.PARAMETERIZED_NUMBER) None[font]
Rescale the schedule to a new maximum time while keeping relative points fixed.
- Llença:
ValueError – If the max time provided is zero.
- add_hamiltonian(label: str, hamiltonian: qilisdk.analog.hamiltonian.Hamiltonian, coefficients: qilisdk.core.interpolator.TimeDict) None[font]
- add_hamiltonian(label: str, hamiltonian: qilisdk.analog.hamiltonian.Hamiltonian, coefficients: qilisdk.core.interpolator.Interpolator) None
- update_hamiltonian(label: str, new_hamiltonian: qilisdk.analog.hamiltonian.Hamiltonian | None = None, new_coefficients: qilisdk.core.interpolator.TimeDict | None = None, interpolation: qilisdk.core.interpolator.Interpolation = Interpolation.LINEAR) None[font]
- update_hamiltonian(label: str, new_hamiltonian: qilisdk.analog.hamiltonian.Hamiltonian | None = None, new_coefficients: qilisdk.core.interpolator.Interpolator | None = None) None
- draw(style: qilisdk.utils.visualization.ScheduleStyle | None = None, filepath: str | None = None) None[font]
Render a plot of the schedule using matplotlib and optionally save it to a file.
The schedule is rendered using the provided style configuration. If
filepathis given, the resulting figure is saved to disk (the output format is inferred from the file extension, e.g..png,.pdf,.svg).- Paràmetres:
style (
ScheduleStyle, optional) – Customization options for the plot appearance. Defaults to ScheduleStyle().filepath (
str | None, optional) – If provided, saves the plot to the specified file path.
- draw_eigenvalues(style: qilisdk.utils.visualization.ScheduleStyle | None = None, filepath: str | None = None, levels: int = 50, intermediate_states: list[qilisdk.core.qtensor.QTensor] | None = None, show_overlaps: bool = False) None[font]
Render a plot of the lowest eigenvalues of the schedule’s Hamiltonians over time.
For each Hamiltonian in the schedule, as well as the total Hamiltonian, the specified number of lowest eigenvalues are computed at each time step and plotted.
- Paràmetres:
levels (
int) – The number of lowest eigenvalues to compute and plot for each Hamiltonian.style (
ScheduleStyle, optional) – Customization options for the plot appearance.filepath (
str | None, optional) – If provided, saves the plot to the specified file path.intermediate_states (
list[QTensor] | None, optional) – If provided, these states are plotted alongside the eigenvalues to show their evolution over time.show_overlaps (
bool) – Whether to annotate the plot with the overlaps between the intermediate states and the eigenstates.
- Llença:
ValueError – If the number of qubits exceeds the supported limit for eigenvalue plotting.
ValueError – If show_overlaps is True but intermediate_states is not provided.
- eig(levels: int = 50) tuple[list[list[float]], list[list[qilisdk.core.qtensor.QTensor]]][font]
Calculate the lowest eigenvalues and corresponding eigenstates of the schedule’s Hamiltonians at each time step.
- Paràmetres:
levels (
int) – The number of lowest eigenvalues and corresponding eigenstates to compute for each Hamiltonian at each time step.- Retorna:
A tuple containing two lists, the first is a list of lists of eigenvalues for each Hamiltonian at each time step, and the second is a list of lists of corresponding eigenstates as QTensors.
- Tipus de retorn:
tuple[list[list[float]], list[list[QTensor]]]
- Llença:
ValueError – If the Hamiltonian at any time step is not a valid Hamiltonian object that can be converted to a QTensor for eigenvalue computation.
- set_parameter_values(values: list[float], where: Callable[[qilisdk.core.variables.Parameter], bool] | None = None) None[font]
Assign parameter values by position and clear caches.
- Paràmetres:
values (
list[float]) – New values ordered consistently withget_parameter_names().where (
Callable[[Parameter],bool] | None) – Optional predicate selecting parameters to update.
- Llença:
ValueError – if the length of the values is not the same as the number of parameters in this object.
- set_parameters(parameters: dict[str, int | float]) None[font]
Assign parameter values by name and clear caches.
- Paràmetres:
parameters (
dict[str,int | float]) – Mapping from parameter labels to numeric values.
- set_parameter_bounds(ranges: dict[str, tuple[float, float]]) None[font]
Update parameter bounds and clear caches.
- Paràmetres:
ranges (
dict[str,tuple[float,float]]) – Bounds keyed by parameter label.