Esquema

The simplest way to construct a common schedule is to use of the helper functions:

  • linear: Interpolació lineal entre dos Hamiltonians.

  • quadratic: Interpolació quadràtica entre dos Hamiltonians.

  • polynomial: Interpolació polinomial de grau arbitrari entre dos Hamiltonians.

  • sinusoidal: Interpolació sinusoïdal entre dos Hamiltonians.

Per exemple, per crear un esquema lineal que interpola entre un Hamiltonià conductor i un Hamiltonià de problema en un temps de 10 unitats:

from qilisdk.analog import Schedule, X, Z

H1 = X(0) + X(1)
H2 = Z(0) * Z(1)

schedule = Schedule.linear(H1, H2, 10.0)
schedule.draw()

For more complex schedules, you can use the Schedule class directly, which provides a flexible interface to fully define time-dependent Hamiltonian coefficients. The Schedule class maps time points to Hamiltonian coefficients. Coefficients can be numbers, parameters/terms, or callables of time, and you can define them at discrete points or over intervals that are sampled automatically.

Arguments principals

  • dt (float): resolució de les mostres temporals. El valor per defecte és 0.1.

  • hamiltonians (dict[str, Hamiltonian]): Mapa d’etiquetes a instàncies de Hamiltonian.

  • coefficients (dict[str, dict]): Mapping from Hamiltonian label to a time-definition dictionary. Each key is either a time point (float/parameter/term) or a 2-tuple defining an interval; each value can be:
    • el coeficient del Hamiltonià en aquell moment

    • or callable returning a coefficient. This callable can take a parameter t that will be replaced by time. Moreover, any other parameters passed to this callable need to have a default value or have their value specified in the **kwargs.

  • interpolation (Interpolation): comportament LINEAR (per defecte) o STEP entre els punts proporcionats.

  • total_time (float | Parameter | Term | None): Optional max time that rescales all time points while preserving relative positions.

Nota

Quan es col·loquen paràmetres a l’eix temporal (p. ex., com a punts temporals o extrems d’interval), l’esquema restringeix automàticament aquells paràmetres perquè es mantinguin entre els seus punts temporals veïns, de manera que l’ordre de la línia de temps continua sent vàlid.

Exemple 1: Coeficients callables amb mostreig per intervals

from qilisdk.analog import Schedule, X, Z
from qilisdk.analog.schedule import Interpolation

h_driver = X(0) + X(1)
h_problem = Z(0) * Z(1)

schedule = Schedule(
    hamiltonians={"driver": h_driver, "problem": h_problem},
    coefficients={
        "driver": {(0.0, 10.0): lambda t: 1 - t / 10.0},
        "problem": {(0.0, 10.0): lambda t: t / 10.0},
    },
    dt=0.5,
    interpolation=Interpolation.LINEAR,
)
schedule.draw()

Exemple 2: Interpolació per passos i reescalat del temps màxim

from qilisdk.analog import Schedule, Z
from qilisdk.analog.schedule import Interpolation
from qilisdk.utils.visualization.style import ScheduleStyle

h = Z(0)
schedule = Schedule(
    hamiltonians={"h": h},
    coefficients={"h": {0.0: 1.0, 5.0: 0.2}},
    dt=0.01,
    interpolation=Interpolation.STEP,
)

# Later, shorten the experiment to 3s without redefining points
schedule.draw(ScheduleStyle(title="Before Time Scaling"))
schedule.scale_max_time(3.0)
schedule.draw(ScheduleStyle(title="After Time Scaling"))
print("Time grid:", schedule.tlist)
print("Coeff at t=1.5:", schedule.coefficients["h"][1.5])

Nota

La funció draw mostra 1/dt punts de l’esquema; per tant, per augmentar la resolució del gràfic podeu reduir dt.

Esquemes parametritzats

Schedule coefficients can be symbolic, enabling classical optimization loops or experiments that scan over a family of time profiles. Coefficients can be instances of Parameter or algebraic expressions (Term) built from parameters. The schedule tracks every parameter it encounters so you can query or set them later.

from qilisdk.analog import Schedule, Z
from qilisdk.core import Parameter, GreaterThanOrEqual

gamma = Parameter("gamma", value=0.5, bounds=(0.0, 1.0))
T = Parameter("T", value=10.0, bounds=(1.0, 20.0))

schedule = Schedule(
    hamiltonians={"problem": Z(0)},
    coefficients={"problem": {(0.0, T): lambda t: gamma * t}},
    dt=0.1,
    total_time=T,
)

schedule.get_parameters()

schedule.set_parameters({"gamma": 0.7})
print(schedule.get_parameter_names())   # ['gamma', 'T']
print(schedule.get_constraints())       # [0 <= T]

Nota

Per a esquemes, Hamiltonians i interpoladors, feu servir get_parameters i els mètodes d’accés relacionats per inspeccionar l’estat dels paràmetres.