Skip to content

Commit

Permalink
🚨 Fix manually
Browse files Browse the repository at this point in the history
  • Loading branch information
EarlMilktea committed Nov 1, 2024
1 parent ff72b85 commit cd6ebaa
Show file tree
Hide file tree
Showing 8 changed files with 13 additions and 15 deletions.
2 changes: 1 addition & 1 deletion graphix/device_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def __init__(self, pattern: Pattern, backend: str = "ibmq", **kwargs) -> None:
self.backend.to_qiskit(save_statevector)
self.backend.transpile(optimization_level)
self.shots = kwargs.get("shots", 1024)
except Exception:
except Exception: # noqa: BLE001

Check warning on line 53 in graphix/device_interface.py

View check run for this annotation

Codecov / codecov/patch

graphix/device_interface.py#L53

Added line #L53 was not covered by tests
save_statevector = kwargs.get("save_statevector", False)
optimization_level = kwargs.get("optimizer_level", 1)
self.backend.to_qiskit(save_statevector)
Expand Down
4 changes: 2 additions & 2 deletions graphix/extraction.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ def __eq__(self, other) -> bool:

def get_fusion_network_from_graph(
graph: BaseGraphState,
max_ghz: int | float = np.inf,
max_lin: int | float = np.inf,
max_ghz: float = np.inf,
max_lin: float = np.inf,
) -> list[ResourceGraph]:
"""Extract GHZ and linear cluster graph state decomposition of desired resource state :class:`~graphix.graphsim.GraphState`.
Expand Down
7 changes: 2 additions & 5 deletions graphix/gflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def check_meas_planes(meas_planes: dict[int, Plane]) -> None:
"""Check that all planes are valid planes."""
for node, plane in meas_planes.items():
if not isinstance(plane, Plane):
raise ValueError(f"Measure plane for {node} is `{plane}`, which is not an instance of `Plane`")
raise TypeError(f"Measure plane for {node} is `{plane}`, which is not an instance of `Plane`")

Check warning on line 37 in graphix/gflow.py

View check run for this annotation

Codecov / codecov/patch

graphix/gflow.py#L37

Added line #L37 was not covered by tests


def find_gflow(
Expand Down Expand Up @@ -982,10 +982,7 @@ def get_dependence_flow(
dependence_flow: dict[int, set]
dependence flow function. dependence_flow[i] is the set of qubits to be corrected for the measurement of qubit i.
"""
try: # if inputs is not empty
dependence_flow = {u: set() for u in inputs}
except Exception:
dependence_flow = dict()
dependence_flow = {u: set() for u in inputs}
# concatenate flow and odd_flow
combined_flow = dict()
for node, corrections in flow.items():
Expand Down
8 changes: 5 additions & 3 deletions graphix/pattern.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import warnings
from copy import deepcopy
from dataclasses import dataclass
from pathlib import Path
from typing import Iterator

import networkx as nx
Expand Down Expand Up @@ -239,7 +240,7 @@ def print_pattern(self, lim=40, target: list[CommandKind] | None = None) -> None
count += 1
print(
f"M, node = {cmd.node}, plane = {cmd.plane}, angle(pi) = {cmd.angle}, "
+ f"s_domain = {cmd.s_domain}, t_domain = {cmd.t_domain}"
f"s_domain = {cmd.s_domain}, t_domain = {cmd.t_domain}"
)
elif cmd.kind == CommandKind.X and (CommandKind.X in target):
count += 1
Expand Down Expand Up @@ -433,9 +434,10 @@ def is_standard(self):
xzc = {CommandKind.X, CommandKind.Z, CommandKind.C}
while kind in xzc:
kind = next(it).kind
return False
except StopIteration:
return True
else:
return False

def shift_signals(self, method="direct") -> dict[int, list[int]]:
"""Perform signal shifting procedure.
Expand Down Expand Up @@ -1520,7 +1522,7 @@ def to_qasm3(self, filename):
filename : str
file name to export to. example: "filename.qasm"
"""
with open(filename + ".qasm", "w") as file:
with Path(filename + ".qasm", "w").open() as file:

Check warning on line 1525 in graphix/pattern.py

View check run for this annotation

Codecov / codecov/patch

graphix/pattern.py#L1525

Added line #L1525 was not covered by tests
file.write("// generated by graphix\n")
file.write("OPENQASM 3;\n")
file.write('include "stdgates.inc";\n')
Expand Down
2 changes: 1 addition & 1 deletion graphix/random_objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ def rand_pauli_channel_kraus(dim: int, rng: Generator | None = None, rank: int |
rng = ensure_rng(rng)

if not isinstance(dim, int):
raise ValueError(f"The dimension must be an integer and not {dim}.")
raise TypeError(f"The dimension must be an integer and not {dim}.")

if not dim & (dim - 1) == 0:
raise ValueError(f"The dimension must be a power of 2 and not {dim}.")
Expand Down
1 change: 0 additions & 1 deletion graphix/sim/base_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ class State:
"""Base class for backend state."""



def _op_mat_from_result(vec: tuple[float, float, float], result: bool) -> np.ndarray:
op_mat = np.eye(2, dtype=np.complex128) / 2
sign = (-1) ** result
Expand Down
2 changes: 1 addition & 1 deletion tests/test_density_matrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -875,8 +875,8 @@ def test_init_fail(self, fx_rng: Generator, nqb, randpattern) -> None:
states = [PlanarState(plane=i, angle=j) for i, j in zip(rand_planes, rand_angles)]

# test init from State Iterable with incorrect size
backend = DensityMatrixBackend()
with pytest.raises(ValueError):
backend = DensityMatrixBackend()
backend.add_nodes(randpattern.input_nodes, data=states)

def test_init_success_2(self) -> None:
Expand Down
2 changes: 1 addition & 1 deletion tests/test_random_utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ def test_random_pauli_channel_fail(self, fx_rng: Generator) -> None:
with pytest.raises(TypeError):
randobj.rand_pauli_channel_kraus(dim=2**nqb, rank=rk + 0.5, rng=fx_rng)

with pytest.raises(ValueError):
with pytest.raises(TypeError):
randobj.rand_pauli_channel_kraus(dim=2**nqb + 0.5, rank=rk, rng=fx_rng)

with pytest.raises(ValueError):
Expand Down

0 comments on commit cd6ebaa

Please sign in to comment.