Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pre-version patch #114

Merged
merged 11 commits into from
Nov 21, 2024
20 changes: 11 additions & 9 deletions examples/notebooks/1_Basics_of_circuit.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -220,9 +220,11 @@
"cell_type": "code",
"execution_count": 9,
"id": "50e96aae",
"metadata": {"tags": [
"skip-execution"
]},
"metadata": {
"tags": [
"skip-execution"
]
},
"outputs": [
{
"data": {
Expand Down Expand Up @@ -315,7 +317,7 @@
},
{
"cell_type": "code",
"execution_count": 13,
"execution_count": null,
"id": "780d0208",
"metadata": {},
"outputs": [
Expand All @@ -331,7 +333,7 @@
}
],
"source": [
"circ3.get_measurements()"
"circ3.measurements"
]
},
{
Expand Down Expand Up @@ -569,7 +571,7 @@
},
{
"cell_type": "code",
"execution_count": 21,
"execution_count": null,
"id": "c39e3e72",
"metadata": {},
"outputs": [
Expand All @@ -596,12 +598,12 @@
}
],
"source": [
"print(circ3.to_qasm2())"
"print(circ3.to_other_language(Language.QASM2))"
]
},
{
"cell_type": "code",
"execution_count": 22,
"execution_count": null,
"id": "0cdb44e5",
"metadata": {},
"outputs": [
Expand Down Expand Up @@ -629,7 +631,7 @@
}
],
"source": [
"print(circ3.to_qasm3())"
"print(circ3.to_other_language(Language.QASM3))"
]
},
{
Expand Down
2 changes: 1 addition & 1 deletion examples/scripts/open_qasm_conversions.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
barrier q;"""

# this exemple should be executed from mpqp root
print(open_qasm_2_to_3(qasm2_3, path_to_file="."))
print(open_qasm_2_to_3(qasm2_3, path_to_file="./examples/scripts"))

print("-------------------------")
print("-------------------------")
Expand Down
20 changes: 16 additions & 4 deletions mpqp/execution/simulated_devices.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,15 @@ def is_remote(self) -> bool:
class StaticIBMSimulatedDevice(SimulatedDevice):
"""A class regrouping methods specific to an ``IBMSimulatedDevice``."""

def supports_observable(self) -> bool:
return True

def supports_observable_ideal(self) -> bool:
return True

def supports_samples(self) -> bool:
return False

def supports_state_vector(self):
return False

Expand All @@ -58,13 +67,16 @@ def to_noise_model(self) -> "Qiskit_NoiseModel":
@staticmethod
def get_ibm_fake_providers() -> list[tuple[str, type["FakeBackendV2"]]]:
from qiskit_ibm_runtime import fake_provider
from qiskit_ibm_runtime.fake_provider.fake_backend import FakeBackendV2

fake_imports = fake_provider.__dict__
return [
(p, fake_imports[p])
for p in fake_imports
if p.startswith("Fake")
and not p.startswith(("FakeProvider", "FakeFractional"))
(name, device)
for name, device in fake_imports.items()
if name.startswith("Fake")
and not name.startswith(("FakeProvider", "FakeFractional"))
and issubclass(device, FakeBackendV2)
and "cairo" not in name.lower()
]


Expand Down
10 changes: 9 additions & 1 deletion mpqp/noise/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,9 @@
from mpqp.noise.noise_model import *
# pyright: reportUnusedImport=false
from mpqp.noise.noise_model import (
AmplitudeDamping,
BitFlip,
Depolarizing,
DimensionalNoiseModel,
NoiseModel,
PhaseDamping,
)
3 changes: 1 addition & 2 deletions mpqp/tools/display.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@

import numpy as np
import numpy.typing as npt
from sympy import Basic

if TYPE_CHECKING:
from sympy import Expr
from sympy import Expr, Basic

from typeguard import typechecked

Expand Down
2 changes: 2 additions & 0 deletions pytest.ini
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ filterwarnings =
ignore: Treating CircuitInstruction as an iterable is deprecated.*:DeprecationWarning
ignore:The qiskit.extensions module is pending deprecation.*:PendingDeprecationWarning
ignore:Building a flow controller with keyword arguments is going to be deprecated.*:PendingDeprecationWarning
ignore:The class ``qiskit.qobj.pulse_qobj.PulseQobjInstruction`` is deprecated as of qiskit 1.2.*:DeprecationWarning
ignore:The class ``qiskit.qobj.pulse_qobj.PulseLibraryItem`` is deprecated as of qiskit 1.2.*:DeprecationWarning
; others
; pyreadline
ignore:Using or importing the ABCs from.*:DeprecationWarning
Expand Down
4 changes: 2 additions & 2 deletions tests/execution/test_validity.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ def test_sample_counts_in_trust_interval(instructions: list[Gate]):
c = QCircuit(instructions)
shots = 50000
err_rate = 0.2
err_rate_pourcentage = 1 - np.power(1 - err_rate, (1 / 2))
err_rate_percentage = 1 - np.power(1 - err_rate, (1 / 2))
res = run(c, state_vector_devices[0])
assert isinstance(res, Result)
expected_counts = [int(count) for count in np.round(shots * res.probabilities)]
Expand All @@ -281,7 +281,7 @@ def test_sample_counts_in_trust_interval(instructions: list[Gate]):
# check if the true value is inside the trust interval
for i in range(len(counts)):
trust_interval = np.ceil(
err_rate_pourcentage * expected_counts[i] + shots / 15
err_rate_percentage * expected_counts[i] + shots / 15
)
print(trust_interval)
assert (
Expand Down
48 changes: 27 additions & 21 deletions tests/test_doc.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@
from functools import partial
from types import TracebackType
from typing import Any, Optional, Type
from anytree import Node

import pytest
from anytree import Node
from dotenv import dotenv_values, set_key, unset_key
from numpy.random import default_rng

from mpqp.all import *
from mpqp.core.instruction.measurement import pauli_string
from mpqp.core.instruction.measurement.pauli_string import PauliString
Expand All @@ -25,41 +27,40 @@
from mpqp.execution.providers.aws import estimate_cost_single_job
from mpqp.execution.runner import generate_job
from mpqp.noise.noise_model import _plural_marker # pyright: ignore[reportPrivateUsage]
from mpqp.tools.display import clean_1D_array, clean_matrix, pprint, format_element
from mpqp.tools.circuit import random_circuit, random_gate, random_noise
from mpqp.qasm import (
qasm2_to_cirq_Circuit,
qasm2_to_myqlm_Circuit,
qasm2_to_Qiskit_Circuit,
qasm3_to_braket_Program,
)
from mpqp.qasm.mpqp_to_qasm import mpqp_to_qasm2
from mpqp.qasm.open_qasm_2_and_3 import (
convert_instruction_3_to_2,
open_qasm_2_to_3,
parse_user_gates,
remove_user_gates,
open_qasm_3_to_2,
convert_instruction_3_to_2,
open_qasm_file_conversion_3_to_2,
parse_user_gates,
remove_include_and_comment,
)
from mpqp.qasm.qasm_to_mpqp import qasm2_parse
from mpqp.qasm import (
qasm2_to_Qiskit_Circuit,
qasm2_to_cirq_Circuit,
qasm2_to_myqlm_Circuit,
qasm3_to_braket_Program,
remove_user_gates,
)
from mpqp.qasm.qasm_to_braket import qasm3_to_braket_Circuit
from mpqp.tools.maths import (
is_hermitian,
is_unitary,
normalize,
rand_orthogonal_matrix,
is_power_of_two,
)
from mpqp.qasm.qasm_to_mpqp import qasm2_parse
from mpqp.tools.circuit import random_circuit, random_gate, random_noise
from mpqp.tools.display import *
from mpqp.tools.display import clean_1D_array, clean_matrix, format_element, pprint
from mpqp.tools.errors import (
OpenQASMTranslationWarning,
UnsupportedBraketFeaturesWarning,
)
from mpqp.tools.generics import find, find_index, flatten
from mpqp.tools.maths import *
from numpy.random import default_rng
from mpqp.tools.maths import (
is_hermitian,
is_power_of_two,
is_unitary,
normalize,
rand_orthogonal_matrix,
)

sys.path.insert(0, os.path.abspath("."))

Expand Down Expand Up @@ -123,6 +124,11 @@ def run_doctest(root: str, filename: str, monkeypatch: pytest.MonkeyPatch):
monkeypatch.setattr('numpy.random.default_rng', stable_random)
warnings.filterwarnings("ignore", category=UnsupportedBraketFeaturesWarning)
warnings.filterwarnings("ignore", category=OpenQASMTranslationWarning)
warnings.filterwarnings(
"ignore",
category=UserWarning,
message=r".*Noise is not applied to any gate, as there is no eligible gate in the circuit.*",
)
assert True
my_module = importlib.import_module(
os.path.join(root, filename)
Expand Down
Loading