Building schedules
Hamiltonian as a list of coefficients and Observables
Schedule
objects are specified using a collection of pairs of time-dependent coefficients and Observable
objects.
Time dependent coefficients are simply arithmetic expressions (built from Variable
), with a possible open parameter representing the time dependence (usually a variable t
).
This collection of pairs is called a “drive”.
Here is a simple example that constructs a schedule containing the time-dependent Hamiltonian:
from qat.core import Variable, Schedule, Observable, Term
t_variable = Variable("t")
schedule = Schedule(drive=[(1 - t_variable, Observable(1, pauli_terms=[Term(1, 'Z', [0])])),
(t_variable, Observable(1, pauli_terms=[Term(1, 'X', [0])]))],
tmax=23.0)
print(schedule)
drive:
(1 - t) * 1 * (Z|[0])
t * 1 * (X|[0])
tmax = 23.0
As one can see, the time during which the schedule is defined (the tmax
parameter) also needs to be provided.
Note
It often leads to a faster Schedule creation (especially for tens or hundreds of qubits) if the coefficient of a Hamiltonian’s term is fed straight inside the respective
Term
(instead of leaving a coefficient \(1\)).Also, if the same Pauli operator will be applied to many terms, list comprehension for the
pauli_terms
argument of anObservable
will lead to a speed-up (compared to having as many tupples in thedrive
).
Using abstract variables
All scalars (i.e coefficients, tmax, etc) can be abstract arithmetic expressions:
from qat.core import Variable, Schedule, Observable, Term
t_variable = Variable("t")
tmax_expr = 15 * Variable("tmax") - 5
schedule = Schedule(drive=[(1 - t_variable, Observable(1, pauli_terms=[Term(1, 'Z', [0])])),
(t_variable, Observable(1, pauli_terms=[Term(1, 'X', [0])]))],
tmax=tmax_expr)
print(schedule, "\n")
print(schedule(tmax=10))
drive:
(1 - t) * 1 * (Z|[0])
t * 1 * (X|[0])
tmax = ((15 * tmax) - 5)
drive:
(1 - t) * 1 * (Z|[0])
t * 1 * (X|[0])
tmax = 145
Hamiltonian as one Observable
Drives can also be declared using an Observable
with time-dependent coefficients:
from qat.core import Variable, Schedule, Observable, Term
t_variable = Variable("t")
hamiltonian = (1 - t_variable) * Observable(1, pauli_terms=[Term(1, 'Z', [0])]) + \
t_variable * Observable(1, pauli_terms=[Term(1, 'X', [0])])
schedule = Schedule(drive=hamiltonian,
tmax=23.0)
print(schedule)
drive:
1 * (1 - t) * (Z|[0]) +
t * (X|[0])
tmax = 23.0