Skip to content

Commit

Permalink
bump v0.6.0.dev5 to v0.6.0.dev6 + update pre-commit + fix regression …
Browse files Browse the repository at this point in the history
…version issue (#88)
  • Loading branch information
ciaranra authored Nov 4, 2024
1 parent b61aadc commit cbccecf
Show file tree
Hide file tree
Showing 56 changed files with 80 additions and 114 deletions.
8 changes: 4 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.6.0
rev: v5.0.0
hooks:
- id: trailing-whitespace
exclude: ^docs/reference/_autosummary/
Expand All @@ -15,7 +15,7 @@ repos:
- id: debug-statements

- repo: https://github.com/crate-ci/typos
rev: v1.21.0
rev: v1.27.0
hooks:
- id: typos
args: []
Expand All @@ -25,13 +25,13 @@ repos:
)$
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.4.3
rev: v0.7.2
hooks:
- id: ruff
args: [--fix, --exit-non-zero-on-fix]

- repo: https://github.com/psf/black
rev: 24.4.2
rev: 24.10.0
hooks:
- id: black
exclude: |
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "quantum-pecos"
version = "0.6.0.dev5"
version = "0.6.0.dev6"
authors = [
{name = "The PECOS Developers"},
]
Expand Down
12 changes: 4 additions & 8 deletions python/pecos/circuit_converters/checks2circuit.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,7 @@ def compile(self, instr, abstract_circuit, mapping=None):
if make_ticks["max_zdatas"]:
# init [data ticks] meas
temp = make_ticks["max_zdatas"] + 1
if temp > largest_tick:
largest_tick = temp
largest_tick = max(temp, largest_tick)

if not make_ticks["max_xdatas"] and not make_ticks["max_zdatas"]:
msg = "Something very weird happened!"
Expand All @@ -98,14 +97,12 @@ def compile(self, instr, abstract_circuit, mapping=None):
tick_list = [ticks]

for t in tick_list:
if t > largest_tick:
largest_tick = t
largest_tick = max(t, largest_tick)

else:
tick = params["tick"]

if tick > largest_tick:
largest_tick = tick
largest_tick = max(tick, largest_tick)

# A quantum circuit with number of ticks == ``largest_tick``
circuit = QuantumCircuit(largest_tick + 1, **gate_params)
Expand Down Expand Up @@ -220,8 +217,7 @@ def _check_ticks(abstract_circuit):
break

if gate_symbol == "X check":
if len(datas) > max_xdatas:
max_xdatas = len(datas)
max_xdatas = max(len(datas), max_xdatas)

elif len(datas) > max_zdatas:
max_zdatas = len(datas)
Expand Down
1 change: 0 additions & 1 deletion python/pecos/error_models/generic_error_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
from pecos.error_models.error_model_abc import ErrorModel
from pecos.error_models.noise_impl.noise_initz_bitflip_leakage import noise_initz_bitflip_leakage
from pecos.error_models.noise_impl.noise_meas_bitflip_leakage import noise_meas_bitflip_leakage
from pecos.error_models.noise_impl.noise_meas_bitflip import noise_meas_bitflip
from pecos.error_models.noise_impl.noise_sq_depolarizing_leakage import noise_sq_depolarizing_leakage
from pecos.error_models.noise_impl.noise_tq_depolarizing_leakage import noise_tq_depolarizing_leakage
from pecos.error_models.noise_impl_old.gate_groups import one_qubits, two_qubits
Expand Down
2 changes: 1 addition & 1 deletion python/pecos/foreign_objects/object_pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class NamedObjectPool(ForeignObject):

def __init__(self, **objects: ForeignObject) -> None:
self.objs = objects
self.default = objects.get("default", None)
self.default = objects.get("default")

def new_instance(self) -> None:
"""Create new instance/internal state."""
Expand Down
4 changes: 2 additions & 2 deletions python/pecos/simulators/compile_cython.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ def main():
for d in cython_dirs:
path = Path(current_location / d)

