Skip to main content
Members:
NameDescription
GenericIQAEThe implementation is based on Algorithm 1 & Algorithm 2 in [1], with the intent of demistifying variables names and simplifying the code flow.
IQAEIterationDataHandles the data storage for a single iteration of the Iterative Quantum Amplitude Estimation algorithm.
IQAEResultRepresents the result of an Iterative Quantum Amplitude Estimation (IQAE) process.
ExecutionPreferencesRepresents the execution settings for running a quantum program.
ConstraintsConstraints for the quantum circuit synthesis engine.
PreferencesPreferences for synthesizing a quantum circuit.
ExecutionSessionA session for executing a quantum program.
QBitA type representing a single qubit.
Z[Qmod core-library function].
allocateInitialize a quantum variable to a new quantum object in the zero state:.
bindReassign qubit or arrays of qubits by redirecting their logical identifiers.
within_applyGiven two operations UU and VV, performs the sequence of operations U{1}VUU^\{-1\} V U.
drop[Qmod core-library function].
create_modelCreate a serialized model from a given Qmod entry function and additional parameters.
synthesizeSynthesize a model with the Classiq engine to receive a quantum program.
IQAEImplementation of Iterative Quantum Amplitude Estimation [1].

GenericIQAE

The implementation is based on Algorithm 1 & Algorithm 2 in [1], with the intent of demistifying variables names and simplifying the code flow. Moreover, we separated the algorithm flow from quantum execution to allow migrating this code to any execution interface and to improve its testability. Methods:
NameDescription
runExecute the estimation algorithm.
current_estimation_confidence_interval
current_estimation
find_next_KWe want to find the largest K (with some lower and upper bounds) such that the K-scaled confidence interval lies completely in the upper or lower h…

iterations

iterations: list[IterationInfo] = []

run

run(
self:
) -> float
Execute the estimation algorithm. See Algorithm 1, [1]. Parameters:
NameTypeDescriptionDefault
selfrequired

find_next_K

find_next_K(
K: int,
is_upper_plane: bool,
confidence_interval: np.ndarray,
r: int = 2
) -> tuple[int, bool]
We want to find the largest K (with some lower and upper bounds) such that the K-scaled confidence interval lies completely in the upper or lower half planes. See Algorithm 2, [1]. Parameters:
NameTypeDescriptionDefault
Kintrequired
is_upper_planeboolrequired
confidence_intervalnp.ndarrayrequired
rint2

IQAEIterationData

Handles the data storage for a single iteration of the Iterative Quantum Amplitude Estimation algorithm. This class is intended to represent the results and state of a single Grover iteration of the IQAE process. Attributes:
NameTypeDescription
grover_iterationsintThe iteration number of Grover’s algorithm.
sample_resultsExecutionDetailsThe ExecutionDetails of Grover iteration. See ExecutionDetails.

grover_iterations

grover_iterations: int

sample_results

sample_results: ExecutionDetails

IQAEResult

Represents the result of an Iterative Quantum Amplitude Estimation (IQAE) process. This class encapsulates the output of the IQAE algorithm, including the estimated value, confidence interval, intermediate iteration data, and any warnings generated during the computation. Attributes:
NameTypeDescription
estimationfloatEstimation of the amplitude.
confidence_intervallist[float]The interval in which the amplitude is within, with a probability equal to epsilon.
iterations_datalist[IQAEIterationData]List of IQAEIterationData of each Grover iteration.
warningslist[str]List of warnings generated during the IQAE process of each Grover iteration.

estimation

estimation: float

confidence_interval

confidence_interval: list[float] = Field(min_length=2, max_length=2)

iterations_data

iterations_data: list[IQAEIterationData]

warnings

warnings: list[str]

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')

Constraints

Constraints for the quantum circuit synthesis engine. This class is used to specify constraints such as maximum width, depth, gate count, and optimization parameters for the synthesis engine, guiding the generation of quantum circuits that satisfy these constraints. Methods: Attributes:
NameTypeDescription
max_widthintMaximum number of qubits allowed in the generated quantum circuit. Defaults to None.
max_depthintMaximum depth of the generated quantum circuit. Defaults to None.
max_gate_countDict[TranspilerBasisGates, int]A dictionary specifying the maximum allowed count for each type of gate in the quantum circuit. Defaults to an empty dictionary.
optimization_parameterOptimizationParameterTypeDetermines if and how the synthesis engine should optimize the solution. Defaults to NO_OPTIMIZATION. See OptimizationParameterType

model_config

model_config = ConfigDict(extra='forbid')

max_width

max_width: pydantic.PositiveInt | None = pydantic.Field(default=None, description='Maximum number of qubits in generated quantum circuit')

max_depth

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

max_gate_count

