Skip to main content

execute

execute(
quantum_program: QuantumProgram
) -> ExecutionJob
Execute a quantum program. The preferences for execution are set on the quantum program using the method set_execution_preferences. Parameters:
NameTypeDescriptionDefault
quantum_programQuantumProgramThe quantum program to execute. This is the result of the synthesize method.required
Returns:
  • Type: ExecutionJob
  • The result of the execution.

ExecutionSession

A session for executing a quantum program. ExecutionSession allows to execute the quantum program with different parameters and operations without the need to re-synthesize the model. The session must be closed in order to ensure resources are properly cleaned up. It’s recommended to use ExecutionSession as a context manager for this purpose. Alternatively, you can directly use the close method. Methods:
NameDescription
closeClose the session and clean up its resources.
get_session_id
update_execution_preferencesUpdate the execution preferences for the session.
sampleSamples the quantum program with the given parameters, if any.
submit_sampleInitiates an execution job with the sample primitive.
batch_sampleSamples the quantum program multiple times with the given parameters for each iteration.
submit_batch_sampleInitiates an execution job with the batch_sample primitive.
estimateEstimates the expectation value of the given Hamiltonian using the quantum program.
submit_estimateInitiates an execution job with the estimate primitive.
batch_estimateEstimates the expectation value of the given Hamiltonian multiple times using the quantum program, with the given parameters for each iteration.
submit_batch_estimateInitiates an execution job with the batch_estimate primitive.
minimizeMinimizes the given cost function using the quantum program.
submit_minimizeInitiates an execution job with the minimize primitive.
estimate_costEstimates circuit cost using a classical cost function.
set_measured_state_filterWhen simulating on a statevector simulator, emulate the behavior of postprocessing by discarding amplitudes for which their states are “undesirable”.
Attributes:
NameTypeDescription
quantum_programQuantumProgramThe quantum program to execute.
execution_preferencesOptional[ExecutionPreferences]Execution preferences for the Quantum Program.

program

program: QuantumProgram = quantum_program

close

close(
self:
) -> None
Close the session and clean up its resources. Parameters:
NameTypeDescriptionDefault
selfrequired

update_execution_preferences

update_execution_preferences(
self: ,
execution_preferences: ExecutionPreferences | None
) -> None
Update the execution preferences for the session. Parameters:
NameTypeDescriptionDefault
selfrequired
execution_preferencesExecutionPreferences | NoneThe execution preferences to update.required
Returns:
  • Type: None

sample

sample(
self: ,
parameters: ExecutionParams | None = None
) -> ExecutionDetails
Samples the quantum program with the given parameters, if any. Parameters:
NameTypeDescriptionDefault
selfrequired
parametersExecutionParams | NoneThe values to set for the parameters of the quantum program when sampling. Each key should be the name of a parameter in the quantum program (parameters of the main function), and the value should be the value to set for that parameter.None
Returns:
  • Type: ExecutionDetails
  • The result of the sampling.

submit_sample

submit_sample(
self: ,
parameters: ExecutionParams | None = None
) -> ExecutionJob
Initiates an execution job with the sample primitive. This is a non-blocking version of sample: it gets the same parameters and initiates the same execution job, but instead of waiting for the result, it returns the job object immediately. Parameters:
NameTypeDescriptionDefault
selfrequired
parametersExecutionParams | NoneThe values to set for the parameters of the quantum program when sampling. Each key should be the name of a parameter in the quantum program (parameters of the main function), and the value should be the value to set for that parameter.None
Returns:
  • Type: ExecutionJob
  • The execution job.

batch_sample

batch_sample(
self: ,
parameters: list[ExecutionParams]
) -> list[ExecutionDetails]
Samples the quantum program multiple times with the given parameters for each iteration. The number of samples is determined by the length of the parameters list. Parameters:
NameTypeDescriptionDefault
selfrequired
parameterslist[ExecutionParams]A list of the parameters for each iteration. Each item is a dictionary where each key should be the name of a parameter in the quantum program (parameters of the main function), and the value should be the value to set for that parameter.required
Returns:
  • Type: list[ExecutionDetails]
  • List[ExecutionDetails]: The results of all the sampling iterations.

submit_batch_sample

submit_batch_sample(
self: ,
parameters: list[ExecutionParams]
) -> ExecutionJob
Initiates an execution job with the batch_sample primitive. This is a non-blocking version of batch_sample: it gets the same parameters and initiates the same execution job, but instead of waiting for the result, it returns the job object immediately. Parameters:
NameTypeDescriptionDefault
selfrequired
parameterslist[ExecutionParams]A list of the parameters for each iteration. Each item is a dictionary where each key should be the name of a parameter in the quantum program (parameters of the main function), and the value should be the value to set for that parameter.required
Returns:
  • Type: ExecutionJob
  • The execution job.

