Execution
from mpqp.execution import *
Execution is the core of this library. Our goal is to allow you to run a circuit
on any hardware without you having to rewrite your circuit in the providers’SDK.
We introduce here how execution works in MPQP
, both in local simulator and
in remote QPUs.
Languages
The execution of a circuit is always ran on a user selected device. Prior to
this execution, the circuit is first translated in the SDK we selected to
support this device. This is being done on the to_other_language
present on
most objects of MPQP
, taking a language
argument. This language
corresponds to said SDK, and you can find the list of available languages in the
Language
enum.
Warning
The current version of qiskit
we are using depends on a package with a
known vulnerability. This the risks associated to this vulnerability are not
high enough to justify immediate actions, but we will fix this as soon as
possible by bumping qiskit
’s version. You can find information about
this vulnerability here:
https://github.com/ColibrITDSAS/mpqp/security/dependabot/1.
Devices
An AvailableDevice
is a device on which one can run or submit a
circuit. While it is an abstract class, all it’s concrete implementations are
enums with a few methods, required by AvailableDevice
.
Each supported provider has its available devices listed as these enums, which you can find bellow:
Not all combinations of AvailableDevice
and
JobType
are possible. Here is the list of
compatible jobs types and devices.
Provider 
Device 
SAMPLE 
STATE_VECTOR 
OBSERVABLE 
OBSERVABLE ideal 

IBM 
AER_SIMULATOR 
✓ 
✓ 
✓ 

IBM 
AER_SIMULATOR_STATEVECTOR 
✓ 
✓ 

IBM 
IBM_BRISBANE 
✓ 
✓ 

IBM 
IBM_OSAKA 
✓ 
✓ 

IBM 
IBM_KYOTO 
✓ 
✓ 

IBM 
IBM_SHERBROOKE 
✓ 
✓ 

IBM 
IBM_KYIV 
✓ 
✓ 

IBM 
IBM_NAZCA 
✓ 
✓ 

IBM 
IBM_CUSCO 
✓ 
✓ 

IBM 
IBM_ITHACA 
✓ 
✓ 

IBM 
IBM_TORINO 
✓ 
✓ 

IBM 
IBM_QUEBEC 
✓ 
✓ 

IBM 
IBM_KAWASAKI 
✓ 
✓ 

IBM 
IBM_CLEVELAND 
✓ 
✓ 

IBM 
IBM_CAIRO 
✓ 
✓ 

IBM 
IBM_HANOI 
✓ 
✓ 

IBM 
IBM_ALGIERS 
✓ 
✓ 

IBM 
IBM_KOLKATA 
✓ 
✓ 

IBM 
IBM_MUMBAI 
✓ 
✓ 

IBM 
IBM_PEEKSKILL 
✓ 
✓ 

IBM 
IBM_RANDOM_SMALL_DEVICE 
✓ 
✓ 

IBM 
IBM_SMALL_DEVICES_LEAST_BUSY 
✓ 
✓ 

Atos 
MYQLM_PYLINALG 
✓ 
✓ 
✓ 
✓ 
Atos 
MYQLM_CLINALG 
✓ 
✓ 
✓ 
✓ 
Atos 
QLM_LINALG 
✓ 
✓ 
✓ 
✓ 
Atos 
QLM_MPS 
✓ 
✓ 
✓ 

Atos 
QLM_MPO 
✓ 
✓ 

Atos 
QLM_NOISY_QPROC 
✓ 
✓ 
✓ 

AWS 
BRAKET_LOCAL_SIMULATOR 
✓ 
✓ 
✓ 
✓ 
AWS 
BRAKET_SV1_SIMULATOR 
✓ 
✓ 
✓ 

AWS 
BRAKET_DM1_SIMULATOR 
✓ 
✓ 

AWS 
BRAKET_TN1_SIMULATOR 
✓ 
✓ 
✓ 

AWS 
BRAKET_IONQ_HARMONY 
✓ 
✓ 

AWS 
BRAKET_IONQ_ARIA_1 
✓ 
✓ 

AWS 
BRAKET_IONQ_ARIA_2 
✓ 
✓ 

AWS 
BRAKET_IONQ_FORTE_1 
✓ 
✓ 

AWS 
BRAKET_OQC_LUCY 
✓ 
✓ 

AWS 
BRAKET_QUERA_AQUILA 
✓ 
✓ 

