Remote devices handling

In order to facilitate the handling of remote QPUs, helper functions were implemented. Most of them are aimed at internal usage even though you can absolutely use them yourself. As a user, the elements of this page of interest for you are most likely:

To setup your access to remote QPUs, see the Set up remote accesses section.

Provider specifics

Even though most of our interfaces use abstractions such that you do not need to know on which provider’s QPU your code is running, we need at some point to tackle the specifics of each providers. Most (hopefully all soon) of it is tackled in these modules.

To see which devices are available, see Devices.

IBM

Connection

config_ibm_account(token, channel)[source]

Configure and save locally IBM Quantum account’s information.

Parameters:
  • token (str) – IBM Quantum API token (API key).

  • channel (str) – The channel to use for the account (default is “ibm_quantum_platform”).

Raises:

IBMRemoteExecutionError – If the account could not be saved.

delete_ibm_account()[source]

Delete the locally stored IBM Quantum account configuration.

get_QiskitRuntimeService()[source]

Return the QiskitRuntimeService needed for remote connection and execution.

Raises:

IBMRemoteExecutionError – When the qiskit runtime is not configured or the configuration cannot be retrieved.

Return type:

QiskitRuntimeService

Example

>>> service = get_QiskitRuntimeService()
>>> service.jobs()
[<RuntimeJob('cmdj3b4nktricigarn8g', 'estimator')>,
 <RuntimeJob('cmdj3a74mi97k7j7ujv0', 'sampler')>,
 <RuntimeJob('cmama29054sir2cq94og', 'estimator')>,
 <RuntimeJob('cmama14pduldih1q4ktg', 'sampler')>,
 <RuntimeJob('cm7vds4pduldih1k1mq0', 'sampler')>]
get_active_account_info()[source]

Return the information concerning the active IBM Quantum account.

Returns:

The description containing the account information.

Return type:

str

Example

>>> print(get_active_account_info())
    Channel: ibm_quantum
    Instance: ibm-q-startup/colibritd/default
    Token: bf5e5*****
    URL: https://auth.quantum-computing.ibm.com/api
    Verify: True
get_all_job_ids()[source]

Retrieve all the job ids of this account.

Returns:

The list of job ids.

Return type:

list[str]

Example

>>> get_all_job_ids()
['cm6pp7e879ps6bbo7m30', 'cm6ou0q70abqioeudkd0', 'cm6opgcpduldih1hq7j0', 'cm01vp4pduldih0uoi2g',
'cnvw8z3b08x0008y3e4g', 'cnvw7qyb08x0008y3e0g', 'cnvw7fdvn4c0008a6ztg', 'cnvw79dvn4c0008a6zt0',
'cnvw64rb08x0008y3dx0', 'cnvw5z7wsx00008wybcg', 'cmdj3b4nktricigarn8g', 'cmdj3a74mi97k7j7ujv0',
'cmama29054sir2cq94og', 'cmama14pduldih1q4ktg', 'cm80qmi70abqiof0o170', 'cm80qlkpduldih1k4png',
'cm80pb1054sir2ck9i3g', 'cm80pa6879ps6bbqg2pg', 'cm7vdugiidfp3m8rg02g', 'cm7vds4pduldih1k1mq0']
get_backend(device)[source]

Retrieve the corresponding qiskit remote device.

Parameters:

device (IBMDevice) – The device to get from the qiskit Runtime service.

Returns:

The requested backend.

Raises:
  • ValueError – If the required backend is a local simulator.

  • IBMRemoteExecutionError – If the device was not found.

Return type:

BackendV2

Example

>>> brisbane = get_backend(IBMDevice.IBM_BRISBANE)
>>> brisbane.properties().gates[0].parameters
[Nduv(datetime.datetime(2024, 1, 9, 11, 3, 18, tzinfo=tzlocal()), gate_error, , 0.00045619997922344296),
 Nduv(datetime.datetime(2024, 1, 9, 15, 41, 39, tzinfo=tzlocal()), gate_length, ns, 60)]
setup_ibm_account()[source]

Set up and update the IBM Quantum account using the existing configuration (or by asking for the token if not already configured).

Note

  • The credential you enter here is an IBM Cloud API key.

  • The same IBM Cloud API key is used for both channels: ibm_quantum_platform ibm_cloud

test_connection()[source]

Test if the connection to the provider works.