estimate

estimate(
self: ,
hamiltonian: Hamiltonian,
parameters: ExecutionParams | None = None
) -> EstimationResult
Estimates the expectation value of the given Hamiltonian using the quantum program. Parameters:
NameTypeDescriptionDefault
selfrequired
hamiltonianHamiltonianThe Hamiltonian to estimate the expectation value of.required
parametersExecutionParams | NoneThe values to set for the parameters of the quantum program when estimating. Each key should be the name of a parameter in the quantum program (parameters of the main function), and the value should be the value to set for that parameter.None
Returns:
  • Type: EstimationResult
  • The result of the estimation.

submit_estimate

submit_estimate(
self: ,
hamiltonian: Hamiltonian,
parameters: ExecutionParams | None = None,
_check_deprecation: bool = True
) -> ExecutionJob
Initiates an execution job with the estimate primitive. This is a non-blocking version of estimate: it gets the same parameters and initiates the same execution job, but instead of waiting for the result, it returns the job object immediately. Parameters:
NameTypeDescriptionDefault
selfrequired
hamiltonianHamiltonianThe Hamiltonian to estimate the expectation value of.required
parametersExecutionParams | NoneThe values to set for the parameters of the quantum program when estimating. Each key should be the name of a parameter in the quantum program (parameters of the main function), and the value should be the value to set for that parameter.None
_check_deprecationboolTrue
Returns:
  • Type: ExecutionJob
  • The execution job.

batch_estimate

batch_estimate(
self: ,
hamiltonian: Hamiltonian,
parameters: list[ExecutionParams]
) -> list[EstimationResult]
Estimates the expectation value of the given Hamiltonian multiple times using the quantum program, with the given parameters for each iteration. The number of estimations is determined by the length of the parameters list. Parameters:
NameTypeDescriptionDefault
selfrequired
hamiltonianHamiltonianThe Hamiltonian to estimate the expectation value of.required
parameterslist[ExecutionParams]A list of the parameters for each iteration. Each item is a dictionary where each key should be the name of a parameter in the quantum program (parameters of the main function), and the value should be the value to set for that parameter.required
Returns:
  • Type: list[EstimationResult]
  • List[EstimationResult]: The results of all the estimation iterations.

submit_batch_estimate

submit_batch_estimate(
self: ,
hamiltonian: Hamiltonian,
parameters: list[ExecutionParams],
_check_deprecation: bool = True
) -> ExecutionJob
Initiates an execution job with the batch_estimate primitive. This is a non-blocking version of batch_estimate: it gets the same parameters and initiates the same execution job, but instead of waiting for the result, it returns the job object immediately. Parameters:
NameTypeDescriptionDefault
selfrequired
hamiltonianHamiltonianThe Hamiltonian to estimate the expectation value of.required
parameterslist[ExecutionParams]A list of the parameters for each iteration. Each item is a dictionary where each key should be the name of a parameter in the quantum program (parameters of the main function), and the value should be the value to set for that parameter.required
_check_deprecationboolTrue
Returns:
  • Type: ExecutionJob
  • The execution job.

minimize

minimize(
self: ,
cost_function: Hamiltonian | QmodExpressionCreator,
initial_params: ExecutionParams,
max_iteration: int,
quantile: float = 1.0,
tolerance: float | None = None
) -> list[tuple[float, ExecutionParams]]
Minimizes the given cost function using the quantum program. Parameters:
NameTypeDescriptionDefault
selfrequired
cost_functionHamiltonian | QmodExpressionCreatorThe cost function to minimize. It can be one of the following: - A quantum cost function defined by a Hamiltonian. - A classical cost function represented as a callable that returns a Qmod expression. The callable should accept QVars as arguments and use names matching the Model outputs.required
initial_paramsExecutionParamsThe initial parameters for the minimization. Only Models with exactly one execution parameter are supported. This parameter must be of type CReal or CArray. The dictionary must contain a single key-value pair, where: - The key is the name of the parameter. - The value is either a float or a list of floats.required
max_iterationintThe maximum number of iterations for the minimization.required
quantilefloatThe quantile to use for cost estimation.1.0
tolerancefloat | NoneThe tolerance for the minimization.None
Returns:
  • Type: list[tuple[float, ExecutionParams]]
  • A list of tuples, each containing the estimated cost and the corresponding parameters for that iteration. cost is a float, and parameters is a dictionary matching the execution parameter format.