AWS 
BRAKET_RIGETTI_ASPEN_M_3 
✓ 
✓ 

CIRQ_LOCAL_SIMULATOR 
✓ 
✓ 
✓ 
✓ 

PROCESSOR_RAINBOW 
✓ 

PROCESSOR_WEBER 
✓ 

IONQ_SIMULATOR 
✓ 

IONQ_QPU 
✓ 
 class ATOSDevice(value)[source]
Bases:
AvailableDevice
Enum regrouping all available devices provided by ATOS.
 static from_str_remote(name)[source]
Returns the first remote ATOSDevice containing the name given in parameter.
 Parameters
name (str) – A string containing the name of the device.
 Raises
ValueError – If no device corresponding to the given name could be found.
Examples
>>> ATOSDevice.from_str_remote('NoisyQProc') <ATOSDevice.QLM_NOISYQPROC: 6> >>> ATOSDevice.from_str_remote('linalg') <ATOSDevice.QLM_LINALG: 3> >>> ATOSDevice.from_str_remote('Mps') <ATOSDevice.QLM_MPS: 4>
 MYQLM_CLINALG = 2
 MYQLM_PYLINALG = 1
 QLM_LINALG = 3
 QLM_MPO = 5
 QLM_MPS = 4
 QLM_NOISYQPROC = 6
 class AWSDevice(value)[source]
Bases:
AvailableDevice
Enum regrouping all available devices provided by AWS Braket.
 static from_arn(arn)[source]
Returns the right AWSDevice from the arn given in parameter.
 Parameters
arn (str) – The AWS arn identifying the AwsDevice.
Examples
>>> AWSDevice.from_arn('arn:aws:braket:useast1::device/qpu/ionq/Harmony') <AWSDevice.BRAKET_IONQ_HARMONY: 'qpu/ionq/Harmony'> >>> AWSDevice.from_arn('arn:aws:braket:::device/quantumsimulator/amazon/sv1') <AWSDevice.BRAKET_SV1_SIMULATOR: 'quantumsimulator/amazon/sv1'>
 get_arn()[source]
Retrieve the AwsDevice arn from this AWSDevice element.
 Returns
The arn of the device.
 Return type
str
Examples
>>> AWSDevice.BRAKET_IONQ_HARMONY.get_arn() 'arn:aws:braket:useast1::device/qpu/ionq/Harmony' >>> AWSDevice.BRAKET_SV1_SIMULATOR.get_arn() 'arn:aws:braket:::device/quantumsimulator/amazon/sv1' >>> AWSDevice.BRAKET_RIGETTI_ASPEN_M_3.get_arn() 'arn:aws:braket:uswest1::device/qpu/rigetti/AspenM3'
 get_region()[source]
Retrieve the Aws region from this AWSDevice element.
 Returns
The region of the device.
 Return type
str
Examples
>>> AWSDevice.BRAKET_IONQ_HARMONY.get_region() 'useast1' >>> AWSDevice.BRAKET_SV1_SIMULATOR.get_region() == get_env_variable("AWS_DEFAULT_REGION") True >>> AWSDevice.BRAKET_RIGETTI_ASPEN_M_3.get_region() 'uswest1'
 BRAKET_DM1_SIMULATOR = 'quantumsimulator/amazon/dm1'
 BRAKET_IONQ_ARIA_1 = 'qpu/ionq/Aria1'
 BRAKET_IONQ_ARIA_2 = 'qpu/ionq/Aria2'
 BRAKET_IONQ_FORTE_1 = 'qpu/ionq/Forte1'
 BRAKET_IONQ_HARMONY = 'qpu/ionq/Harmony'
 BRAKET_LOCAL_SIMULATOR = 'LocalSimulator'
 BRAKET_OQC_LUCY = 'qpu/oqc/Lucy'
 BRAKET_QUERA_AQUILA = 'qpu/quera/Aquila'
 BRAKET_RIGETTI_ASPEN_M_3 = 'qpu/rigetti/AspenM3'
 BRAKET_SV1_SIMULATOR = 'quantumsimulator/amazon/sv1'
 BRAKET_TN1_SIMULATOR = 'quantumsimulator/amazon/tn1'
 class AvailableDevice(value)[source]
Bases:
Enum
Class used to define a generic device (quantum computer, or simulator).
 abstract is_gate_based()[source]
Indicates whether a device is gate based or not.
 Returns
