Execution Session
This section explains how to execute a quantum program using theExecutionSession class.
The class enables executing a quantum program with parameters and operations, eliminating the need to resynthesize the model.
Initializing
InitializeExecutionSession with a quantum program; the output of the synthesis operation.
It is recommended to use ExecutionSession as a context manager in order to ensure resources are cleaned up. Alternatively, you can call the close method directly.
For example:
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 -
batch: Samples/estimates the quantum program multiple times. The number of samples or estimations is determined by the length of the parameters list. -
submit: When using submit as a prefix, the job object returns immediately, and the results should be polled. SeeExecutionJobin the sdk reference.
sample method, these variations are available:
-
es.sample(parameter: Optional[ExecutionParams]) -
es.batch_sample(parameter: List[ExecutionParams]) -
es.submit_sample(parameter: Optional[ExecutionParams]) -
es.submit_batch_sample(parameter: List[ExecutionParams])
estimate method has the same variations:
-
es.estimate(hamiltonian: SparsePauliOp, parameters: Optional[ExecutionParams]) -
es.batch_estimate(hamiltonian, parameters: List[ExecutionParams]) -
es.submit_estimate(hamiltonia, parameters: Optional[ExecutionParams]) -
es.submit_batch_estimate(hamiltonian, parameters: 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.