Skip to content

Commit 8f874e9

Browse files
big refactor + documentation improvements + types refinements
1 parent d35057b commit 8f874e9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+447
-358
lines changed

docs/execution-extras.rst

+3-3
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ __________
3131
Execution
3232
__________
3333

34-
.. automodule:: mpqp.execution.providers_execution.ibm_execution
34+
.. automodule:: mpqp.execution.providers.ibm
3535

3636
Atos/Eviden
3737
^^^^^^^^^^^
@@ -44,12 +44,12 @@ __________
4444
Execution
4545
__________
4646

47-
.. automodule:: mpqp.execution.providers_execution.atos_execution
47+
.. automodule:: mpqp.execution.providers.atos
4848

4949
AWS
5050
^^^
5151

52-
.. automodule:: mpqp.execution.providers_execution.aws_execution
52+
.. automodule:: mpqp.execution.providers.aws
5353

5454
Connection
5555
__________
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

mpqp/all.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# pyright: reportUnusedImport=false
22
import numpy as np
33

4-
from mpqp.execution.providers_execution.atos_execution import get_result_from_qlm_job_id
4+
from mpqp.execution.providers.atos import get_result_from_qlm_job_id
55

66
from . import Barrier, Instruction, Language, QCircuit
77
from .execution import (

mpqp/core/circuit.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -412,8 +412,7 @@ def optimize(self, criteria: Optional[str | list[str]] = None) -> QCircuit:
412412
...
413413

414414
def to_matrix(self) -> npt.NDArray[np.complex64]:
415-
"""
416-
Compute the unitary matrix associated to this circuit.
415+
"""Compute the unitary matrix associated to this circuit.
417416
418417
Examples:
419418
>>> c = QCircuit([H(0), CNOT(0,1)])
@@ -670,6 +669,7 @@ def to_other_language(
670669
qargs = range(instruction.size)
671670
else:
672671
raise ValueError(f"Instruction not handled: {instruction}")
672+
assert not isinstance(qiskit_inst, Operator)
673673

674674
new_circ.append(
675675
qiskit_inst,

mpqp/core/instruction/gates/native_gates.py

+7-4
Original file line numberDiff line numberDiff line change
@@ -47,19 +47,23 @@
4747

4848

4949
@typechecked
50-
def _qiskit_parameter_adder(param: Expr | float, qiskit_parameters: set[Parameter]):
50+
def _qiskit_parameter_adder(
51+
param: Expr | float, qiskit_parameters: set[Parameter]
52+
) -> Parameter | float | int:
5153
"""To avoid having several parameters in qiskit for the same value we keep
5254
track of them in a set. This function takes care of this, this way you can
5355
directly call `QiskitGate(_qiskit_parameter_adder(<param>, <q_params_set>))`
5456
without having to manually take care of the de-duping.
5557
58+
This process is a form of memoization.
59+
5660
Args:
5761
param: The parameter you need for your qiskit gate.
5862
qiskit_parameters: The set of previously set qiskit parameters. This set
5963
is updated inplace.
6064
6165
Returns:
62-
66+
The memoized parameter
6367
"""
6468
if isinstance(param, Expr):
6569
name = str(param)
@@ -520,8 +524,7 @@ def __repr__(self):
520524

521525

522526
class CNOT(InvolutionGate, NoParameterGate, ControlledGate):
523-
"""
524-
Two-qubit Controlled-NOT gate.
527+
"""Two-qubit Controlled-NOT gate.
525528
526529
Args:
527530
control: index referring to the qubit used to control the gate

mpqp/core/instruction/gates/parametrized_gate.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010

1111
from abc import ABC
1212
from copy import deepcopy
13-
from typing import Optional
1413
from numbers import Complex
14+
from typing import Optional
1515

1616
from sympy import Expr, symbols # pyright: ignore [reportUnusedImport]
1717
from typeguard import typechecked
@@ -29,11 +29,11 @@
2929

3030
@typechecked
3131
class ParametrizedGate(Gate, ABC):
32-
"""
33-
Define a parametrized gate.
32+
"""Define a parametrized gate.
3433
3534
Args:
36-
definition: Provide a definition of the gate (matrix, gate combination, ...).
35+
definition: Provide a definition of the gate (matrix, gate combination,
36+
...).
3737
targets: List of indices referring to the qubits on which the gate will
3838
be applied.
3939
parameters: List of parameters used to define the gate.

mpqp/core/instruction/measurement/basis.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
:class:`ComputationalBasis` and :class:`HadamardBasis`."""
1010

1111
from __future__ import annotations
12+
1213
from abc import abstractmethod
1314
from functools import reduce
1415
from typing import Optional
@@ -17,7 +18,7 @@
1718
import numpy.typing as npt
1819
from typeguard import typechecked
1920

20-
from mpqp.tools.maths import matrix_eq, atol
21+
from mpqp.tools.maths import atol, matrix_eq
2122

2223

2324
@typechecked
@@ -107,8 +108,7 @@ def __init__(self, nb_qubits: Optional[int] = None):
107108

108109
@abstractmethod
109110
def set_size(self, nb_qubits: int):
110-
"""
111-
To allow the user to use a basis without having to specify the size
111+
"""To allow the user to use a basis without having to specify the size
112112
(because implicitly the size should be the number of qubits of the
113113
circuit), we use this method, that will only be called once the
114114
circuit's size is definitive (i.e. at the last moment before the circuit

mpqp/core/noise/noise_methods.py

+32-29
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
11
from __future__ import annotations
2-
from typing import Optional
32

4-
from mpqp.core.instruction.gates import (
5-
KrausRepresentation,
6-
PauliDecomposition,
7-
)
8-
from mpqp.core.languages import Language
3+
from typing import Optional
94

105
import numpy as np
116
import numpy.typing as npt
@@ -14,15 +9,17 @@
149
# from qat.lang.AQASM import Program, H, PH, CNOT, SWAP, RX
1510
from qat.quops.quantum_channels import QuantumChannelKraus
1611

17-
# QISKIT
18-
1912
# Import from Qiskit Aer noise module
2013
from qiskit_aer.noise import depolarizing_error
2114

15+
from mpqp.core.instruction.gates import KrausRepresentation, PauliDecomposition
16+
from mpqp.core.languages import Language
17+
18+
# QISKIT
19+
2220

2321
class GateNoise:
24-
"""
25-
A class used to apply Noise on a specific Gate
22+
"""A class used to apply Noise on a specific Gate.
2623
2724
Noise can be defined in several ways, and this class allows us apply a
2825
specific qubit quantum error to a selected gate
@@ -42,6 +39,7 @@ class GateNoise:
4239
4340
#This will go in the MPQPNoiseModel class
4441
hw_model = HardwareModel(gates_spec, gates_noise, idle_noise=None)
42+
# 3M-TODO : implement and comment
4543
4644
"""
4745

@@ -53,23 +51,25 @@ def __init__(
5351

5452

5553
class GateNoiseCombination:
56-
"""
57-
A class that allows to combine different types of Noise on a selected Gate(s)
58-
by using composition, tensor product, and tensor expansion and thus produces a
59-
new quantum error.
54+
"""A class that allows to combine different types of Noise on a selected
55+
Gate(s) by using composition, tensor product, and tensor expansion and thus
56+
produces a new quantum error.
6057
6158
6259
Args:?
63-
matrix : unitary matrix representing the gate
64-
gate_combination : combination of gates (sum, product, ...) defining the gate
65-
kraus_operators : generalized Kraus representation of the gate
66-
pauli_decomposition : when it is possible, decomposition of the gate in the Pauli basis (I, X, Y, Z)
67-
nb_qubits : number of qubits of the gate defined
60+
matrix: Unitary matrix representing the gate.
61+
gate_combination: Combination of gates (sum, product, ...) defining the
62+
gate.
63+
kraus_operators : Generalized Kraus representation of the gate.
64+
pauli_decomposition: When it is possible, decomposition of the gate in
65+
the Pauli basis (I, X, Y, Z).
66+
nb_qubits: Number of qubits of the gate defined.
6867
6968
more has to be added here, once it is thought through
7069
7170
Attributes:
72-
_current_type (str): string describing which definition is currently used to define the gate
71+
_current_type (str): string describing which definition is currently
72+
used to define the gate
7373
7474
7575
"""
@@ -80,21 +80,23 @@ def __init__(self):
8080

8181

8282
class NoiseModules:
83-
"""
84-
A class that contains function and methods for noise modeling.
83+
"""A class that contains function and methods for noise modeling.
8584
8685
8786
Args:
88-
matrix : unitary matrix representing the gate
89-
gate_combination : combination of gates (sum, product, ...) defining the gate
90-
kraus_operators : generalized Kraus representation of the gate
91-
pauli_decomposition : when it is possible, decomposition of the gate in the Pauli basis (I, X, Y, Z)
92-
nb_qubits : number of qubits of the gate defined
87+
matrix: Unitary matrix representing the gate.
88+
gate_combination: Combination of gates (sum, product, ...) defining the
89+
gate.
90+
kraus_operators: Generalized Kraus representation of the gate.
91+
pauli_decomposition: When it is possible, decomposition of the gate in
92+
the Pauli basis (I, X, Y, Z)?
93+
nb_qubits: Number of qubits of the gate defined.
9394
9495
more has to be added here, once it is thought through
9596
9697
Attributes:
97-
_current_type (str): string describing which definition is currently used to define the gate
98+
_current_type (str): String describing which definition is currently
99+
used to define the gate.
98100
99101
100102
"""
@@ -107,7 +109,8 @@ def __init__(self, nb_qubits: int, param: float, language: str):
107109
def depolarizing_error(
108110
self, param: float, num_qubits: int, language: Language = Language.QISKIT
109111
):
110-
"""
112+
"""Depol error.
113+
111114
Args:
112115
param: depolarizing error parameter.
113116
num_qubits: the number of qubits for the error channel.

mpqp/execution/connection/aws_connection.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,7 @@ def get_aws_braket_account_info() -> str:
9292

9393
@typechecked
9494
def get_braket_device(device: AWSDevice) -> BraketDevice:
95-
"""
96-
Returns the AwsDevice device associate with the AWSDevice in parameter.
95+
"""Returns the AwsDevice device associate with the AWSDevice in parameter.
9796
9897
Example:
9998
>>> device = get_braket_device(AWSDevice.BRAKET_RIGETTI_ASPEN_M_3)
@@ -107,7 +106,8 @@ def get_braket_device(device: AWSDevice) -> BraketDevice:
107106
device: AWSDevice element describing which remote/local AwsDevice we want.
108107
109108
Raises:
110-
AWSBraketRemoteExecutionError
109+
AWSBraketRemoteExecutionError: If the device or the region could not be
110+
retrieved.
111111
"""
112112

113113
if not device.is_remote():

mpqp/execution/connection/ibm_connection.py

+14-15
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@
1919

2020
@typechecked
2121
def config_ibm_account(token: str):
22-
"""
23-
Configure and save locally IBM Quantum account's information.
22+
"""Configure and save locally IBM Quantum account's information.
2423
2524
Args:
2625
token: IBM Quantum API token.
@@ -128,8 +127,8 @@ def get_IBMProvider() -> IBMProvider:
128127

129128

130129
def get_QiskitRuntimeService() -> QiskitRuntimeService:
131-
"""
132-
Returns the QiskitRuntimeService needed for remote connection and execution
130+
"""Returns the QiskitRuntimeService needed for remote connection and
131+
execution.
133132
134133
Example:
135134
>>> service = get_QiskitRuntimeService()
@@ -141,7 +140,8 @@ def get_QiskitRuntimeService() -> QiskitRuntimeService:
141140
<RuntimeJob('cm7vds4pduldih1k1mq0', 'sampler')>]
142141
143142
Raises:
144-
IBMRemoteExecutionError
143+
IBMRemoteExecutionError: When the ``qiskit`` runtime is not configured
144+
or the configuration cannot be retrieved.
145145
"""
146146
global Runtime_Service
147147
if Runtime_Service is None:
@@ -160,8 +160,7 @@ def get_QiskitRuntimeService() -> QiskitRuntimeService:
160160

161161

162162
def get_active_account_info() -> str:
163-
"""
164-
Returns the information concerning the active IBMQ account
163+
"""Returns the information concerning the active IBMQ account.
165164
166165
Example:
167166
>>> print(get_active_account_info())
@@ -172,7 +171,7 @@ def get_active_account_info() -> str:
172171
Verify: True
173172
174173
Returns:
175-
A string describing the account info.
174+
The description containing the account information.
176175
"""
177176
provider = get_IBMProvider()
178177
account = provider.active_account()
@@ -186,8 +185,8 @@ def get_active_account_info() -> str:
186185

187186
@typechecked
188187
def get_backend(device: IBMDevice) -> BackendV1:
189-
"""
190-
Retrieves the IBM Q remote device corresponding to the device in parameter
188+
"""Retrieves the IBM Q remote device corresponding to the device in
189+
parameter.
191190
192191
Args:
193192
device: The IBMDevice to get from IBMQ provider.
@@ -199,10 +198,11 @@ def get_backend(device: IBMDevice) -> BackendV1:
199198
Nduv(datetime.datetime(2024, 1, 9, 15, 41, 39, tzinfo=tzlocal()), gate_length, ns, 60)]
200199
201200
Returns:
202-
A qiskit.providers.backend.Backend object that will be use to execute circuit.
201+
The requested backend.
203202
204203
Raises:
205-
IBMRemoteExecutionError
204+
ValueError: If the required backend is a local simulator.
205+
IBMRemoteExecutionError: If the device was not found.
206206
"""
207207
# NOTE:
208208
# Question : when a backend is present in several IBMQ instances, which instance does it use to submit jobs
@@ -228,9 +228,8 @@ def get_backend(device: IBMDevice) -> BackendV1:
228228

229229

230230
def get_all_job_ids() -> list[str]:
231-
"""
232-
Retrieves all the job ids of this account from the several IBM remote providers
233-
(IBMProvider, QiskitRuntimeService, ...)
231+
"""Retrieves all the job ids of this account from the several IBM remote
232+
providers (IBMProvider, QiskitRuntimeService, ...).
234233
235234
Example:
236235
>>> get_all_job_ids()

mpqp/execution/connection/setup_connections.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@
99

1010

1111
def print_config_info():
12-
"""
13-
Prints the info concerning each provider's registered account
14-
"""
12+
"""Prints the info concerning each provider's registered account."""
1513
print("===== IBM Quantum info : ===== ")
1614
try:
1715
print(ibmqc.get_active_account_info())

0 commit comments

Comments
 (0)