p = subprocess.Popen(
p = subprocess.Popen( # noqa: S602
"python setup.py build_ext --inplace", # noqa: S607
shell=True, # noqa: S602
shell=True,
cwd=path,
stderr=subprocess.PIPE,
)
Expand Down
9 changes: 4 additions & 5 deletions python/pecos/slr/block.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,17 +62,16 @@ def __iter__(self):
def iter(self):
yield from self.__iter__()

def gen(self, target: object | str):

def gen(self, target: object | str, add_versions=True):
if isinstance(target, str):
if target == "qasm":
target = QASMGenerator()
target = QASMGenerator(add_versions=add_versions)
else:
msg = f"Code gen target '{target}' is not supported."
raise NotImplementedError(msg)

target.generate_block(self)
return target.get_output()

def qasm(self):
return self.gen("qasm")
def qasm(self, add_versions=True):
return self.gen("qasm", add_versions=add_versions)
30 changes: 20 additions & 10 deletions python/pecos/slr/gen_codes/gen_qasm.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,12 @@


class QASMGenerator:
def __init__(self, includes: list[str] | None = None):
def __init__(self, includes: list[str] | None = None, add_versions=True):
self.output = []
self.current_scope = None
self.includes = includes
self.cond = None
self.add_versions = add_versions

def write(self, line):
self.output.append(line)
Expand All @@ -37,8 +38,10 @@ def enter_block(self, block):
for inc in self.includes:
self.write(f'include "{str(inc)}";')
else:
# TODO: dump definitions in for things that are used instead of using includes
self.write('include "hqslib1.inc";')
self.write(f"// Generated using: PECOS version {__version__}")
if self.add_versions:
self.write(f"// Generated using: PECOS version {__version__}")
for var in block.vars:
var_def = self.process_var_def(var)
self.write(var_def)
Expand Down Expand Up @@ -71,7 +74,6 @@ def generate_block(self, block):
self.cond = None

elif block_name == "Repeat":

for _ in range(block.cond):
self.block_op_loop(block)
else:
Expand Down Expand Up @@ -180,7 +182,6 @@ def generate_op(self, op):
op_list = op_str.split("\n")
op_new = []
for o in op_list:

o = o.strip()
if o != "" and not o.startswith("//"):
for qi in o.split(";"):
Expand Down Expand Up @@ -215,22 +216,31 @@ def process_qgate(self, op):
op_str = self.qgate_tq_qasm(op)

else:

match sym:
case "Measure":
op_str = " ".join([f"measure {str(q)} -> {c};" for q, c in zip(op.qargs, op.cout, strict=True)])
op_str = " ".join(
[f"measure {str(q)} -> {c};" for q, c in zip(op.qargs, op.cout, strict=True)],
)

case "F":
op_str = " ".join([f"rx(pi/2) {str(q)};\nrz(pi/2) {str(q)};" for q in op.qargs])
op_str = " ".join(
[f"rx(pi/2) {str(q)};\nrz(pi/2) {str(q)};" for q in op.qargs],
)

case "Fdg":
op_str = " ".join([f"ry(-pi/2) {str(q)};\nrz(-pi/2) {str(q)};" for q in op.qargs])
op_str = " ".join(
[f"ry(-pi/2) {str(q)};\nrz(-pi/2) {str(q)};" for q in op.qargs],
)

case "F4":
op_str = " ".join([f"ry(-pi/2) {str(q)};\nrz(pi/2) {str(q)};" for q in op.qargs])
op_str = " ".join(
[f"ry(-pi/2) {str(q)};\nrz(pi/2) {str(q)};" for q in op.qargs],
)

case "F4dg":
op_str = " ".join([f"rx(-pi/2) {str(q)};\nrz(-pi/2) {str(q)};" for q in op.qargs])
op_str = " ".join(
[f"rx(-pi/2) {str(q)};\nrz(-pi/2) {str(q)};" for q in op.qargs],
)

case "Prep":
op_str = self.qgate_qasm(op, "reset")
Expand Down
3 changes: 1 addition & 2 deletions python/pecos/tools/stabilizer_verification.py
Original file line number Diff line number Diff line change
Expand Up @@ -913,8 +913,7 @@ def shortest_logicals(self, start_weight=None, delta=0, verbose=True, css=False)

qudit_set = self.data_qubits

if end_weight > len(qudit_set):
end_weight = len(qudit_set)
end_weight = min(end_weight, len(qudit_set))

state = self.state
found = self._dist_mode_smallest(
Expand Down
36 changes: 18 additions & 18 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,31 @@
#
# pip-compile --extra=tests --no-annotate --no-emit-index-url --output-file=requirements.txt --strip-extras pyproject.toml
#
annotated-types==0.6.0
attrs==23.2.0
contourpy==1.2.0
annotated-types==0.7.0
attrs==24.2.0
contourpy==1.3.0
cycler==0.12.1
fonttools==4.50.0
hypothesis==6.100.1
fonttools==4.54.1
hypothesis==6.116.0
iniconfig==2.0.0
kiwisolver==1.4.5
kiwisolver==1.4.7
markdown-it-py==3.0.0
matplotlib==3.8.3
matplotlib==3.9.2
mdurl==0.1.2
networkx==2.8.8
numpy==1.26.4
packaging==24.0
packaging==24.1
phir==0.3.3
pillow==10.2.0
pluggy==1.4.0
pydantic==2.6.4
pydantic-core==2.16.3
pygments==2.17.2
pyparsing==3.1.2
pytest==8.1.1
pillow==11.0.0
pluggy==1.5.0
pydantic==2.9.2
pydantic-core==2.23.4
pygments==2.18.0
pyparsing==3.2.0
pytest==8.3.3
python-dateutil==2.9.0.post0
rich==13.7.1
scipy==1.12.0
rich==13.9.4
scipy==1.14.1
six==1.16.0
sortedcontainers==2.4.0
typing-extensions==4.10.0
typing-extensions==4.12.2
1 change: 0 additions & 1 deletion tests/integration/state_sim_tests/test_cointoss.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
from __future__ import annotations

import numpy as np

from pecos.circuits import QuantumCircuit
from pecos.simulators import CoinToss

Expand Down
1 change: 0 additions & 1 deletion tests/integration/state_sim_tests/test_statevec.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@

import numpy as np
import pytest

from pecos.circuits import QuantumCircuit
from pecos.engines.hybrid_engine import HybridEngine
from pecos.error_models.generic_error_model import GenericErrorModel
Expand Down
26 changes: 13 additions & 13 deletions tests/integration/test_phir.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ def is_wasmer_supported():
return WASMER_ERR_MSG != "Wasmer is not available on this system"


@pytest.mark.wasmtime()
@pytest.mark.optional_dependency()
@pytest.mark.wasmtime
@pytest.mark.optional_dependency
def test_spec_example_wasmtime():
"""A random example showing that various basic aspects of PHIR is runnable by PECOS."""

Expand All @@ -67,8 +67,8 @@ def test_spec_example_wasmtime():
)


@pytest.mark.wasmtime()
@pytest.mark.optional_dependency()
@pytest.mark.wasmtime
@pytest.mark.optional_dependency
def test_spec_example_noisy_wasmtime():
"""A random example showing that various basic aspects of PHIR is runnable by PECOS, with noise."""

Expand All @@ -95,8 +95,8 @@ def test_spec_example_noisy_wasmtime():
)


