QuantumProgram (see Quantum Program Synthesis) and, for sampling, also OpenQASM 2.0 or 3.0.
Once you have defined the format of input for execution,
you can run it using a set of high-level APIs designed to be consistent and easy to use.
Quick workflow
Execution typically consists of four steps:-
Choose the execution function based on the desired result type:
sample(...)for shot-based measurement resultscalculate_state_vector(...)for amplitudes and basis-state informationobserve(...)for expectation values
-
Choose a backend
Use
get_backend_details()to inspect the available providers and devices.
Not all result types are available on all backends. For example, state vector results cannot be obtained from QPUs.
-
Pass execution settings in one place
Use
config=for provider-specific configuration, together with common execution arguments such asnum_shots,random_seed, andtranspilation_option. -
Inspect the returned result
sample(...)returns a DataFramecalculate_state_vector(...)returns a DataFrameobserve(...)returns a scalar- If
parametersis a list, the returned value is a list of results of the corresponding type
Step 1 — Choose the type of result you want
Before running your program, it is important to decide what kind of information you want to extract. There are three common execution functions:| Function | When to use | Output |
|---|---|---|
sample | You want measurement statistics | DataFrame |
calculate_state_vector | You want amplitudes and phases | DataFrame |
observe | You want an expectation value | float |
- Use sample when you want to see the outcomes that would be obtained by measuring the circuit many times.
- Use calculate_state_vector when you want the full quantum state, including amplitudes and phases.
- Use observe when you want to evaluate an observable and obtain a single expectation value.
Step 2 — Inspect available backends
Before executing, you should inspect which backends are available.- provider (e.g., classiq, azure, braket)
- backend (device name)
- type (simulator / hardware)
- num_qubits
- is_available
- queue_time
Provider-specific configuration
All execution functions (sample, observe, and calculate_state_vector) accept a config argument that allows you to pass provider-specific configuration. This is the main mechanism for customizing how your program is executed on a given backend.When to use config
Use config when you need to:- Provide authentication details (e.g., API keys or credentials)
- Configure execution settings specific to a provider
- Enable features such as noise models on simulators
- Control advanced backend behavior that is not exposed through the common execution arguments
Basic usage
The config argument can be passed as either:- A plain Python dictionary, or
- a provider-specific configuration object (for example, IBMConfig, BraketConfig, etc.)
emulate on an Azure backend to enable IonQ hardware noise simulation in
two different ways: First, using config as a dict, and then using config as a provider-specific object.
Example: Using config as a dict
Key takeaways
- Execution always follows the same pattern:
- Choose result type
- Choose backend
- Configure in one place
- Analyze result
- Data is returned in ready-to-use structures
- DataFrames for sampling and state vector
- Scalars for observables
- Batch execution is automatic when passing a list of parameters