Returns:

False if login failed.

Return type:

bool

Execution

check_job_compatibility(job)[source]

Checks whether the job in parameter has coherent and compatible attributes.

Parameters:

job (Job) – Job for which we want to check compatibility.

Raises:

DeviceJobIncompatibleError – If there is a mismatch between information contained in the job (measure and job_type, device and job_type, etc…).

compute_expectation_value(ibm_circuit, job, simulator)[source]

Configures observable job and run it locally, and returns the corresponding Result.

Parameters:
  • ibm_circuit (QuantumCircuit) – QuantumCircuit (with its qubits already reversed) for which we want to estimate the expectation value.

  • job (Job) – Job containing the execution input data.

  • simulator (Optional['AerSimulator']) – AerSimulator to be used to set the EstimatorV2 options.

Returns:

The Result of the job.

Raises:

ValueError – If the job’s device is not a IBMSimulatedDevice and simulator is None.

Return type:

Result

Note

This function is not meant to be used directly, please use run() instead.

extract_result(result, job, device)[source]

Parses a result from IBM execution (remote or local) in a MPQP Result.

Parameters:
  • result (QiskitResult | EstimatorResult | PrimitiveResult[PubResult | SamplerPubResult]) – Result returned by IBM after running of the job.

  • job (Optional[Job]) – MPQP job used to generate the run. Enables a more complete result.

  • device (IBMDevice | StaticIBMSimulatedDevice | AZUREDevice) – IBMDevice on which the job was submitted. Used to know if the run was remote or local

Returns:

The qiskit result converted to our format.

Return type:

Result

extract_samples(job, result)[source]

Extracts measurement samples from the execution results.

Parameters:
  • job (Job) – MPQP job used to generate the run. Enables a more complete result.

  • result (QiskitResult) – Result returned by IBM after running of the job.

Returns:

A list of sample objects representing measurement outcomes.

Return type:

list[Sample]

generate_qiskit_noise_model(circuit, multiple_noise_warning=True)[source]

Generate a qiskit noise model packing all the NoiseModel attached to the given QCircuit.

In qiskit, the noise cannot be applied to qubits unaffected by any operations. For this reason, this function also returns a copy of the circuit padded with identities on “naked” qubits.

Parameters:
  • circuit (QCircuit) – Circuit containing the noise models to pack.

  • multiple_noise_warning (bool) – Boolean to enable/disable warnings about multiple noise on the same gate. Default True, warnings will be raised.

Returns:

A qiskit noise model combining the provided noise models and the modified circuit, padded with identities on the “naked” qubits.

Return type:

tuple[‘Qiskit_NoiseModel’, QCircuit]

Note

The qubit order in the returned noise model is reversed to match qiskit’s qubit ordering conventions.

get_result_from_ibm_job_id(job_id)[source]

Retrieves from IBM remote platform and parse the result of the job_id given in parameter. If the job is still running, we wait (blocking) until it is DONE.

Parameters:

job_id (str) – Id of the remote IBM job.

Returns:

The result (or batch of result) converted to our format.

Return type:

Result

run_aer(job)[source]

Executes the job on the right AER local simulator precised in the job in parameter.

Parameters:

job (Job) – Job to be executed.

Returns:

the result of the job.

Note

This function is not meant to be used directly, please use run() instead.

run_ibm(job)[source]

Executes the job on the right IBM Q device precised in the job in parameter.

Parameters:

job (Job) – Job to be executed.

Returns:

The result of the job.

Return type:

Result

Note

This function is not meant to be used directly, please use run() instead.

run_remote_ibm(job)[source]

Submits the job on the right IBM remote device, precised in the job in parameter, and waits until the job is completed.

Parameters:

job (Job) – Job to be executed.

Returns:

A Result after submission and execution of the job.

Return type:

Result

Note

This function is not meant to be used directly, please use run() instead.

submit_remote_ibm(job)[source]

Submits the job on the remote IBM device (quantum computer or simulator).

Parameters:

job (Job) – Job to be executed.

Returns:

IBM’s job id and the qiskit job itself.

Return type:

tuple[str, ‘RuntimeJobV2’]

Note

This function is not meant to be used directly, please use run() instead.

Atos/Eviden

Connection

config_qlm_account(username, password, global_config)[source]

Configures and saves locally QLM account’s information.