max_gate_count: dict[TranspilerBasisGates, pydantic.NonNegativeInt] = pydantic.Field(default_factory=(lambda: defaultdict(int)))

optimization_parameter

optimization_parameter: OptimizationParameterType = pydantic.Field(default=(OptimizationParameter.NO_OPTIMIZATION), description='If set, the synthesis engine optimizes the solution according to that chosen parameter')

Preferences

Preferences for synthesizing a quantum circuit. Methods: Attributes:
NameTypeDescription
machine_precisionintSpecifies the precision used for quantum operations. Defaults to DEFAULT_MACHINE_PRECISION.
backend_service_providerstrThe provider company or cloud service for the requested backend. Defaults to None.
backend_namestrThe name of the requested backend or target. Defaults to None.
custom_hardware_settingsCustomHardwareSettingsDefines custom hardware settings for optimization. This field is ignored if backend preferences are specified.
debug_modeboolIf True, debug information is added to the synthesized result, potentially slowing down the synthesis. Useful for executing interactive algorithms. Defaults to True.
optimization_levelOptimizationLevel)The optimization level used during synthesis (0-3);
output_formatList[QuantumFormat]Lists the output format(s) for the quantum circuit. Defaults to [QuantumFormat.QASM]. QuantumFormat Options: - QASM = “qasm” - QSHARP = “qsharp” - QIR = “qir” - IONQ = “ionq” - CIRQ_JSON = “cirq_json” - QASM_CIRQ_COMPATIBLE = “qasm_cirq_compatible”
pretty_qasmboolIf True, formats OpenQASM 2 outputs with line breaks inside gate declarations, improving readability. Defaults to True.
qasm3Optional[bool]If True, outputs OpenQASM 3.0 in addition to 2.0, applicable to relevant attributes in GeneratedCircuit. Defaults to None.
transpilation_optionTranspilationOptionSets the transpilation option to optimize the circuit. Defaults to AUTO_OPTIMIZE. See TranspilationOption
solovay_kitaev_max_iterationsOptional[int]Specifies the maximum number of iterations for the Solovay-Kitaev algorithm, if used. Defaults to None.
timeout_secondsintTimeout setting for circuit synthesis in seconds. Defaults to 300.
optimization_timeout_secondsOptional[int]Specifies the timeout for optimization in seconds, or None for no optimization timeout. This will still adhere to the overall synthesis timeout. Defaults to None.
random_seedintRandom seed for circuit synthesis.

machine_precision

machine_precision: PydanticMachinePrecision = DEFAULT_MACHINE_PRECISION

backend_service_provider

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

backend_name

backend_name: PydanticBackendName | AllBackendsNameByVendor | None = pydantic.Field(default=None, description='Name of the requested backend or target.')

custom_hardware_settings

custom_hardware_settings: CustomHardwareSettings = pydantic.Field(default_factory=CustomHardwareSettings, description='Custom hardware settings which will be used during optimization. This field is ignored if backend preferences are given.')

debug_mode

debug_mode: bool = pydantic.Field(default=True, description='Add debug information to the synthesized result. Setting this option to False can potentially speed up the synthesis, and is recommended for executing iterative algorithms.')

synthesize_all_separately

synthesize_all_separately: bool = pydantic.Field(default=False, description='If true, a heuristic is used to determine if a function should be synthesized separately', deprecated=True)

optimization_level

optimization_level: OptimizationLevel = pydantic.Field(default=(OptimizationLevel.LIGHT), description='The optimization level used during synthesis; determines the trade-off between synthesis speed and the quality of the results')

output_format

output_format: PydanticConstrainedQuantumFormatList = pydantic.Field(default=[QuantumFormat.QASM], description='The quantum circuit output format(s). ')

pretty_qasm

pretty_qasm: bool = pydantic.Field(True, description='Prettify the OpenQASM2 outputs (use line breaks inside the gate declarations).')

qasm3

qasm3: bool | None = pydantic.Field(None, description='Output OpenQASM 3.0 instead of OpenQASM 2.0. Relevant only for the qasmandtranspiled_circuit.qasmattributes ofGeneratedCircuit.')

transpilation_option

transpilation_option: TranspilationOption = pydantic.Field(default=(TranspilationOption.AUTO_OPTIMIZE), description='If true, the returned result will contain a transpiled circuit and its depth')

solovay_kitaev_max_iterations

solovay_kitaev_max_iterations: pydantic.PositiveInt | None = pydantic.Field(None, description='Maximum iterations for the Solovay-Kitaev algorithm (if applied).')

timeout_seconds

timeout_seconds: pydantic.PositiveInt = pydantic.Field(default=300, description='Generation timeout in seconds')

optimization_timeout_seconds

