ExecutionSession class.
The class enables executing a quantum program with parameters and operations, eliminating the need to resynthesize the model.
Initializing
InitializeExecutionSession with either:
- A quantum program (the output of
synthesize), or - OpenQASM 2.0 or 3.0 source as a string (same semantics as the first argument to
sample).
ExecutionSession as a context manager in order to ensure resources are cleaned up. Alternatively, you can call the close method directly.
Quantum program
OpenQASM string
parameters on sample / submit_sample for Qmod-style main arguments; use a synthesized QuantumProgram instead.
Operations
ExecutionSession supports two types of operations:
-
sample: Executes the quantum program with the specified parameters. -
estimate: Computes the expectation value of the specified Hamiltonian using the quantum program.
ClassiqSimulatorBackendNames.SIMULATOR_STATEVECTOR backend
calculates the expectation value directly from the computed state vector, as opposed to computing it from shots.
Each invocation mode can use one of these options:
-
single -
submit: When using submit as a prefix, the job object returns immediately, and the results should be polled. SeeExecutionJobin the sdk reference.
sample method, pass a single parameter dict or a list for batch execution:
-
es.sample(parameters: Optional[ExecutionParams | List[ExecutionParams]]) -
es.submit_sample(parameters: Optional[ExecutionParams | List[ExecutionParams]])
estimate method works the same way:
-
es.estimate(hamiltonian: SparsePauliOp, parameters: Optional[ExecutionParams | List[ExecutionParams]]) -
es.submit_estimate(hamiltonian: SparsePauliOp, parameters: Optional[ExecutionParams | List[ExecutionParams]])
Examples
sample()
A simple example of how to usesample and its variations:
estimate()
An example that shows how to useestimate and its variations:
Handling Long Jobs
When handling long-running jobs (jobs that are submitted to HW providers with potentially very long queues) it is advisable to retrieve and save the job ID for future reference:@cfunc
Note that Classiq does not support algorithms utilizing @cfunc (or cscope in Qmod native) for long job execution.