submit_minimize

submit_minimize(
self: ,
cost_function: Hamiltonian | QmodExpressionCreator,
initial_params: ExecutionParams,
max_iteration: int,
quantile: float = 1.0,
tolerance: float | None = None,
_check_deprecation: bool = True
) -> ExecutionJob
Initiates an execution job with the minimize primitive. This is a non-blocking version of minimize: it gets the same parameters and initiates the same execution job, but instead of waiting for the result, it returns the job object immediately. Parameters:
NameTypeDescriptionDefault
selfrequired
cost_functionHamiltonian | QmodExpressionCreatorThe cost function to minimize. It can be one of the following: - A quantum cost function defined by a Hamiltonian. - A classical cost function represented as a callable that returns a Qmod expression. The callable should accept QVars as arguments and use names matching the Model outputs.required
initial_paramsExecutionParamsThe initial parameters for the minimization. Only Models with exactly one execution parameter are supported. This parameter must be of type CReal or CArray. The dictionary must contain a single key-value pair, where: - The key is the name of the parameter. - The value is either a float or a list of floats.required
max_iterationintThe maximum number of iterations for the minimization.required
quantilefloatThe quantile to use for cost estimation.1.0
tolerancefloat | NoneThe tolerance for the minimization.None
_check_deprecationboolTrue
Returns:
  • Type: ExecutionJob
  • The execution job.

estimate_cost

estimate_cost(
self: ,
cost_func: Callable[[ParsedState], float],
parameters: ExecutionParams | None = None,
quantile: float = 1.0
) -> float
Estimates circuit cost using a classical cost function. Parameters:
NameTypeDescriptionDefault
selfrequired
cost_funcCallable[[ParsedState], float]classical circuit sample cost functionrequired
parametersExecutionParams | Noneexecution parameters sent to ‘sample’None
quantilefloatdrop cost values outside the specified quantile1.0
Returns:
  • Type: float
  • cost estimation

set_measured_state_filter

set_measured_state_filter(
self: ,
output_name: str,
condition: Callable
) -> None
When simulating on a statevector simulator, emulate the behavior of postprocessing by discarding amplitudes for which their states are “undesirable”. Parameters:
NameTypeDescriptionDefault
selfrequired
output_namestrThe name of the register to filterrequired
conditionCallableFilter out values of the statevector for which this callable is Falserequired

ExecutionPreferences

Represents the execution settings for running a quantum program. Execution preferences for running a quantum program. For more details, refer to: ExecutionPreferences example: ExecutionPreferences.. Attributes:
NameTypeDescription
noise_propertiesOptional[NoiseProperties]Properties defining the noise in the quantum circuit. Defaults to None.
random_seedintThe random seed used for the execution. Defaults to a randomly generated seed.
backend_preferencesBackendPreferencesTypesPreferences for the backend used to execute the circuit. Defaults to the Classiq Simulator.
num_shotsOptional[pydantic.PositiveInt]The number of shots (executions) to be performed.
transpile_to_hardwareTranspilationOptionOption to transpile the circuit to the hardware’s basis gates before execution. Defaults to TranspilationOption.DECOMPOSE.
job_nameOptional[str]The name of the job, with a minimum length of 1 character.

noise_properties

noise_properties: NoiseProperties | None = pydantic.Field(default=None, description='Properties of the noise in the circuit')

random_seed

random_seed: int = pydantic.Field(default_factory=create_random_seed, description='The random seed used for the execution')

backend_preferences

backend_preferences: BackendPreferencesTypes = backend_preferences_field(backend_name=(ClassiqSimulatorBackendNames.SIMULATOR))

num_shots

num_shots: pydantic.PositiveInt | None = pydantic.Field(default=None)

transpile_to_hardware

transpile_to_hardware: TranspilationOption = pydantic.Field(default=(TranspilationOption.DECOMPOSE), description='Transpile the circuit to the hardware basis gates before execution', title='Transpilation Option')

job_name

job_name: str | None = pydantic.Field(min_length=1, description='The job name', default=None)

include_zero_amplitude_outputs

include_zero_amplitude_outputs: bool = pydantic.Field(default=False, description='In state vector simulation, whether to include zero-amplitude states in the result')

BackendPreferences

Preferences for the execution of the quantum program. Methods: Attributes:
NameTypeDescription
backend_service_providerstrProvider company or cloud for the requested backend.
backend_namestrName of the requested backend or target.

backend_service_provider

backend_service_provider: ProviderVendor = pydantic.Field(..., description='Provider company or cloud for the requested backend.')