True
if this device is a gatebased simulator/QPU. Return type
bool
 abstract is_noisy_simulator()[source]
Indicates whether a device can simulate noise or not.
 Returns
True
if this device can simulate noise. Return type
bool
 class GOOGLEDevice(value)[source]
Bases:
AvailableDevice
Enum regrouping all available devices provided by CIRQ.
 is_processor()[source]
Check if the device is a processor.
 Returns
True if the device is a processor, False otherwise.
 Return type
bool
 CIRQ_LOCAL_SIMULATOR = 'LocalSimulator'
 IONQ_QPU = 'qpu'
 IONQ_SIMULATOR = 'simulator'
 PROCESSOR_RAINBOW = 'rainbow'
 PROCESSOR_WEBER = 'weber'
 class IBMDevice(value)[source]
Bases:
AvailableDevice
Enum regrouping all available devices provided by IBM Quantum.
Warning
Since previous version, many devices were disabled by IBM. This may affect your code. We are currently investigating the issue to check if a workaround is possible for some of them (like replacing a simulator by an equivalent one for instance).
 AER_SIMULATOR = 'aer_simulator'
 AER_SIMULATOR_STATEVECTOR = 'aer_simulator_statevector'
 IBM_ALGIERS = 'ibm_algiers'
 IBM_BRISBANE = 'ibm_brisbane'
 IBM_CAIRO = 'ibm_cairo'
 IBM_CLEVELAND = 'ibm_cleveland'
 IBM_CUSCO = 'ibm_cusco'
 IBM_HANOI = 'ibm_hanoi'
 IBM_ITHACA = 'ibm_ithaca'
 IBM_KAWASAKI = 'ibm_kawasaki'
 IBM_KOLKATA = 'ibm_kolkata'
 IBM_KYIV = 'ibm_kyiv'
 IBM_KYOTO = 'ibm_kyoto'
 IBM_MUMBAI = 'ibm_mumbai'
 IBM_NAZCA = 'ibm_nazca'
 IBM_OSAKA = 'ibm_osaka'
 IBM_PEEKSKILL = 'ibm_peekskill'
 IBM_QUEBEC = 'ibm_quebec'
 IBM_RANDOM_SMALL_DEVICE = 'ibm_small_device'
 IBM_SHERBROOKE = 'ibm_sherbrooke'
 IBM_SMALL_DEVICES_LEAST_BUSY = 'ibm_least_busy'
 IBM_TORINO = 'ibm_torino'
Running a circuit
Once the circuit is defined, you can to execute it and retrieve the result using
the function run()
. You can execute said circuit on one or several devices
(local or remote). The function will wait (blocking) until the job is completed
and will return a Result
in only one
device was given or a BatchResult
otherwise (see below).
Alternatively, when running jobs on a remote device, you could prefer to
retrieve the result asynchronously, without having to wait and block the
application until the computation is completed. In that case, you can use the
submit()
instead. It will submit the job and
return the corresponding job id and Job
object.
Note
Unlike run()
, we can only submit on one device at a time.
 adjust_measure(measure, circuit)[source]
We allow the measure to not span the entire circuit, but providers usually don’t support this behavior. To make this work we tweak the measure this function to match the expected behavior.
In order to do this, we add identity measures on the qubits not targeted by the measure. In addition of this, some swaps are automatically added so the the qubits measured are ordered and contiguous (though this is done in
generate_job()
) Parameters
measure (ExpectationMeasure) – The expectation measure, potentially incomplete.
circuit (QCircuit) – The circuit to which will be added the potential swaps allowing the user to get the expectation value of the qubits in an arbitrary order (this part is not handled by this function).
 Returns
The measure padded with the identities before and after.
 generate_job(circuit, device, values={})[source]
Creates the Job of appropriate type and containing the information needed for the execution of the circuit.
If the circuit contains symbolic variables (see section Variational Quantum Algorithms for more information on them), the
values
parameter is used perform the necessary substitutions. Parameters
circuit (QCircuit) – Circuit to be run.
device (AvailableDevice) – Device on which the circuit will be run.
values (dict[sympy.core.expr.Expr  str, numbers.Complex]) – Set of values to substitute symbolic variables.
 Returns
The Job containing information about the execution of the circuit.
 Return type
 run(circuit, device, values=None)[source]
