Creating a quantum program
A QuantumProgram
combines a Register
and a Drive
and serves as the main interface for compilation and execution.
from qoolqit import PiecewiseLinear
from qoolqit import Register, Drive, QuantumProgram
# Defining the Drive
wf0 = PiecewiseLinear([1.0, 2.0, 1.0], [0.0, 0.5, 0.5, 0.0])
wf1 = PiecewiseLinear([1.0, 2.0, 1.0], [-1.0, -1.0, 1.0, 1.0])
drive = Drive(amplitude = wf0, detuning = wf1)
# Defining the Register
coords = [(0.0, 0.0), (0.0, 1.0), (1.0, 0.0), (1.0, 1.0)]
register = Register.from_coordinates(coords)
# Creating the Program
program = QuantumProgram(register, drive)
At this point, the program has not been compiled to any device. As shown above, this is conveniently displayed
when printing the program. It can also be checked through the is_compiled
property.
Now we instantiate a device and compile the program to that device. Compiling in QoolQit means to translate the adimensional values of time, energy, and distance used when defining the program in the Rydberg analog model to a specific set of values that implement the same set of instructions in a Pulser device, taking into account the Pulser units and the specific parameters of that device. More detailed information on this conversion is provided in the Rydberg analog model page.
Now that the program has been compiled, we can inspect the compiled sequence, which is an instance of a Pulser Sequence
.
Finally, we can draw both the original program and the compiled sequence.
Compiler profiles
In the example above the AnalogDevice
was used, and no changes were made to the unit converter. As such, the default was used, which sets the reference energy unit as the maximum amplitude, as described in the Devices page.
When a QoolQit program is compiled to Pulser, several compiler profiles can be used. You can check them in the following enumeration:
By default CompilerProfile.DEFAULT
is used, which directly takes the unit converter present in the device and uses it when converting the values.
Other compiler profiles will ignore the unit converter present in the device and utilize their own logic to determine the best possible conversion to achieve a desired compilation directive.
The CompilerProfile.MAX_AMPLITUDE
maps whatever is the maximum amplitude in the drive of your QoolQit program to the device's maximum allowed amplitude:
The CompilerProfile.MAX_DURATION
maps whatever is the duration of your QoolQit program to the device's maximum allowed sequence duration:
The CompilerProfile.MIN_DISTANCE
maps whatever is the minimum distance in the register of your QoolQit program to the device's minimum allowed atom separation:
try:
program.compile_to(device, profile = CompilerProfile.MIN_DISTANCE)
except Exception as error:
print(error)
In this case, you can see the compilation failed because putting the atoms that close together for this program would require setting an amplitude that is larger than what the device allows.