backend_name

backend_name: str = pydantic.Field(..., description='Name of the requested backend or target.')

hw_provider

hw_provider: Provider Members:
NameDescription
ExecutionJobFiltersFilter parameters for querying execution jobs.
get_execution_jobsQuery execution jobs.
get_execution_actionsQuery execution jobs with optional filters.

ExecutionJobFilters

Filter parameters for querying execution jobs. All filters are combined using AND logic: only jobs matching all specified filters are returned. Range filters (with _min/_max suffixes) are inclusive. Datetime filters are compared against the job’s timestamps. Methods:
NameDescription
format_filtersConvert filter fields to API kwargs, excluding None values and converting datetimes.

id

id: str | None = None

session_id

session_id: str | None = None

status

status: JobStatus | None = None

name

name: str | None = None

provider

provider: str | None = None

backend

backend: str | None = None

program_id

program_id: str | None = None

total_cost_min

total_cost_min: float | None = None

total_cost_max

total_cost_max: float | None = None

start_time_min

start_time_min: datetime | None = None

start_time_max

start_time_max: datetime | None = None

end_time_min

end_time_min: datetime | None = None

end_time_max

end_time_max: datetime | None = None

format_filters

format_filters(
self:
) -> dict[str, Any]
Convert filter fields to API kwargs, excluding None values and converting datetimes. Parameters:
NameTypeDescriptionDefault
selfrequired

get_execution_jobs

get_execution_jobs(
offset: int = 0,
limit: int = 50
) -> list[ExecutionJob]
Query execution jobs. Parameters:
NameTypeDescriptionDefault
offsetintNumber of results to skip (default: 0)0
limitintMaximum number of results to return (default: 50)50
Returns:
  • Type: list[ExecutionJob]
  • List of ExecutionJob objects.

get_execution_actions

get_execution_actions(
offset: int = 0,
limit: int = 50,
filters: ExecutionJobFilters | None = None
) -> pd.DataFrame
Query execution jobs with optional filters. Parameters:
NameTypeDescriptionDefault
offsetintNumber of results to skip (default: 0)0
limitintMaximum number of results to return (default: 50)50
filtersExecutionJobFilters | NoneOptional ExecutionJobFilters object containing filter parameters.None
Returns:
  • Type: pd.DataFrame
  • pandas.DataFrame containing execution job information with columns:
  • id, name, start_time, end_time, provider, backend_name, status,
  • num_shots, program_id, error, cost.

assign_parameters

assign_parameters(
quantum_program: QuantumProgram,
parameters: ExecutionParams
) -> QuantumProgram
Assign parameters to a parametric quantum program. Parameters:
NameTypeDescriptionDefault
quantum_programQuantumProgramThe quantum program to be assigned. This is the result of the synthesize method.required
parametersExecutionParamsThe parameter assignments.required
Returns:
  • Type: QuantumProgram
  • The quantum program after assigning parameters.

transpile

transpile(
quantum_program: QuantumProgram,
preferences: Preferences | None = None
) -> QuantumProgram
Transpiles a quantum program. Parameters:
NameTypeDescriptionDefault
quantum_programQuantumProgramThe quantum program to transpile. This is the result of the synthesize method.required
preferencesPreferences | NoneThe transpilation preferences.None
Returns:
  • Type: QuantumProgram
  • The result of the transpilation (Optional).

get_budget

get_budget(
provider: ProviderVendor | None = None
) -> UserBudgets
Retrieve the user’s budget information for quantum computing resources. Parameters:
NameTypeDescriptionDefault
providerProviderVendor | None(Optional) The quantum backend provider to filter budgets by. If not provided, budgets for all providers will be returned.None
Returns:
  • Type: UserBudgets
  • An object containing the user’s budget information.

set_budget_limit

set_budget_limit(
provider: ProviderVendor,
limit: float
) -> UserBudgets
Set a budget limit for a specific quantum backend provider. Parameters:
NameTypeDescriptionDefault
providerProviderVendorThe quantum backend provider for which to set the budget limit.required
limitfloatThe budget limit to set. Must be greater than zero and not exceed the available budget.required
Returns:
  • Type: UserBudgets
  • An object containing the updated budget information.

clear_budget_limit

clear_budget_limit(
provider: ProviderVendor
) -> UserBudgets
Clear the budget limit for a specific quantum backend provider. Parameters:
NameTypeDescriptionDefault
providerProviderVendorThe quantum backend provider for which to clear the budget limit.required
Returns:
  • Type: UserBudgets
  • An object containing the updated budget information.