Runs the circuit on the backend, or list of backend, provided in parameter.
If the circuit contains symbolic variables (see section Variational Quantum Algorithms for more information on them), the
values
parameter is used perform the necessary substitutions. Parameters
circuit (Union[QCircuit, Sequence[QCircuit]]) – QCircuit to be run.
device (Union[AvailableDevice, Sequence[AvailableDevice]]) – Device, or list of devices, on which the circuit will be run.
values (Optional[dict[sympy.core.expr.Expr  str, numbers.Complex]]) – Set of values to substitute symbolic variables. Defaults to
{}
.
 Returns
The Result containing information about the measurement required.
 Return type
Union[Result, BatchResult]
Examples
>>> c = QCircuit( ... [X(0), CNOT(0, 1), BasisMeasure([0, 1], shots=1000)], ... label="X CNOT circuit", ... ) >>> result = run(c, IBMDevice.AER_SIMULATOR) >>> print(result) Result: X CNOT circuit, IBMDevice, AER_SIMULATOR Counts: [0, 0, 0, 1000] Probabilities: [0, 0, 0, 1] Samples: State: 11, Index: 3, Count: 1000, Probability: 1.0 Error: None >>> batch_result = run( ... c, ... [ATOSDevice.MYQLM_PYLINALG, AWSDevice.BRAKET_LOCAL_SIMULATOR] ... ) >>> print(batch_result) BatchResult: 2 results Result: X CNOT circuit, ATOSDevice, MYQLM_PYLINALG Counts: [0, 0, 0, 1000] Probabilities: [0, 0, 0, 1] Samples: State: 11, Index: 3, Count: 1000, Probability: 1.0 Error: 0.0 Result: X CNOT circuit, AWSDevice, BRAKET_LOCAL_SIMULATOR Counts: [0, 0, 0, 1000] Probabilities: [0, 0, 0, 1] Samples: State: 11, Index: 3, Count: 1000, Probability: 1.0 Error: None >>> c2 = QCircuit( ... [X(0), X(1), BasisMeasure([0, 1], shots=1000)], ... label="X circuit", ... ) >>> result = run([c,c2], IBMDevice.AER_SIMULATOR) >>> print(result) BatchResult: 2 results Result: X CNOT circuit, IBMDevice, AER_SIMULATOR Counts: [0, 0, 0, 1000] Probabilities: [0, 0, 0, 1] Samples: State: 11, Index: 3, Count: 1000, Probability: 1.0 Error: None Result: X circuit, IBMDevice, AER_SIMULATOR Counts: [0, 0, 0, 1000] Probabilities: [0, 0, 0, 1] Samples: State: 11, Index: 3, Count: 1000, Probability: 1.0 Error: None
 submit(circuit, device, values={})[source]
Submit the job related with the circuit on the remote backend provided in parameter. The submission returns a
job_id
that can be used to retrieve theResult
later, using theget_remote_result
function.If the circuit contains symbolic variables (see section Variational Quantum Algorithms for more information on them), the
values
parameter is used perform the necessary substitutions.Mind that this function only support single device submissions.
 Parameters
circuit (QCircuit) – QCircuit to be run.
device (AvailableDevice) – Remote device on which the circuit will be submitted.
values (dict[sympy.core.expr.Expr  str, numbers.Complex]) – Set of values to substitute symbolic variables.
 Returns
The job id provided by the remote device after submission of the job.
 Return type
tuple[str, mpqp.execution.job.Job]
Example
>>> circuit = QCircuit([H(0), CNOT(0,1), BasisMeasure([0,1], shots=10)]) >>> job_id, job = submit(circuit, ATOSDevice.QLM_LINALG) Logging as user <qlm_user>... Submitted a new batch: Job766 >>> print("Status of " +job_id +":", job.job_status) Status of Job766: JobStatus.RUNNING
Helpers for remote jobs
After the jobs are submitted, one can use the functions of this module to retrieve the results from a job_id or the job directly, and list all job attached to the configured accounts.
 get_all_job_ids()[source]
Retrieve from the remote providers all the jobids associated with this account.
 Returns
A dictionary of jobids indexed by the correspond AvailableDevice (ATOSDevice, AWSDevice, IBMDevice, …).
 Return type
dict[type[AvailableDevice], list[str]]
 get_remote_result(job_data, device=None)[source]
Retrieve and parse a remote the result from a job_id and device. If the job is still running, it will wait until it is done.
 Parameters
