Basic Usage¶
Indirect Selene Usage via Guppy¶
The program defines a quantum function main() using the @guppy decorator. A qubit is allocated and measured. Further qubit allocations and operations on those qubits are conditioned upon the measurement result of the first qubit. This is an example of a program with conditional blocks of operations.
This program can be emulated with Selene using the syntax below. An emulator instance with seed=2 is instantiated. This instance can run the Guppy program by invocation of the run
method.
Direct Selene Usage¶
The selene-sim API can be directly consumed, but first requires Guppy source be compiled into a compact representation, HUGR. Direct selene-sim usage may be preferred if the user wants to configure the simulation with different plugins. main.compile
compiles the guppy source to HUGR, and build
lowers the HUGR to LLVM that adheres to Quantinuum’s Quantum Instruction Set (QIS).
The classical replay simualator allows Selene to traverse measurement-conditioned branches in the user’s program. A set of classical replay data is required as input. Replay data consists of lists representing predetermined classical measurement outcomes, as simulation input. This ensures that all classical branches of the program (conditional logic based on measurement results) get exercised without having to simulate probabilistic measurements. Replay data consusts of a list of lists. Each sublist corresponds to a new shot. The length of each sublist corresponds to the number of measurements required per shot.
The code-cell below executes the simulation and returns a QsysResult object. Instead of a real quantum simulator, a classical replay simulator is used. This simulator bypasses quantum randomness and simply returns the given measurement outcomes ((simulator=ClassicalReplay(measurements=measurements)
). The quantum program will be executed as if it had three qubits (n_qubits=3
). The program will run three separate shots, one for each set of replayed measurements (n_shots=3
). The output is wrapped in a QsysResult
object, shots, which provides structured access to execution results, including measurements and simulation logs.