Parameters:
  • username (str) – QLM username.

  • password (str) – QLM password.

  • global_config (bool) – If True, this QLM account will be configured to work even outside MPQP.

Raises:

QLMRemoteExecutionError – If the account could not be saved.

Return type:

bool

delete_qlm_account()[source]

Deletes the locally stored QLM account configuration.

Return type:

tuple[str, list[Any]]

get_QLMaaSConnection()[source]

Connects to the QLM and returns the QLMaaSConnection. If the connection was already established, we only return the one stored in global variable, otherwise we instantiate a new QLMaaSConnection.

get_all_job_ids()[source]

Retrieves from the remote QLM all the job-ids associated with this account.

Returns:

List of all job-ids associated with this account.

Return type:

list[str]

Example

>>> get_all_job_ids()
['Job144361', 'Job144360', 'Job144359', 'Job144358', 'Job144357', 'Job143334', 'Job143333', 'Job143332',
'Job141862', 'Job141861', 'Job141722', 'Job141720', 'Job141716', 'Job141715', 'Job141712', 'Job19341']
setup_qlm_account()[source]

Setups the QLM account, by looking at the existing configuration, asking for username/password and updating the current account.

Return type:

tuple[str, list[Any]]

Execution

extract_observable_result(myqlm_result, job=None, device=ATOSDevice.MYQLM_PYLINALG)[source]

Constructs a Result from the result given by the myQLM/QLM run in observable mode.

Parameters:
  • myqlm_result (list['QLM_Result']) – Result returned by myQLM/QLM after running of the job.

  • job (Optional[Job]) – Original MPQP job used to generate the run. Used to retrieve more easily info to instantiate the result.

  • device (ATOSDevice) – ATOSDevice on which the job was submitted. Used to know if the run was remote or local.

Returns:

A Result containing the result info extracted from the myQLM/QLM observable result.

Return type:

Result

extract_result(myqlm_result, job=None, device=ATOSDevice.MYQLM_PYLINALG)[source]

Constructs a Result from the result given by the myQLM/QLM run.

Parameters:
  • myqlm_result (list['QLM_Result']) – Result returned by myQLM/QLM after running of the job.

  • job (Optional[Job]) – Original MPQP job used to generate the run. Used to retrieve more easily info to instantiate the result.

  • device (ATOSDevice) – ATOSDevice on which the job was submitted. Used to know if the run was remote or local.

Returns:

A Result containing the result info extracted from the myQLM/QLM result.

Return type:

Result

extract_sample_result(myqlm_result, job=None, device=ATOSDevice.MYQLM_PYLINALG)[source]

Constructs a Result from the result given by the myQLM/QLM run in sample mode.

Parameters:
  • myqlm_result (QLM_Result) – Result returned by myQLM/QLM after running of the job.

  • job (Optional[Job]) – Original MPQP job used to generate the run. Used to retrieve more easily info to instantiate the result.

  • device (ATOSDevice) – ATOSDevice on which the job was submitted. Used to know if the run was remote or local.

Returns:

A Result containing the result info extracted from the myQLM/QLM sample result.

Return type:

Result

extract_state_vector_result(myqlm_result, job=None, device=ATOSDevice.MYQLM_PYLINALG)[source]

Constructs a Result from the result given by the myQLM/QLM run in state vector mode.

Parameters:
  • myqlm_result (QLM_Result) – Result returned by myQLM/QLM after running of the job.

  • job (Optional[Job]) – Original MPQP job used to generate the run. Used to retrieve more easily info to instantiate the result.

  • device (ATOSDevice) – ATOSDevice on which the job was submitted. Used to know if the run was remote or local.

Returns:

A Result containing the result info extracted from the myQLM/QLM statevector result.

Return type:

Result

generate_hardware_model(noises, nb_qubits)[source]

Generates the QLM HardwareModel corresponding to the list of NoiseModel in parameter. The algorithm consider the cases when there are gate noise, for all qubits or specific to some, and the same for idle noise.

Parameters:
  • noises (list[NoiseModel]) – List of NoiseModel of a QCircuit used to generate a QLM HardwareModel.

  • nb_qubits (int) – Number of qubits of the circuit.

Returns:

The HardwareModel corresponding to the combination of NoiseModels given in parameter.

Return type:

HardwareModel

generate_observable_job(myqlm_circuit, job)[source]

Generates a myQLM job from the myQLM circuit and observable.