@pytest.mark.wasmtime()
@pytest.mark.optional_dependency()
@pytest.mark.wasmtime
@pytest.mark.optional_dependency
def test_example1_wasmtime():
"""A random example showing that various basic aspects of PHIR is runnable by PECOS."""

Expand All @@ -108,8 +108,8 @@ def test_example1_wasmtime():
)


@pytest.mark.wasmtime()
@pytest.mark.optional_dependency()
@pytest.mark.wasmtime
@pytest.mark.optional_dependency
def test_example1_noisy_wasmtime():
"""A random example showing that various basic aspects of PHIR is runnable by PECOS, with noise."""

Expand Down Expand Up @@ -137,8 +137,8 @@ def test_example1_noisy_wasmtime():


@pytest.mark.skipif(not is_wasmer_supported(), reason="Wasmer is not support on some OS/Python version combinations.")
@pytest.mark.wasmer()
@pytest.mark.optional_dependency()
@pytest.mark.wasmer
@pytest.mark.optional_dependency
def test_example1_wasmer():
"""A random example showing that various basic aspects of PHIR is runnable by PECOS."""

Expand All @@ -151,8 +151,8 @@ def test_example1_wasmer():


@pytest.mark.skipif(not is_wasmer_supported(), reason="Wasmer is not support on some OS/Python version combinations.")
@pytest.mark.wasmer()
@pytest.mark.optional_dependency()
@pytest.mark.wasmer
@pytest.mark.optional_dependency
def test_example1_noisy_wasmer():
"""A random example showing that various basic aspects of PHIR is runnable by PECOS, with noise."""

Expand Down Expand Up @@ -260,7 +260,7 @@ def test_qparallel():
assert m.count("1111") == len(m)


@pytest.mark.optional_dependency() # uses projectq / state-vector
@pytest.mark.optional_dependency # uses projectq / state-vector
def test_bell_qparallel():
"""Testing a program creating and measuring a Bell state and using qparallel blocks returns expected results."""

Expand Down
17 changes: 12 additions & 5 deletions tests/regression/test_qasm/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,14 @@
import pytest


@pytest.fixture()
@pytest.fixture
def compare_qasm():
def _compare_qasm(block, *params, directory: Path | None = None, filename: str | None = None):

def _compare_qasm(
block,
*params,
directory: Path | None = None,
filename: str | None = None,
):
if directory is None:
directory = Path(__file__).parent

Expand All @@ -28,10 +32,13 @@ def _compare_qasm(block, *params, directory: Path | None = None, filename: str |

qasm1 = qasm1.strip()

if hasattr(block, "gen"):
# TODO: Fix this... this is kinda hacky
if hasattr(block, "qargs") and hasattr(block, "params") and hasattr(block, "sym"):
qasm2 = block.gen("qasm").strip()
elif hasattr(block, "gen"):
qasm2 = block.gen("qasm", add_versions=False).strip()
else:
qasm2 = block.qasm().strip()
qasm2 = block.qasm(add_versions=False).strip()

assert qasm1 == qasm2

Expand Down
Loading

0 comments on commit cbccecf

Please sign in to comment.