job_data (str  mpqp.execution.job.Job) – Either the
Job
object or the job id used to identify the job on the remote device.device (Optional[AvailableDevice]) – Remote device on which the job was launched, needed only if
job_data
is the identifier of the job.
 Returns
The
Result
of the desired remote job. Return type
Examples
>>> print(get_remote_result('Job141933', ATOSDevice.QLM_LINALG)) Result: ATOSDevice, QLM_LINALG Counts: [1017, 0, 0, 0, 983, 0, 0, 0] Probabilities: [0.5085 0. 0. 0. 0.4915 0. 0. 0. ] State: 000, Index: 0, Count: 1017, Probability: 0.5085 State: 100, Index: 4, Count: 983, Probability: 0.4915 Error: 0.011181519941139355 >>> print(get_remote_result( ... 'cm80pb1054sir2ck9i3g', ... IBMDevice.IBMQ_QASM_SIMULATOR, ... )) Result: IBMDevice, IBMQ_QASM_SIMULATOR Expectation value: 1.6410799999999999 Error/Variance: 1.24570724535 >>> aws_task_id = ( ... 'arn:aws:braket:useast1:752542621531:quantumtask/' ... '6a46ae9ad02f4a23b46feae43471bc22' ... ) >>> print(get_remote_result( ... aws_task_id, ... AWSDevice.BRAKET_SV1_SIMULATOR, ... )) Result: AWSDevice, BRAKET_SV1_SIMULATOR Expectation value: 1.6635202030411578 Error/Variance: None
>>> circ = QCircuit([H(0), CNOT(0,1)]) >>> _, job = submit(circ, ATOSDevice.QLM_LINALG) >>> print(get_remote_result(job)) Result: ATOSDevice, QLM_LINALG State vector: [0.7071068, 0, 0, 0.7071068] Probabilities: [0.5, 0, 0, 0.5] Number of qubits: 2
Jobs
When you call run
or
submit
, a Job
is created by
generate_job
. This job contains all
the needed information to configure the execution, and eventually retrieve
remote results.
A Job
can be of three types, given by the JobType
enum. In
addition, it has a status, given by the JobStatus
enum.
As described above, a Job
is generated on circuit submission so you
would in principle never need to instantiate one yourself.
 class Job(job_type, circuit, device, measure=None)[source]
Bases:
object
Representation of a job, an object regrouping all the information about the submission of a computation/measure of a quantum circuit on a specific hardware.
A job has a type, and a status, and is attached to a specific device. Moreover, the job contains also the quantum circuit and the measure to be performed on the circuit.
 Parameters
job_type (JobType) – Type of the job (sample, observable, …).
circuit (QCircuit) – Circuit to execute.
device (AvailableDevice) – Device (simulator, quantum computer) on which we want to execute the job.
measure (Optional[Measure]) – Object representing the measure to perform.
Examples
>>> circuit = QCircuit(3) >>> job = Job(JobType.STATE_VECTOR, circuit, IBMDevice.AER_SIMULATOR)
>>> circuit.add(BasisMeasure([0, 1], shots=1000)) >>> job2 = Job( ... JobType.STATE_VECTOR, ... circuit, ... IBMDevice.AER_SIMULATOR, ... circuit.get_measurements()[0], ... )
 circuit
See parameter description.
 device
See parameter description.
 id: Optional[str]
Contains the id of the remote job, used to retrieve the result from the remote provider.
None
if the job is local. If the job is not local, it will be set later on.
 job_type
See parameter description.
 measure
See parameter description.
 property status
Update and return the current job status. Mainly relevant for remote jobs.
 class JobStatus(value=<no_arg>, names=None, module=None, qualname=None, type=None, start=1, boundary=None)[source]
Bases:
MessageEnum
Possible states of a Job.
 CANCELLED = 4
The job is cancelled.
 DONE = 6
The job is successfully done.
 ERROR = 5
An error occurred with the job.
 INIT = 1
Initializing the job.
 QUEUED = 2
The job is in the queue.
 RUNNING = 3
The job is currently running.
 class JobType(value=<no_arg>, names=None, module=None, qualname=None, type=None, start=1, boundary=None)[source]
Bases:
Enum
Possible types of Job to execute.
Each type of job is restricted to some measures (and to some backends, but this is tackled by the backends themselves).
 OBSERVABLE = {ExpectationMeasure}
