Skip to content

Executor

Classiq executor allows you to easily execute quantum programs on different quantum hardware vendors. The executor gets as input a quantum program instruction set (e.g. OpenQASM), and a quantum hardware to execute on (e.g. IonQ hardware). In addition, the executor supports proprietary and generic execution schemes (e.g. VQE).

Please note that usage of some hardware providers may require an appropriate account.

Usage

In order to use the executor, you may pick one of the following options:

  • Classiq python SDK.
  • VS Code Classiq extension.

The "backend_preferences" field determines the hardware to execute on. There are four ways to get the measurement results of the execution.

  1. The counts attribute of the result allows access to the measurement results of all qubits.
  2. The counts_of_qubits method allows access to results of specific qubits. The order of qubits in the measurement result is determined by their order in the qubits argument of the method.
  3. The counts_of_output method is similar to counts_of_qubits, but receives an output name as an argument. Note it may only be used if the generated model has outputs. See Model Inputs & Outputs for output setting instructions.
  4. The counts_of_multiple_outputs is similar to counts_of_output. It receives a tuple of output names, and returns the counts of all specified outputs, keyed by a tuple of states matching the requested outputs.

Circuit Example

Create the following file: execution_preferences.exct

{
    "preferences": {
        "num_shots": 1000,
        "backend_preferences": {
            "backend_service_provider": "IBM Quantum",
            "backend_name": "aer_simulator"
        }
    }
}
Run Classiq execute command (Classiq: Execute Quantum Program), choose a file containing the program and pick it's instruction set (e.g. QASM or ionq) and the outptut path.

from classiq import ModelDesigner, Executor
from classiq.builtin_functions import StatePreparation

from classiq.interface.backend import backend_preferences
from classiq.interface.executor import execution_preferences
from classiq.interface.generator.state_preparation import (
    Metrics,
    NonNegativeFloatRange,
)

# circuit generation
model_designer = ModelDesigner()
probabilities = (0.5, 0.1, 0.2, 0.005, 0.015, 0.12, 0.035, 0.025)
sp_params = StatePreparation(
    probabilities=probabilities,
    num_qubits=3,
    error_metric={Metrics.KL: NonNegativeFloatRange(upper_bound=0.01)},
)
model_designer.StatePreparation(sp_params)
circuit = model_designer.synthesize()

res = Executor(
    num_shots=1000,
    backend_preferences=backend_preferences.IBMBackendPreferences(
        backend_name="aer_simulator"
    ),
).execute(circuit)
all_qubit_counts = res.counts
first_two_qubit_counts = res.counts_of_qubits((0, 1))
Note that the code input argument in QuantumProgram class can accept any string in QASM or ionq format and can be executed without generating it.

Amplitude Estimation Example

In the execution preferences, add "amplitude_estimation" with three fields:

-alpha, confidence level of the AE algorithm

-epsilon: estimation precision

-objective_qubits: list specifying on which qubits to perform the amplitude estimation, qubits numbering starts with zero

"amplitude_estimation":{
    "alpha":0.05,
    "epsilon":0.01,
    "objective_qubits": [1]
}

Is equal to:

\[ P(|{a_{estimation} - a_{real}}| > epsilon) < alpha \]

where \(a_{real} = P(Qubit_1 = \ket{1})\).

Create the following file: execution_preferences.exct

{
    "preferences": {
        "backend_preferences": {
            "backend_service_provider": "IBM Quantum",
            "backend_name": "aer_simulator"
        },
        "amplitude_estimation":{
            "alpha":0.05,
            "epsilon":0.01,
            "objective_qubits": [1]
        }
    }
}
Run Classiq execute command (Classiq: Execute Quantum Program), choose a file containing the program and pick it's instruction set (e.g. QASM or ionq) and the outptut path.

from classiq import Executor
from classiq.interface.backend import backend_preferences
from classiq.interface.executor import execution_preferences

qasm = 'OPENQASM 2.0;\ninclude "qelib1.inc";\nqreg q[2];\nx q[1];\n'

res = Executor(
    amplitude_estimation=execution_preferences.AmplitudeEstimation(
        alpha=0.05, epsilon=0.01, objective_qubits=[1]
    ),
    backend_preferences=backend_preferences.IBMBackendPreferences(
        backend_name="aer_simulator_density_matrix"
    ),
).execute(qasm)

Note, in the SDK it is also possible to generate multiple backend preferences from a single provider using the 'batch_preferences' command.

from classiq.interface.backend import backend_preferences

backends = backend_preferences.IBMBackendPreferences.batch_preferences(
    backend_names=["aer_simulator", "aer_simulator_density_matrix"],
    access_token=None,
)

Supported Backend Providers

The different executions types (and commands) for textual model are:

  • Execute Quantum Program: Executes a quantum program object, i.e. simply run the a given circuit.
  • Execute Generated Circuit: Execute a generated circuit, the result of a generation call. This can be used for finance and grover applications. See Finance.