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:
IBM’s
get_all_job_ids()
;Eviden’s
get_all_job_ids()
;AWS’s
get_all_task_ids()
;IonQ’s
get_ionq_job_ids()
;Azure’s
get_all_job_ids()
;The Connection setup section.
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 tackle in these modules.
To see which devices are available, see Devices.
IBM
Connection
- config_ibm_account(token)[source]
Configure and save locally IBM Quantum account’s information.
- Parameters
token (str) – IBM Quantum API token.
- Raises
IBMRemoteExecutionError – If the account could not be saved.
- get_QiskitRuntimeService()[source]
Returns 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]
Returns 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]
Retrieves 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]
Retrieves 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)]
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
andsimulator
isNone
.- Return type
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 aMPQP
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 | IBMSimulatedDevice | 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
- generate_qiskit_noise_model(circuit)[source]
Generate a
qiskit
noise model packing all the class:`~mpqp.noise.noise_model.NoiseModel`s 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.
- 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’, mpqp.core.circuit.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 converted to our format.
- Return type
- 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.
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
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
- 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']
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 (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
- 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 (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
- 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
- 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
- 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
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 remoteQLM
and converts it in aMPQP
Result
. If the job is still running, we wait (blocking) until its status becomesDONE
.- Parameters
job_id (str) – Id of the remote QLM job.
- Returns
The converted result.
- Raises
QLMRemoteExecutionError – When the job cannot be found.
QLMRemoteExecutionError – When the job has a non-accessible status (cancelled, deleted, …).
- Return type
- job_pre_processing(job)[source]
Extracts the myQLM circuit and check if
job.type
andjob.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
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
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
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, ‘AsyncResult’]
Note
This function is not meant to be used directly, please use
run()
instead.
AWS
Connection
- 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]
Get AWS Braket credentials information including access key ID, obfuscated secret access key, and region.
- Returns
A formatted string containing AWS credentials information with an obfuscated secret access key.
- Return type
str
Example
>>> get_aws_braket_account_info() access_key_id: 'AKIA26NYJ***********' secret_access_key: 'sMDad***********************************' region: 'us-east-1'
- get_braket_device(device, is_noisy=False)[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.
- Raises
AWSBraketRemoteExecutionError – If the device or the region could not be retrieved.
- Return type
BraketDevice
Example
>>> device = get_braket_device(AWSDevice.RIGETTI_ANKAA_2) >>> 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)]
- setup_aws_braket_account()[source]
Setups 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. It then collects the user’s AWS access key, AWS secret key (hidden input), and the AWS region for Amazon Braket. The function attempts to configure the Amazon Braket account using the provided credentials.
- 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]]
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[mpqp.noise.noise_model.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 anAWSDevice
.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
- Returns
The
braket
result converted to our format.- Return type
- 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
- 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
Note
This function is not meant to be used directly, please use
run()
instead.
- 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 noExpectationMeasure
.NotImplementedError – If the job type is not
STATE_VECTOR
,SAMPLE
orOBSERVABLE
.
- 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, useget_ionq_job_ids()
.- Returns
A list of job IDs.
- Return type
list[str]
Execution
- extract_result_OBSERVABLE_ideal(results, job)[source]
Extracts the result from an observable-based ideal job.
The simulation from which the result to parse comes from can take in several observables, and each observable will have a corresponding value in the result. But since we only support a single measure per circuit for now, we could simplify this function by only returning the first value.
Note
for some reason, the values we retrieve from cirq are not always float, but sometimes are complex. This is likely due to numerical approximation since the complex part is always extremely small, so we just remove it, but this might result in slightly unexpected results.
- extract_result_OBSERVABLE_processors(results, job)[source]
Process measurement results for an observable from a quantum job.
- Parameters
results (Sequence[Sequence[float]]) – A sequence of measurement results, where each inner sequence represents a set of results for a particular shot.
job (Job) – The original job.
- Returns
The formatted result.
- Raises
NotImplementedError – If the job does not contain a measurement (i.e.,
job.measure
isNone
).- Return type
- extract_result_OBSERVABLE_shot_noise(results, job)[source]
Extracts the result from an observable-based job.
- extract_result_STATE_VECTOR(result, job)[source]
Extracts the result from a state vector-based job.
- 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
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
- 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
- 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
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
- 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
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.
- 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
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
file.
- 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.
The details on how to get these information can be found in the section Set up remote accesses.
On disk configuration manager
This module takes care of saving and loading the configuration of supported providers.
- config_key(key_name, configuration_name, test_connection)[source]
Configure a key by setting the API token.
- Parameters
key_name (str) – The name of the key to be saved in the environment variables.
configuration_name (str) – The name of the service for which the API token is being configured.
test_connection (Callable[[str], bool]) – A callable function taking as input token and returning a boolean indicating whether the connection setup was successful.
- 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
- get_env_variable(key)[source]
Loads the
.mpqp
env file and returns the value associated with the key in parameter. If the variable does not exist, an empty string is returned.- Parameters
key (str) – The key for which we want to get the value.
- Return type
str
Example
>>> save_env_variable("BRAKET_CONFIGURED", 'True') True >>> get_env_variable("BRAKET_CONFIGURED") 'True' >>> get_env_variable("RaNdOM") ''
- get_existing_config_str()[source]
Gets the content of the
.mpqp
config file.- Returns
The string with .mpqp file content.
- Return type
str
Example
>>> save_env_variable('QLM_USER', 'hjaffali') True >>> save_env_variable('QLM_PASSWD', '****************') True >>> save_env_variable('QLM_CONFIGURED', 'True') True >>> save_env_variable('BRAKET_CONFIGURED', 'True') True >>> print(get_existing_config_str()) QLM_USER='hjaffali' QLM_PASSWD='****************' QLM_CONFIGURED='True' BRAKET_CONFIGURED='True'
- load_env_variables()[source]
Loads the variables stored in the
.mpqp
file.- Returns
True
if the variables are loaded correctly.- Return type
bool
Example
>>> os.getenv("IBM_CONFIGURED") >>> open(os.path.expanduser("~") + "/.mpqp", "w").write("IBM_CONFIGURED='True'\n") 22 >>> os.getenv("IBM_CONFIGURED") >>> load_env_variables() True >>> os.getenv("IBM_CONFIGURED") 'True'
- save_env_variable(key, value)[source]
Adds or updates the
key
environment variable in.mpqp
file.- Parameters
key (str) – Name of the environment variable.
value (str) – Value to be saved.
- Returns
True
if the save was successful.- Return type
bool
Examples
>>> get_env_variable("RaNdOM") '' >>> save_env_variable("RaNdOM", "azertyuiop") True >>> get_env_variable("RaNdOM") 'azertyuiop'