Computes the expectation value of an observable, using the state_vector or the samples. This type is ideal too: it requires some trickery to retrieve the expectation value in an optimal manner.
 SAMPLE = {BasisMeasure}
Measures several times the quantum state in the basis, and retrieve the counts. Contrarily to the
STATE_VECTOR
job type, this one is realistic.
 STATE_VECTOR = {BasisMeasure, <class 'NoneType'>}
Retrieves the vector representing the quantum state, this type is ideal.
 get_aws_job_status(job_id)[source]
Retrieves the status of a AWS Braket from the id in parameter, and returns the corresponding JobStatus of this library.
 Parameters
job_id (str) – Id of the job for which we want to retrieve the status.
 Return type
Results
Once the computation ended, the Result
contains all the data from
the execution.
The job type affects the data contained in the Result
. For a given
result
, here are how to retrieve the data depending on the job type:
for a job type
STATE_VECTOR
you can retrieve theStateVector
fromresult.state_vector
. If you want to directly get the amplitudes of your state vector, you can reach forresult.amplitudes
;for a job type
SAMPLE
you can retrieve the list ofSample
fromresult.samples
. For aSAMPLE
job type, you might be interested in results packed in a different shape than a list ofSample
, even though you could rebuild them from said list, we also provide a few shorthands likeresult.probabilities
andresult.counts
;for a job type
OBSERVABLE
you can retrieve the expectation value (afloat
) fromresult.expectation_value
.
When several devices are given to run
, the
results are stored in a BatchResult
.
 class BatchResult(results)[source]
Bases:
object
Class used to handle several Result instances.
 Parameters
results (list[Result]) – List of results.
Example
>>> result1 = Result( ... Job(JobType.STATE_VECTOR,QCircuit(0),ATOSDevice.MYQLM_PYLINALG), ... StateVector(np.array([1, 1, 1, 1])/2, 2), ... 0, ... 0 ... ) >>> result2 = Result( ... Job( ... JobType.SAMPLE, ... QCircuit(0), ... ATOSDevice.MYQLM_PYLINALG, ... BasisMeasure([0,1],shots=500) ... ), ... [Sample(2, index=0, count=250), Sample(2, index=3, count=250)], ... 0.034, ... 500) >>> result3 = Result( ... Job(JobType.OBSERVABLE,QCircuit(0),ATOSDevice.MYQLM_PYLINALG), ... 3.09834, ... 0.021, ... 2048 ... ) >>> batch_result = BatchResult([result1, result2, result3]) >>> print(batch_result) BatchResult: 3 results Result: None, ATOSDevice, MYQLM_PYLINALG State vector: [0.5, 0.5, 0.5, 0.5] Probabilities: [0.25, 0.25, 0.25, 0.25] Number of qubits: 2 Result: None, ATOSDevice, MYQLM_PYLINALG Counts: [250, 0, 0, 250] Probabilities: [0.5, 0, 0, 0.5] Samples: State: 00, Index: 0, Count: 250, Probability: 0.5 State: 11, Index: 3, Count: 250, Probability: 0.5 Error: 0.034 Result: None, ATOSDevice, MYQLM_PYLINALG Expectation value: 3.09834 Error/Variance: 0.021 >>> print(batch_result[0]) Result: None, ATOSDevice, MYQLM_PYLINALG State vector: [0.5, 0.5, 0.5, 0.5] Probabilities: [0.25, 0.25, 0.25, 0.25] Number of qubits: 2
 plot(show=True)[source]
Display the result(s) using
matplotlib.pyplot
.The result(s) must be from a job who’s
job_type
isSAMPLE
. They will be displayed as histograms.If a
BatchResult
is given, the contained results will be displayed in a grid using subplots. Parameters
show (bool) –
plt.show()
is only executed ifshow
, useful to batch plots.
 results
See parameter description.
 class Result(job, data, error=None, shots=0)[source]
Bases:
object
Result associated to a submitted job.
The data type in a result depends on the job type, according to the following chart:
Job Type
Data Type
OBSERVABLE
float
SAMPLE
list[Sample]
STATE_VECTOR
StateVector
 Parameters
