Skip to content

Commit 1888b3c

Browse files
Merge branch 'dev' of https://github.com/ColibrITD-SAS/mpqp into dev
2 parents 6d63cf6 + 2219de6 commit 1888b3c

File tree

7 files changed

+49
-53
lines changed

7 files changed

+49
-53
lines changed

examples/notebooks/3_Expectation_value_of_observables.ipynb

+26-36
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,6 @@
2020
"id": "a3c9a6e8",
2121
"metadata": {},
2222
"outputs": [
23-
{
24-
"name": "stderr",
25-
"output_type": "stream",
26-
"text": [
27-
"<frozen importlib._bootstrap>:228: RuntimeWarning: scipy._lib.messagestream.MessageStream size changed, may indicate binary incompatibility. Expected 56 from C header, got 64 from PyObject\n"
28-
]
29-
},
3023
{
3124
"name": "stdout",
3225
"output_type": "stream",
@@ -167,11 +160,11 @@
167160
"text": [
168161
"BatchResult: 2 results\n",
169162
"Result: ATOSDevice, MYQLM_PYLINALG\n",
170-
" Expectation value: -3.4769999999999994\n",
171-
" Error/Variance: 0.10704925979198084\n",
163+
" Expectation value: -3.6279999999999997\n",
164+
" Error/Variance: 0.10472127540648739\n",
172165
"Result: IBMDevice, AER_SIMULATOR\n",
173-
" Expectation value: -3.6155\n",
174-
" Error/Variance: 22.003217250000002\n"
166+
" Expectation value: -3.2729999999999992\n",
167+
" Error/Variance: 22.060085000000004\n"
175168
]
176169
}
177170
],
@@ -192,7 +185,7 @@
192185
},
193186
{
194187
"cell_type": "code",
195-
"execution_count": 11,
188+
"execution_count": 9,
196189
"id": "4ac9c7e0",
197190
"metadata": {},
198191
"outputs": [],
@@ -256,7 +249,7 @@
256249
},
257250
{
258251
"cell_type": "code",
259-
"execution_count": 15,
252+
"execution_count": 10,
260253
"id": "bc5ed517",
261254
"metadata": {},
262255
"outputs": [
@@ -290,7 +283,7 @@
290283
},
291284
{
292285
"cell_type": "code",
293-
"execution_count": 16,
286+
"execution_count": 11,
294287
"id": "06784ef3",
295288
"metadata": {},
296289
"outputs": [
@@ -299,7 +292,7 @@
299292
"output_type": "stream",
300293
"text": [
301294
"ps_2 = 1*I@Z + 2.555555555*Y@I + 1*X@Z + -1*X@Z\n",
302-
" = 1*I@Z + 2.555555555*Y@I\n",
295+
" = 2.555555555*Y@I + 1*I@Z\n",
303296
" ~= 1*I@Z + 2.6*Y@I + 1*X@Z + -1*X@Z\n",
304297
" ~= 1*I@Z + 2.5556*Y@I\n"
305298
]
@@ -325,7 +318,7 @@
325318
},
326319
{
327320
"cell_type": "code",
328-
"execution_count": 17,
321+
"execution_count": 12,
329322
"id": "b9cadb08",
330323
"metadata": {},
331324
"outputs": [
@@ -347,7 +340,6 @@
347340
"\n",
348341
"Tensor product:\n",
349342
"(1*I@Z + -3*X@Y) @ Z = 1*I@Z@Z + -3*X@Y@Z\n",
350-
"\n",
351343
"(1*I@Z + -3*X@Y) @ (1*I@Z + 2.6*Y@I) = 1*I@Z@I@Z + -3*I@Z@X@Y + 2.6*Y@I@I@Z + -7.8*Y@I@X@Y\n"
352344
]
353345
}
@@ -368,7 +360,6 @@
368360
"\n",
369361
"Tensor product:\n",
370362
"({ps_1}) @ Z = {ps_1@Z}\n",
371-
"\n",
372363
"({ps_1}) @ ({ps_2}) = {ps_1@ps_2}\"\"\")"
373364
]
374365
},
@@ -382,7 +373,7 @@
382373
},
383374
{
384375
"cell_type": "code",
385-
"execution_count": null,
376+
"execution_count": 13,
386377
"id": "5b0537a1",
387378
"metadata": {},
388379
"outputs": [],
@@ -402,7 +393,7 @@
402393
},
403394
{
404395
"cell_type": "code",
405-
"execution_count": null,
396+
"execution_count": 14,
406397
"id": "1732e099",
407398
"metadata": {},
408399
"outputs": [
@@ -422,12 +413,12 @@
422413
"\n",
423414
"`obs1` created with Pauli string:\n",
424415
"Pauli string:\n",
425-
"1*I@X + -3*X@Y\n",
416+
"1*I@Z + -3*X@Y\n",
426417
"matrix:\n",
427-
"[[0.+0.j 1.+0.j 0.+0.j 0.-3.j]\n",
428-
" [1.+0.j 0.+0.j 0.+3.j 0.+0.j]\n",
429-
" [0.+0.j 0.-3.j 0.+0.j 1.+0.j]\n",
430-
" [0.+3.j 0.+0.j 1.+0.j 0.+0.j]]\n"
418+
"[[ 1.+0.j 0.+0.j 0.+0.j 0.-3.j]\n",
419+
" [ 0.+0.j -1.+0.j 0.+3.j 0.+0.j]\n",
420+
" [ 0.+0.j 0.-3.j 1.+0.j 0.+0.j]\n",
421+
" [ 0.+3.j 0.+0.j 0.+0.j -1.+0.j]]\n"
431422
]
432423
}
433424
],
@@ -458,7 +449,7 @@
458449
},
459450
{
460451
"cell_type": "code",
461-
"execution_count": null,
452+
"execution_count": 15,
462453
"id": "892f0b6e",
463454
"metadata": {},
464455
"outputs": [],
@@ -469,7 +460,7 @@
469460
},
470461
{
471462
"cell_type": "code",
472-
"execution_count": null,
463+
"execution_count": 16,
473464
"id": "745aa999",
474465
"metadata": {},
475466
"outputs": [
@@ -478,16 +469,15 @@
478469
"output_type": "stream",
479470
"text": [
480471
"BatchResult: 3 results\n",
481-
"Result: IBMDevice, AER_SIMULATOR\n",
482-
" Expectation value: 0.08399999999999999\n",
483-
" Error/Variance: 9.98776\n",
484-
"Result: ATOSDevice, MYQLM_PYLINALG\n",
485-
" Expectation value: 0.010000000000000009\n",
486-
" Error/Variance: 0.10000486474653607\n",
487472
"Result: ATOSDevice, MYQLM_CLINALG\n",
488-
" Expectation value: -0.017999999999999933\n",
489-
" Error/Variance: 0.10001671531970716\n",
490-
"\n"
473+
" Expectation value: 0.08200000000000007\n",
474+
" Error/Variance: 0.10000294289963965\n",
475+
"Result: ATOSDevice, MYQLM_PYLINALG\n",
476+
" Expectation value: 0.12600000000000006\n",
477+
" Error/Variance: 0.10000590573151757\n",
478+
"Result: IBMDevice, AER_SIMULATOR\n",
479+
" Expectation value: 0.14800000000000002\n",
480+
" Error/Variance: 9.987479999999998\n"
491481
]
492482
}
493483
],