Parameters:
  • myqlm_circuit (Circuit) – MyQLM circuit of the job.

  • job (Job) – Original MPQP job used to generate the myQLM job.

Returns:

A myQLM Job for retrieving the expectation value of the observable.

Return type:

list[‘JobQLM’]

generate_sample_job(myqlm_circuit, job)[source]

Generates a myQLM job from the myQLM circuit and job sample info (target, shots, …).

Parameters:
  • myqlm_circuit (Circuit) – MyQLM circuit of the job.

  • job (Job) – Original mpqp job used to generate the myQLM job.

Returns:

A myQLM Job for sampling the circuit according to the mpqp Job parameters.

Return type:

JobQLM

generate_state_vector_job(myqlm_circuit)[source]

Generates a myQLM job from the myQLM circuit.

Parameters:

myqlm_circuit (Circuit) – MyQLM circuit of the job.

Returns:

A myQLM Job to retrieve the statevector of the circuit.

Return type:

JobQLM

get_local_qpu(device)[source]

Returns the myQLM local QPU associated with the ATOSDevice given in parameter.

Parameters:

device (ATOSDevice) – ATOSDevice referring to the myQLM local QPU.

Raises:

ValueError – If the required backend is a remote simulator.

Return type:

QPUHandler

get_remote_qpu(device, job)[source]

Returns the QLM remote QPU associated with the ATOSDevice given in parameter.

Parameters:
  • device (ATOSDevice) – ATOSDevice referring to the QLM remote QPU.

  • job (Job) – MPQP job containing all info about the execution.

Raises:

ValueError – If the required backend is a local simulator.

get_result_from_qlm_job_id(job_id)[source]

Retrieves the QLM result, described by the job_id in parameter, from the remote QLM and converts it in a MPQP Result. If the job is still running, we wait (blocking) until its status becomes DONE.

Parameters:

job_id (str) – Id of the remote QLM job.

Returns:

The converted result.

Raises:
Return type:

Result

job_pre_processing(job)[source]

Extracts the myQLM circuit and check if job.type and job.measure are coherent.

Parameters:

job (Job) – Mpqp job used to instantiate the myQLM circuit.

Returns:

The myQLM Circuit translated from the circuit of the job in parameter.

Return type:

Circuit

run_QLM(job)[source]

Submits the job on the remote QLM machine and waits for it to be done.

Parameters:

job (Job) – Job to be executed.

Returns:

A Result after submission and execution of the job.

Raises:

ValueError – If the device is not a remote QLM device of the enum ATOSDevice.

Return type:

Result

Note

This function is not meant to be used directly, please use run() instead.

run_atos(job)[source]

Executes the job on the right ATOS device precised in the job in parameter.

Parameters:

job (Job) – Job to be executed.

Returns:

A Result after submission and execution of the job.

Return type:

Result

Note

This function is not meant to be used directly, please use run() instead.

run_myQLM(job)[source]

Executes the job on the local myQLM simulator.

Parameters:

job (Job) – Job to be executed.

Returns:

A Result after submission and execution of the job.

Return type:

Result

Note

This function is not meant to be used directly, please use run() instead.

submit_QLM(job)[source]

Submits the job on the remote QLM machine.

Parameters:

job (Job) – Job to be executed.

Returns:

The job_id and the AsyncResult of the submitted job.

Raises:
  • ValueError – When job of type different from \(STATE_VECTOR\), \(OBSERVABLE\) or \(SAMPLE\)

  • NotImplementedError – If the basis given is not the ComputationalBasis

Return type:

tuple[str, list[‘AsyncResult’]]

Note

This function is not meant to be used directly, please use run() instead.

AWS

Connection

configure_account_iam()[source]

Configure IAM authentication for Amazon Braket.

Return type:

tuple[str, list[Any]]

configure_account_sso()[source]

Configure SSO authentication for Amazon Braket.

Return type:

tuple[str, list[Any]]

delete_aws_braket_account()[source]

Deletes the locally stored AWS Braket configuration.

Return type:

tuple[str, list[Any]]

get_all_partial_ids()[source]

Retrieves all the task ids of this account/group from AWS and extracts the significant part.

Example