optimization_timeout_seconds: pydantic.PositiveInt | None = pydantic.Field(default=None, description='Optimization timeout in seconds, or None for no optimization timeout (will still timeout when the generation timeout is over)')

random_seed

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

symbolic_loops

symbolic_loops: bool = pydantic.Field(default=False)

backend_preferences

backend_preferences: BackendPreferences | None

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

QBit

A type representing a single qubit. QBit serves both as a placeholder for a temporary, non-allocated qubit and as the type of an allocated physical or logical qubit. Conceptually, a qubit is a two-level quantum system, described by the superposition of the computational basis states: 0=(10),1=(01)|0\rangle = \begin{pmatrix} 1 \\ 0 \end{pmatrix}, \quad |1\rangle = \begin{pmatrix} 0 \\ 1 \end{pmatrix} Therefore, a qubit state is a linear combination: ψ=α0+β1,|\psi\rangle = \alpha |0\rangle + \beta |1\rangle, where ( \alpha ) and ( \beta ) are complex numbers satisfying: α2+β2=1.|\alpha|^2 + |\beta|^2 = 1. Typical usage includes:
  • Representing an unallocated qubit before its allocation.
  • Acting as the output type for a qubit or an allocated qubit in the main function after calling an allocation function.
Examples: Methods:
NameDescription
to_qvar
get_qmod_type

Z

Z(
target: Const[QBit]
) -> None
[Qmod core-library function] Performs the Pauli-Z gate on a qubit. This operation is represented by the following matrix: Z=[1001]Z = \begin{bmatrix} 1 & 0 \\ 0 & -1 \end{bmatrix} Parameters:
NameTypeDescriptionDefault
targetConst[QBit]The qubit to apply the Pauli-Z gate to.required

allocate

allocate(
args: Any = (),
kwargs: Any = 
) -> None
Initialize a quantum variable to a new quantum object in the zero state: \left|\text{out}\right\rangle = \left|0\right\rangle^{\otimes \text{num_qubits}} If ‘num_qubits’ is not specified, it will be inferred according to the type of ‘out’. In case the quantum variable is of type QNum, its numeric attributes can be specified as well. Parameters:
NameTypeDescriptionDefault
argsAny()
kwargsAny

bind

bind(
source: Input[QVar] | list[Input[QVar]],
destination: Output[QVar] | list[Output[QVar]]
) -> None
Reassign qubit or arrays of qubits by redirecting their logical identifiers. This operation rewires the logical identity of the source qubits to new objects given in destination. For example, an array of two qubits X can be mapped to individual qubits Y and Z. Parameters:
NameTypeDescriptionDefault
sourceInput[QVar] | list[Input[QVar]]A qubit or list of initialized qubits to reassign.required
destinationOutput[QVar] | list[Output[QVar]]A qubit or list of target qubits to bind to. Must match the number of qubits in source.required

within_apply

within_apply(
within: Callable[[], Statements],
apply: Callable[[], Statements]
) -> None
Given two operations UU and VV, performs the sequence of operations U{1}VUU^\{-1\} V U. This operation is used to represent a sequence where the inverse gate U^{-1} is applied, followed by another operation V, and then U is applied to uncompute. This pattern is common in reversible computation and quantum subroutines. Parameters:
NameTypeDescriptionDefault
withinCallable[[], Statements]The unitary operation U to be computed and then uncomputed.required
applyCallable[[], Statements]The operation V to be applied within the U block.required

drop

drop(
in_: Input[QArray[QBit]]
) -> None
[Qmod core-library function] Discards the qubits allocated to a quantum variable which may be in any state, preventing their further use. Parameters:
NameTypeDescriptionDefault
in_Input[QArray[QBit]]The quantum variable that will be dropped. Must be initialized before.required

create_model

create_model(
entry_point: QFunc | GenerativeQFunc,
constraints: Constraints | None = None,
execution_preferences: ExecutionPreferences | None = None,
preferences: Preferences | None = None,
classical_execution_function: CFunc | None = None,
out_file: str | None = None
) -> SerializedModel
Create a serialized model from a given Qmod entry function and additional parameters. Parameters:
NameTypeDescriptionDefault
entry_pointQFunc | GenerativeQFuncThe entry point function for the model, which must be a QFunc named ‘main’.required
constraintsConstraints | NoneConstraints for the synthesis of the model. See Constraints (Optional).None
execution_preferencesExecutionPreferences | NonePreferences for the execution of the model. See ExecutionPreferences (Optional).None
preferencesPreferences | NonePreferences for the synthesis of the model. See Preferences (Optional).None
classical_execution_functionCFunc | NoneA function for the classical execution logic, which must be a CFunc (Optional).None
out_filestr | NoneFile path to write the Qmod model in native Qmod representation to (Optional).None
Returns:
  • Type: SerializedModel
  • A serialized model.