job (Job) – Type of the job related to this result.
data (float  StateVector  list[Sample]) – Data of the result, can be an expectation value (float), a StateVector, or a list of sample depending on the job_type.
error (Optional[float]) – Information about the error or the variance in the measurement.
shots (int) – Number of shots of the experiment (equal to zero if the exact value was required).
Examples
>>> job = Job(JobType.STATE_VECTOR, QCircuit(2), ATOSDevice.MYQLM_CLINALG) >>> print(Result(job, StateVector(np.array([1, 1, 1, 1], dtype=np.complex64) / 2, 2), 0, 0)) Result: None, ATOSDevice, MYQLM_CLINALG State vector: [0.5, 0.5, 0.5, 0.5] Probabilities: [0.25, 0.25, 0.25, 0.25] Number of qubits: 2 >>> job = Job(JobType.SAMPLE, QCircuit(2), ATOSDevice.MYQLM_CLINALG, BasisMeasure([0, 1], shots=1000)) >>> print(Result(job, [ ... Sample(2, index=0, count=250), ... Sample(2, index=3, count=250) ... ], 0.034, 500)) Result: None, ATOSDevice, MYQLM_CLINALG Counts: [250, 0, 0, 250] Probabilities: [0.5, 0, 0, 0.5] Samples: State: 00, Index: 0, Count: 250, Probability: 0.5 State: 11, Index: 3, Count: 250, Probability: 0.5 Error: 0.034 >>> job = Job(JobType.OBSERVABLE, QCircuit(2), ATOSDevice.MYQLM_CLINALG) >>> print(Result(job, 3.09834, 0.021, 2048)) Result: None, ATOSDevice, MYQLM_CLINALG Expectation value: 3.09834 Error/Variance: 0.021
 plot(show=True)[source]
Extract sampling info from the result and construct the bar diagram plot.
 Parameters
show (bool) –
plt.show()
is only executed ifshow
, useful to batch plots.
 property amplitudes: ndarray[Any, dtype[complex64]]
Get the amplitudes of the state of this result
 property counts: list[int]
Get the list of counts for each sample of the experiment
 property device: AvailableDevice
Device on which the job of this result was run
 error
See parameter description.
 property expectation_value: float
Get the expectation value stored in this result
 job
See parameter description.
 property probabilities: ndarray[Any, dtype[float32]]
Get the list of probabilities associated with this result
 property samples: list[mpqp.execution.result.Sample]
Get the list of samples of the result
 shots
See parameter description.
 property state_vector: StateVector
Get the state vector of the state associated with this result
 class Sample(nb_qubits, probability=None, index=None, count=None, bin_str=None)[source]
Bases:
object
A sample is a partial result of job job with type
SAMPLE
. It contains the count (and potentially the associated probability) for a given basis state, i.e. the number of times this basis state was measured. Parameters
nb_qubits (int) – Number of qubits of the quantum system of the experiment.
probability (Optional[float]) – Probability of measuring the basis state associated to this sample.
index (Optional[int]) – Index in decimal notation representing the basis state.
count (Optional[int]) – Number of times this basis state was measured during the experiment.
bin_str (Optional[str]) – String representing the basis state in binary notation.
Examples
>>> print(Sample(3, index=3, count=250, bin_str="011")) State: 011, Index: 3, Count: 250, Probability: None
>>> print(Sample(4, index=6, probability=0.5)) State: 0110, Index: 6, Count: None, Probability: 0.5
>>> print(Sample(5, bin_str="01011", count=1234)) State: 01011, Index: 11, Count: 1234, Probability: None
 bin_str: str
See parameter description.
 count
See parameter description.
 index: int
See parameter description.
 nb_qubits
See parameter description.
 probability
See parameter description.
 class StateVector(vector, nb_qubits=None, probabilities=None)[source]
Bases:
object
Class representing the state vector of a multiqubit quantum system.
 Parameters
vector (list[Complex]  npt.NDArray[np.complex64]) – List of amplitudes defining the state vector.
nb_qubits (Optional[int]) – Number of qubits of the state.
probabilities (Optional[list[float]  npt.NDArray[np.float32]]) – List of probabilities associated with the state vector.
Example
>>> state_vector = StateVector(np.array([1, 1, 1, 1])/2, 2) >>> state_vector.probabilities array([0.25, 0.25, 0.25, 0.25]) >>> print(state_vector) State vector: [0.5, 0.5, 0.5, 0.5] Probabilities: [0.25, 0.25, 0.25, 0.25] Number of qubits: 2
 property amplitudes
Return the amplitudes of the state vector
 nb_qubits
See parameter description.
 probabilities
See parameter description.