>>> get_all_partial_ids()
['6a46ae9a-d02f-4a23-b46f-eae43471bc22',
 '11db7e68-2b17-4b00-a4ec-20f662fd4876',
 '292d329f-727c-4b92-83e1-7d4bedd4b243',
 '4b94c703-2ce8-480b-b3f3-ecb2580dbb82',
 'edc094aa-23e8-4a8c-87be-f2e09281d79d',
 'af9e623a-dd1c-4ecb-9db6-dbbd1af08110']
Return type:

list[str]

get_all_task_ids()[source]

Retrieves all the task ids of this account/group from AWS.

Example

>>> get_all_task_ids()
['arn:aws:braket:us-east-1:752542621531:quantum-task/6a46ae9a-d02f-4a23-b46f-eae43471bc22',
 'arn:aws:braket:us-east-1:752542621531:quantum-task/11db7e68-2b17-4b00-a4ec-20f662fd4876',
 'arn:aws:braket:us-east-1:752542621531:quantum-task/292d329f-727c-4b92-83e1-7d4bedd4b243',
 'arn:aws:braket:us-east-1:752542621531:quantum-task/4b94c703-2ce8-480b-b3f3-ecb2580dbb82',
 'arn:aws:braket:us-east-1:752542621531:quantum-task/edc094aa-23e8-4a8c-87be-f2e09281d79d',
 'arn:aws:braket:us-east-1:752542621531:quantum-task/af9e623a-dd1c-4ecb-9db6-dbbd1af08110']
Return type:

list[str]

get_aws_braket_account_info()[source]

Retrieves AWS Braket credentials information including access key ID, secret access key, and region. For SSO authentication, the session token is also included.

Returns:

A formatted string containing AWS credentials information with an obfuscated secret access key.

Return type:

str

Examples

>>> print(get_aws_braket_account_info())
    Authentication method: IAM
    Access Key ID: 'AKIA26JFZI8JFZ18FI4N'
    Secret Access Key: 'E9oF9*********************************'
    Region: 'us-east-1'
>>> print(get_aws_braket_account_info())
    Authentication method: SSO
    Access Key ID: 'ASIA26JFEZ6JEOZ9JC7K'
    Secret Access Key: 'FiZp3***********************************'
    SSO Session Token: 'EfGkf2kbI3nfC5V...IIZUf79jofZNF=='
    Region: 'us-east-1'

Note

This function assumes that the AWS credentials are already configured in the AWS credentials/config file ~/.aws/credentials.

get_braket_device(device, is_noisy=False, is_gate_model=True)[source]

Returns the AwsDevice device associate with the AWSDevice in parameter.

Parameters:
  • device (AWSDevice) – AWSDevice element describing which remote/local AwsDevice we want.

  • is_noisy (bool) – If the expected device is noisy or not.

  • is_gate_model (bool) – If the expected device supports gate-based circuits or not.

Raises:

AWSBraketRemoteExecutionError – If the device or the region could not be retrieved.

Return type:

BraketDevice

Example

>>> device = get_braket_device(AWSDevice.RIGETTI_ANKAA_3)
>>> device.properties.action['braket.ir.openqasm.program'].supportedResultTypes
[ResultType(name='Sample', observables=['x', 'y', 'z', 'h', 'i'], minShots=10, maxShots=50000),
 ResultType(name='Expectation', observables=['x', 'y', 'z', 'h', 'i'], minShots=10, maxShots=50000),
 ResultType(name='Variance', observables=['x', 'y', 'z', 'h', 'i'], minShots=10, maxShots=50000),
 ResultType(name='Probability', observables=None, minShots=10, maxShots=50000)]
get_user_sso_credentials()[source]
Return type:

dict[str, str] | None

setup_aws_braket_account()[source]

Set-up the connection to an Amazon Braket account using user input.

This function checks whether an Amazon Braket account is already configured and prompts the user to update it if needed. The function attempts to configure the Amazon Braket account using two authentication methods:

IAM (Identity and Access Management):
  • The user is guided to enter their AWS access key, secret access key, and region.

  • Credentials are stored in the default AWS credentials file.

SSO (Single Sign-On):
  • The user is guided through the process of configuring SSO authentication.

  • SSO credentials, including the session token, are retrieved and provided by the user

    to complete the authentication process.

It then collects the user’s AWS access key, AWS secret key (hidden input), AWS session token (hidden input) in case of SSO auth and the AWS region for Amazon Braket.

Returns:

A tuple containing a message indicating the result of the setup (e.g., success, cancelled, or error, …) and an empty list. The list is included for consistency with the existing code structure.

Return type:

tuple[str, list[Any]]

update_aws_credentials_file(profile_name, access_key_id, secret_access_key, session_token, region)[source]

Create or update the ~/.aws/credentials file with the provided credentials. Ensure that the directory and file exist before making changes.

Parameters:
  • profile_name (str)

  • access_key_id (str)

  • secret_access_key (str)

  • session_token (str | None)

  • region (str)

validate_aws_credentials()[source]

Validate AWS credentials by calling STS get_caller_identity.

Return type:

bool

Execution

apply_noise_to_braket_circuit(braket_circuit, noises, nb_qubits)[source]

Apply noise models to a Braket circuit.

This function applies noise models to a given Braket circuit based on the specified noise models and the number of qubits in the circuit. It modifies the original circuit by adding noise instructions and returns a new circuit with the noise applied.

Parameters:
  • braket_circuit (Circuit) – The Braket circuit to apply noise to.

  • noises (list[NoiseModel]) – A list of noise models to apply to the circuit.

  • nb_qubits (int) – The number of qubits in the circuit.

Returns:

A new circuit with the noise applied.

Return type:

Circuit

estimate_cost_single_job(job, hybrid_iterations=1, estimated_time_seconds=3)[source]

Estimates the cost of executing a Job on a remote AWS Braket device.

Parameters:
  • job (Job) – Job for which we want to estimate the cost. The job’s device must be an AWSDevice.

  • hybrid_iterations (int) – Number of iteration in a case of a hybrid (quantum-classical) job.

  • estimated_time_seconds (int) – Estimated runtime for simulator jobs (in seconds). The minimum duration billing is 3 seconds.

Returns:

The estimated price (in USD) for the execution of the job in parameter.

Return type:

float

Example

>>> circuit = QCircuit([H(0), CNOT(0, 1), CNOT(1, 2), BasisMeasure(shots=245)])
>>> job = generate_job(circuit, AWSDevice.IONQ_ARIA_1)
>>> estimate_cost_single_job(job, hybrid_iterations=150)
1147.5
extract_result(braket_result, job=None, device=AWSDevice.BRAKET_LOCAL_SIMULATOR)[source]

Constructs a Result from the result given by the run with Braket.

Parameters:
  • braket_result (GateModelQuantumTaskResult) – Result returned by myQLM/QLM after running of the job.

  • job (Optional[Job]) – Original mpqp job used to generate the run. Used to retrieve more easily info to instantiate the result.

  • device (AWSDevice) – AWSDevice on which the job was submitted.

Returns:

The braket result converted to our format.

Return type:

Result

get_result_from_aws_task_arn(task_arn)[source]

Retrieves the result, described by the job_id in parameter, from the remote QLM and converts it into an mpqp result.

If the job is still running, we wait (blocking) until it is DONE.

Parameters:

task_arn (str) – Arn of the remote aws task.

Raises:

AWSBraketRemoteExecutionError – When the status of the task is unknown.

Return type:

Result

run_braket(job)[source]

Executes the job on the right AWS Braket device (local or remote) precised in the job in parameter and waits until the task is completed, then returns the Result.

Parameters:

job (Job) – Job to be executed, it MUST be corresponding to a mpqp.execution.devices.AWSDevice.

Returns:

The result of the job.

Return type:

Result

Note

This function is not meant to be used directly, please use run() instead.

run_braket_observable(job)[source]

Returns the result of an OBSERVABLE job.

TODO: check that the link bellow is correctly generated. If optimize_measurement, this function will run based on the grouping of the pauli monomials (Read TODO here for more information).

Otherwise each observable will be ran one by one.

Parameters:

job (Job) – Job to be executed.

Returns:

A result containing the expectation values of the observables.

submit_job_braket(job)[source]

Submits the job to the right local/remote device and returns the generated task.

Parameters:

job (Job) – Job to be executed, it MUST be corresponding to a mpqp.execution.devices.AWSDevice.

Returns:

The task’s id and the Task itself.

Raises:
  • ValueError – If the job type is not supported for noisy simulations, or if it is of type OBSERVABLE but got no ExpectationMeasure.

  • NotImplementedError – If the job type is not STATE_VECTOR, SAMPLE or OBSERVABLE.

Return type:

tuple[str, ‘QuantumTask’]