synthesize

synthesize(
model: SerializedModel | BaseQFunc,
auto_show: bool = False,
constraints: Constraints | None = None,
preferences: Preferences | None = None
) -> QuantumProgram
Synthesize a model with the Classiq engine to receive a quantum program. More details Parameters:
NameTypeDescriptionDefault
modelSerializedModel | BaseQFuncThe entry point of the Qmod model - a qfunc named ‘main’ (or alternatively the output of ‘create_model’).required
auto_showboolWhether to ‘show’ the synthesized model (False by default).False
constraintsConstraints | NoneConstraints for the synthesis of the model. See Constraints (Optional).None
preferencesPreferences | NonePreferences for the synthesis of the model. See Preferences (Optional).None
Returns:
  • Type: QuantumProgram
  • Quantum program. (See: QuantumProgram)

IQAE

Implementation of Iterative Quantum Amplitude Estimation [1]. Given AA s.t. A0>n0>={1a}ψ0>n0>+{a}ψ1>n1>A`|0>`_n`|0>` = \sqrt\{1-a\}|\psi_0>_n`|0>` + \sqrt\{a\}|\psi_1>_n`|1>`, the algorithm estimates aa by iteratively sampling QkAQ^kA, where Q=AS0A{}S{ψ0}Q=AS_0A^\{\dagger\}S_\{\psi_0\}, and kk is an integer variable. For estimating aa, The algorithm estimates θa\theta_a which is defined by a=sin2(θa)a = sin^2(\theta_a), so it starts with a confidence interval (0,π/2)(0, \pi/2) and narrows down this interval on each iteration according to the sample results. Methods:
NameDescription
get_modelImplement the quantum part of IQAE in terms of the Qmod Model.
get_qprogCreate an executable quantum Program for IQAE.
runExecutes IQAE’s quantum program with the provided epsilon, alpha, and execution preferences.

get_model

get_model(
self:
) -> SerializedModel
Implement the quantum part of IQAE in terms of the Qmod Model Parameters:
NameTypeDescriptionDefault
selfrequired
Returns:
  • Type: SerializedModel
  • A serialized model.

get_qprog

get_qprog(
self:
) -> QuantumProgram
Create an executable quantum Program for IQAE. Parameters:
NameTypeDescriptionDefault
selfrequired
Returns:
  • Type: QuantumProgram
  • Quantum program. See QuantumProgram.

run

run(
self: ,
epsilon: float,
alpha: float,
execution_preferences: ExecutionPreferences | None = None
) -> IQAEResult
Executes IQAE’s quantum program with the provided epsilon, alpha, and execution preferences. If execution_preferences has been proved, or if it does not contain num_shot, then num_shot is set to 2048. Parameters:
NameTypeDescriptionDefault
selfrequired
epsilonfloatTarget accuracy in therm of θa\theta_a e.g a=sin2(θa±ϵ)a = sin^2(\theta_a \pm \epsilon) .required
alphafloatSpecifies the confidence level (1 - alpha)required
execution_preferencesExecutionPreferences | NonePreferences for the execution of the model. See ExecutionPreferences (Optional).None
Members:
NameDescription
IQAEIterationDataHandles the data storage for a single iteration of the Iterative Quantum Amplitude Estimation algorithm.
IQAEResultRepresents the result of an Iterative Quantum Amplitude Estimation (IQAE) process.

IQAEIterationData

Handles the data storage for a single iteration of the Iterative Quantum Amplitude Estimation algorithm. This class is intended to represent the results and state of a single Grover iteration of the IQAE process. Attributes:
NameTypeDescription
grover_iterationsintThe iteration number of Grover’s algorithm.
sample_resultsExecutionDetailsThe ExecutionDetails of Grover iteration. See ExecutionDetails.

grover_iterations

grover_iterations: int

sample_results

sample_results: ExecutionDetails

IQAEResult

Represents the result of an Iterative Quantum Amplitude Estimation (IQAE) process. This class encapsulates the output of the IQAE algorithm, including the estimated value, confidence interval, intermediate iteration data, and any warnings generated during the computation. Attributes:
NameTypeDescription
estimationfloatEstimation of the amplitude.
confidence_intervallist[float]The interval in which the amplitude is within, with a probability equal to epsilon.
iterations_datalist[IQAEIterationData]List of IQAEIterationData of each Grover iteration.
warningslist[str]List of warnings generated during the IQAE process of each Grover iteration.

estimation

estimation: float

confidence_interval

confidence_interval: list[float] = Field(min_length=2, max_length=2)

iterations_data

iterations_data: list[IQAEIterationData]

warnings

warnings: list[str]