Manipulating schedules

The Schedule class has some overloaded operators which allow you to manipulate them efficiently.

Two schedules can be temporally composed using the pipe/or operator:

from qat.core import Variable, Observable, Schedule, Term

t_variable = Variable("t")
schedule1 = Schedule(drive=(1 - t_variable) * Observable(1, pauli_terms=[Term(1, 'Z', [0])]),
                     tmax=2.0)
schedule2 = Schedule(drive=t_variable * Observable(1, pauli_terms=[Term(1, 'X', [0])]),
                     tmax=3.0)

print(schedule1 | schedule2)
drive:
heaviside(t,0,2.0) * (1 - t) * (Z|[0])
heaviside(t,2.0,5.0) * (t - 2.0) * (X|[0])
tmax = 5.0

Note how the coefficients are ponderated by a heaviside signal to filter the ranges of the two schedules.

Two schedules can be merged into a single schedule containing the sum of the two drives using an addition.

from qat.core import Variable, Observable, Schedule, Term

t_variable = Variable("t")
schedule1 = Schedule(drive=(1 - t_variable) * Observable(1, pauli_terms=[Term(1, 'Z', [0])]),
                     tmax=2.0)
schedule2 = Schedule(drive=t_variable * Observable(1, pauli_terms=[Term(1, 'X', [0])]),
                     tmax=3.0)

print(schedule1 + schedule2)
drive:
heaviside(t,0,2.0) * (1 - t) * (Z|[0])
heaviside(t,0,3.0) * t * (X|[0])
tmax = 3.0

Schedules can be rescaled via multiplication by a scalar:

from qat.core import Variable, Observable, Schedule, Term

t_variable = Variable("t")
schedule = Schedule(drive=(1 - t_variable) * Observable(1, pauli_terms=[Term(1, 'Z', [0])]),
                    tmax=2.0)

print(45 * schedule, "\n")
print(Variable("foo") * schedule)
Reverse mult 45 * drive:
1 * (1 - t) * (Z|[0])
tmax = 2.0
drive:
45 * (1 - t) * (Z|[0])
tmax = 2.0 

Reverse mult foo * drive:
1 * (1 - t) * (Z|[0])
tmax = 2.0
drive:
foo * (1 - t) * (Z|[0])
tmax = 2.0

Schedules can be delayed (in the past or the future) by using the bit shift operators << and >>:

from qat.core import Variable, Observable, Schedule, Term

t_variable = Variable("t")
schedule = Schedule(drive=(1 - t_variable) * Observable(1, pauli_terms=[Term(1, 'Z', [0])]),
                    tmax=2.0)

print(schedule >> 3, "\n")
print(schedule << Variable('bar'))
drive:
heaviside(t,3,5.0) * (1 - (t - 3)) * (Z|[0])
tmax = 5.0 

drive:
heaviside(t,-(bar),(2.0 + -(bar))) * (1 - (t - -(bar))) * (Z|[0])
tmax = (2.0 + -(bar))