Note

This function is not meant to be used directly, please use run() instead.

Google

Connection

For now, Google’s access is very restricted, so this section is mostly here for future proofing.

get_all_job_ids()[source]

Retrieves all job IDs associated with google jobs.

Note

For now, no provider is exclusively attached to cirq, so this will not return any job ID. For job IDs relative to ionQ, use get_ionq_job_ids().

Returns:

A list of job IDs.

Return type:

list[str]

Execution

apply_noise_to_cirq_circuit(cirq_circuit, noises)[source]

Apply noise models to a Cirq circuit.

This function applies noise models to a given Cirq circuit based on the specified noise models and the number of qubits in the circuit. It constructs a new circuit by adding noise operations after the original gates and returns the circuit with the noise applied.

Parameters:
  • cirq_circuit (CirqCircuit) – The Cirq circuit to apply noise to.

  • noises (list[NoiseModel]) – The noise models to apply to the circuit.

Returns:

A new circuit with the noise operations applied.

Return type:

CirqCircuit

extract_result_SAMPLE(result, job)[source]

Extracts the result from a sample-based job.

Parameters:
  • result (CirqResult) – The result of the simulation.

  • job (Job) – The original job.

Returns:

The formatted result.

Return type:

Result

extract_result_STATE_VECTOR(result, job)[source]

Extracts the result from a state vector-based job.

Parameters:
  • result (StateVectorTrialResult) – The result of the simulation.

  • job (Job) – The original job.

Returns:

The formatted result.

Return type:

Result

run_cirq_observable(job, circuit, simulator)[source]

Returns the result of an OBSERVABLE job. Here optimize_measurement allows cirq to do the grouping on the Pauli string of every observable. Otherwise each observables are sent without modification.

This function should be called by run_local and run_local_processor, not with any remote jobs. :param job: Job to be executed. :param circuit: The circuit to measure. :param simulator: The simulator on which the circuit is ran.

Returns:

A result containing the expectation values of the observables.

Parameters:
  • job (Job)

  • circuit (CirqCircuit)

  • simulator (Union['Simulator', 'SimulatedLocalEngine'])

Return type:

Result

run_cirq_observable_remote(job, circuit, service)[source]

Returns the result of an OBSERVABLE job. Here optimize_measurements will performs the whole grouping of the pauli monomials in mpqp. This function is not available without optimize_measurement at True.

This function should be called by run_remote, not with any local jobs. :param job: Job to be executed. :param circuit: The circuit to measure. :param service: The service on which the circuit is ran.

Returns:

A result containing the expectation values of the observables.

Parameters:
  • job (Job)

  • circuit (CirqCircuit)

  • service (Service)

Return type:

Result

run_google(job)[source]

Executes the job on the right Google device precised in the job in parameter.

Parameters:

job (Job) – Job to be executed.

Returns:

A Result after submission and execution of the job. Note:

Return type:

Result

Note

This function is not meant to be used directly, please use run() instead.

run_google_remote(job)[source]

Executes the job remotely on a Google quantum device. At present, only IonQ devices are supported.

Parameters:

job (Job) – Job to be executed, it MUST be corresponding to a GOOGLEDevice.

Returns:

The result after submission and execution of the job.

Raises:
  • ValueError – If the job’s device is not an instance of GOOGLEDevice.

  • NotImplementedError – If the job’s device is not supported (only IonQ devices are supported currently).

  • NotImplementedError – If the job type or basis measure is not supported.

Return type:

Result

run_local(job)[source]

Executes the job locally.

Parameters:

job (Job) – Job to be executed, it MUST be corresponding to a GOOGLEDevice.

Returns:

The result after submission and execution of the job.

Raises:

ValueError – If the job device is not GOOGLEDevice.

Return type:

Result

run_local_processor(job)[source]

Executes the job locally on processor.

Parameters:

job (Job) – Job to be executed, it MUST be corresponding to a GOOGLEDevice.

Returns:

The result after submission and execution of the job.

Return type:

Result

IonQ

Connection

config_ionq_key()[source]

Configure the IonQ account by setting the API token.

Returns:

A message indicating the result of the configuration and an empty list (used to conform to the protocol needed by the functions calling this one).

Return type:

tuple

delete_ionq_account()[source]
get_ionq_account_info()[source]

Get the IonQ API key from the environment variables.

Returns:

A string containing the IonQ API key.

Return type:

str

get_ionq_job_ids()[source]

Retrieves ionq job IDs associated with IonQ jobs.

Returns:

A list of job IDs.

Return type:

list[str]

test_ionq_connection(key=None)[source]

Test the connection to the IonQ service.

Parameters:

key (str | None) – The API key for authenticating with the IonQ service.

Returns:

True if the connection is successful, False otherwise.

Return type:

bool

Azure

Connection

config_azure_account()[source]

Configure the Azure account by setting the resource ID and location.

This function will prompt the user for their Azure resource ID and location. If the account is already configured, the user will be given the option to update the configuration. The function validates the connection to Azure before saving the credentials.

Returns:

A tuple containing a message indicating the result of the configuration and an empty list. If the configuration is successful, the message indicates the success, otherwise, it indicates a failure or cancellation.

delete_azure_account()[source]

Deletes the locally stored Azure Quantum account configuration.

get_all_job_ids()[source]

Retrieve the job IDs associated with the current Azure account/group.

Returns:

All job IDs of your tasks saved in Azure Quantum Workspace.

Example

>>> get_all_jobs_ids()
['6a46ae9a-d02f-4a23-b46f-eae43471bc22',
 '11db7e68-2b17-4b00-a4ec-20f662fd4876',
 '292d329f-727c-4b92-83e1-7d4bedd4b243',
 '4b94c703-2ce8-480b-b3f3-ecb2580dbb82',
 'edc094aa-23e8-4a8c-87be-f2e09281d79d',
 'af9e623a-dd1c-4ecb-9db6-dbbd1af08110']
get_azure_account_info()[source]

Retrieve Azure resource ID and location information from the environment variables and format them in a way to be displayed to the user.

Returns:

The resource id and location in a displayable format.

Return type:

str

Example

>>> get_azure_account_info()
AZURE_RESOURCE_ID: /subs*****
AZURE_LOCATION: East US
get_azure_provider()[source]

Retrieve the Azure Quantum Provider.

Returns:

An instance of Azure Quantum Provider linked to the Azure Quantum Workspace.

Return type:

AzureQuantumProvider

Example

>>> provider = get_azure_provider()
<azure.quantum.qiskit.provider.AzureQuantumProvider object at 0x000000000000>
get_azure_workspace()[source]

Retrieve the Azure Quantum Workspace instance.

Returns:

An instance of the Azure Quantum Workspace configured with the resource ID and location from the environment variables.

Return type:

Workspace

Example

>>> workspace = get_azure_workspace()
<azure.quantum.workspace.Workspace object at 0x000000000000>
get_jobs_by_id(job_id)[source]

Retrieve a specific Azure Quantum job by its ID.

Parameters:

job_id (str) – The ID of the job to retrieve.

Returns:

The Azure Quantum job object.

Example

>>> job = get_jobs_by_id('6a46ae9a-d02f-4a23-b46f-eae43471bc22')
<azure.quantum.job.job.Job object at 0x0000000000000>
test_connection(resource_id, Location)[source]

Test the connection to Azure service.

Parameters:
  • resource_id (str) – The Azure resource ID.

  • location – The Azure resource location.

  • Location (str)

Returns:

True if the connection is successful.

Return type:

bool

Example

>>> resource_id = "/subscriptions/ac1e2d6a-6adf-acad-b795-eaa8bfe45cbc/resourceGroups/MyGroup/providers/Microsoft.Quantum/Workspaces/myworkspace"
>>> test_connection(resource_id, "East US")
True

Execution

IonQ’s hardware is accessible through cirq, so see Circ’s Execution section for the functions used for IonQ’s hardware.

Connection setup

Connection setup script

The setup_connections script helps you configuring the connections for all the supported remote backends. In time, it will also guide you to retrieve the tokens, passwords, etc… but for now, it is a prerequisite that you already have these credentials to use this script.

Information concerning which provider is configured and related credentials are stored in the ~/.mpqp/.env file.

delete_config()[source]

Delete stored credentials for a selected provider.

main_setup()[source]

Main function of the script, triggering the choice selection, and guiding you through the steps needed to configure each provider access. This function has to be executed from a terminal like environment, allowing you to type tokens and alike.

print_config_info()[source]

Displays the information stored for each provider.

The details on how to get these information can be found in the section Set up remote accesses.