examples/notebooks/6_Noise_Simulation.ipynb

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"from mpqp import QCircuit, Language\n",
2121
"from mpqp.gates import *\n",
2222
"from mpqp.noise import Depolarizing\n",
23-
"from mpqp.measures import *\n",
23+
"from mpqp.measures import BasisMeasure\n",
2424
"from mpqp.execution import *"
2525
]
2626
},
@@ -441,7 +441,7 @@
441441
],
442442
"source": [
443443
"for device in AWSDevice:\n",
444-
" print(device.name, \"|\", device.is_noisy_simulator() )"
444+
" print(device.name, \"|\", device.is_noisy_simulator())"
445445
]
446446
},
447447
{

mpqp/core/instruction/measurement/pauli_string.py

+8-5
Original file line numberDiff line numberDiff line change
@@ -458,14 +458,16 @@ class PauliStringAtom(PauliStringMonomial):
458458
"""Represents a single Pauli operator acting on a qubit in a Pauli string.
459459
460460
Args:
461-
label: The label representing the Pauli operator (e.g., 'I', 'X', 'Y', 'Z').
461+
label: The label representing the Pauli operator.
462462
matrix: The matrix representation of the Pauli operator.
463463
464464
Raises:
465-
AttributeError: new atoms cannot be created
465+
RuntimeError: New atoms cannot be created, you should use the available
466+
ones.
466467
467468
Note:
468-
All the atoms are already initialized. Available atoms are ('I', 'X', 'Y', 'Z').
469+
All the atoms are already initialized. Available atoms are (``I``,
470+
``X``, ``Y``, ``Z``).
469471
"""
470472

471473
__is_mutable = True
@@ -476,8 +478,9 @@ def __init__(self, label: str, matrix: npt.NDArray[np.complex64]):
476478
self.matrix = matrix
477479
self.__is_mutable = False
478480
else:
479-
raise AttributeError(
480-
"New atoms cannot be created, just use the given I, X, Y and Z"
481+
raise RuntimeError(
482+
"New atoms cannot be created, just use the given `I`, `X`, `Y` "
483+
"and `Z`"
481484
)
482485

483486
@property

mpqp/execution/connection/ibm_connection.py

+7-6
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def config_ibm_account(token: str):
2525
token: IBM Quantum API token.
2626
2727
Raises:
28-
IBMRemoteExecutionError
28+
IBMRemoteExecutionError: If the account could not be saved.
2929
"""
3030
from qiskit_ibm_provider import IBMProvider
3131

@@ -95,7 +95,8 @@ def get_IBMProvider() -> "IBMProvider":
9595
execution.
9696
9797
Raises:
98-
IBMRemoteExecutionError
98+
IBMRemoteExecutionError: In the account was not properly configured
99+
previously.
99100
100101
Example:
101102
>>> instance = get_IBMProvider()
@@ -124,13 +125,13 @@ def get_IBMProvider() -> "IBMProvider":
124125
Ibm_Provider = IBMProvider()
125126
except RequestsApiError as err:
126127
raise IBMRemoteExecutionError(
127-
"Error when instantiating IBM Provider (probably wrong token saved "
128-
"in the account).\nTrace: " + str(err)
128+
"Error when instantiating IBM Provider (probably wrong token "
129+
"saved in the account).\nTrace: " + str(err)
129130
)
130131
except AccountNotFoundError as err:
131132
raise IBMRemoteExecutionError(
132-
"Error when instantiating IBM Provider. No IBM Q account configured.\nTrace: "
133-
+ str(err)
133+
"Error when instantiating IBM Provider. No IBM Q account "
134+
"configured.\nTrace: " + str(err)
134135
)
135136
return Ibm_Provider
136137

mpqp/execution/connection/qlm_connection.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def config_qlm_account(username: str, password: str, global_config: bool) -> boo
2828
outside MPQP.
2929
3030
Raises:
31-
QLMRemoteExecutionError
31+
QLMRemoteExecutionError: If the account could not be saved.
3232
"""
3333
# store the username and password in environment variables QLM_USER and QLM_PASSWD in .mpqp
3434
prev_user = get_env_variable("QLM_USER")

mpqp/execution/devices.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,8 @@ def from_str_remote(name: str):
169169
name: A string containing the name of the device.
170170
171171
Raises:
172-
ValueError
172+
ValueError: If no device corresponding to the given name could be
173+
found.
173174
174175
Examples:
175176
>>> ATOSDevice.from_str_remote('NoisyQProc')

mpqp/execution/vqa/__init__.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# pyright: reportUnusedImport=false
2-
from .vqa import minimize
3-
from .optimizer import Optimizer
42
from sympy import symbols
3+
4+
from .optimizer import Optimizer
5+
from .vqa import minimize

0 commit comments

Comments
 (0)