Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion graphqomb/euler.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ def __init__(self, alpha: float = 0, beta: float = 0, gamma: float = 0) -> None:

def print_angles(self) -> None:
"""Print the Euler angles."""
print(f"alpha: {self.alpha}, beta: {self.beta}, gamma: {self.gamma}") # noqa: T201
print(f"alpha: {self.alpha}, beta: {self.beta}, gamma: {self.gamma}") # ruff:ignore[print]

def conjugate(self) -> LocalUnitary:
"""Return the conjugate of the `LocalUnitary` object.
Expand Down
8 changes: 4 additions & 4 deletions graphqomb/feedforward.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def dag_from_flow(
------
TypeError
If the flowlike object is not a Flow or GFlow
""" # noqa: E501
""" # ruff:ignore[line-too-long]
dag: dict[int, set[int]] = {}
output_nodes = set(graph.output_node_indices)
non_output_nodes = graph.nodes - output_nodes
Expand Down Expand Up @@ -202,7 +202,7 @@ def check_flow(
The X correction flow (flow and gflow are included)
zflow : `collections.abc.Mapping`\[`int`, `int`\] | `collections.abc.Mapping`\[`int`, `collections.abc.Set`\[`int`\]\] | `None`
The Z correction flow. If `None`, it is generated from xflow by odd neighbors.
""" # noqa: E501
""" # ruff:ignore[line-too-long]
dag = dag_from_flow(graph, xflow, zflow)
check_dag(dag)

Expand Down Expand Up @@ -245,7 +245,7 @@ def signal_shifting(
return new_xflow, new_zflow


def propagate_correction_map( # noqa: C901, PLR0912
def propagate_correction_map( # ruff:ignore[complex-structure, too-many-branches]
target_node: int,
graph: BaseGraphState,
xflow: Mapping[int, AbstractSet[int]],
Expand Down Expand Up @@ -331,7 +331,7 @@ def propagate_correction_map( # noqa: C901, PLR0912
return new_xflow, new_zflow


def pauli_simplification( # noqa: C901, PLR0912
def pauli_simplification( # ruff:ignore[complex-structure, too-many-branches]
graph: BaseGraphState,
xflow: Mapping[int, AbstractSet[int]],
zflow: Mapping[int, AbstractSet[int]] | None = None,
Expand Down
4 changes: 2 additions & 2 deletions graphqomb/focus_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def is_focused(flowlike: Mapping[int, int] | Mapping[int, AbstractSet[int]], gra
------
TypeError
If the flowlike object is not a Flow or GFlow
""" # noqa: E501
""" # ruff:ignore[line-too-long]
meas_bases = graph.meas_bases
outputs = set(graph.output_node_indices)

Expand Down Expand Up @@ -88,7 +88,7 @@ def focus_gflow(
------
TypeError
If the flowlike object is not a Flow or GFlow
""" # noqa: E501
""" # ruff:ignore[line-too-long]
if _is_flow(flowlike):
flowlike = {key: {value} for key, value in flowlike.items()}
elif _is_gflow(flowlike):
Expand Down
26 changes: 13 additions & 13 deletions graphqomb/gates.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ def unit_gates(self) -> list[UnitGate]:
"""
return [self]

def matrix( # noqa: PLR6301
def matrix( # ruff:ignore[no-self-use]
self,
) -> NDArray[np.complex128]:
r"""Get the `matrix` representation of the gate.
Expand Down Expand Up @@ -267,7 +267,7 @@ def unit_gates(self) -> list[UnitGate]:
"""
return [J(self.qubit, 0), J(self.qubit, 0)]

def matrix(self) -> NDArray[np.complex128]: # noqa: PLR6301
def matrix(self) -> NDArray[np.complex128]: # ruff:ignore[no-self-use]
r"""Get the `matrix` representation of the gate.

Returns
Expand Down Expand Up @@ -308,7 +308,7 @@ def unit_gates(self) -> list[UnitGate]:
"""
return [J(self.qubit, 0), J(self.qubit, math.pi)]

def matrix(self) -> NDArray[np.complex128]: # noqa: PLR6301
def matrix(self) -> NDArray[np.complex128]: # ruff:ignore[no-self-use]
r"""Get the `matrix` representation of the gate.

Returns
Expand Down Expand Up @@ -354,7 +354,7 @@ def unit_gates(self) -> list[UnitGate]:
J(self.qubit, 0),
]

def matrix(self) -> NDArray[np.complex128]: # noqa: PLR6301
def matrix(self) -> NDArray[np.complex128]: # ruff:ignore[no-self-use]
r"""Get the `matrix` representation of the gate.

Returns
Expand Down Expand Up @@ -395,7 +395,7 @@ def unit_gates(self) -> list[UnitGate]:
"""
return [J(self.qubit, math.pi), J(self.qubit, 0)]

def matrix(self) -> NDArray[np.complex128]: # noqa: PLR6301
def matrix(self) -> NDArray[np.complex128]: # ruff:ignore[no-self-use]
r"""Get the `matrix` representation of the gate.

Returns
Expand Down Expand Up @@ -436,7 +436,7 @@ def unit_gates(self) -> list[UnitGate]:
"""
return [J(self.qubit, 0)]

def matrix(self) -> NDArray[np.complex128]: # noqa: PLR6301
def matrix(self) -> NDArray[np.complex128]: # ruff:ignore[no-self-use]
r"""Get the `matrix` representation of the gate.

Returns
Expand Down Expand Up @@ -478,7 +478,7 @@ def unit_gates(self) -> list[UnitGate]:
"""
return [J(self.qubit, math.pi / 2), J(self.qubit, 0)]

def matrix(self) -> NDArray[np.complex128]: # noqa: PLR6301
def matrix(self) -> NDArray[np.complex128]: # ruff:ignore[no-self-use]
r"""Get the `matrix` representation of the gate.

Returns
Expand Down Expand Up @@ -519,7 +519,7 @@ def unit_gates(self) -> list[UnitGate]:
"""
return [J(self.qubit, math.pi / 4), J(self.qubit, 0)]

def matrix(self) -> NDArray[np.complex128]: # noqa: PLR6301
def matrix(self) -> NDArray[np.complex128]: # ruff:ignore[no-self-use]
r"""Get the `matrix` representation of the gate.

Returns
Expand Down Expand Up @@ -560,7 +560,7 @@ def unit_gates(self) -> list[UnitGate]:
"""
return [J(self.qubit, -math.pi / 4), J(self.qubit, 0)]

def matrix(self) -> NDArray[np.complex128]: # noqa: PLR6301
def matrix(self) -> NDArray[np.complex128]: # ruff:ignore[no-self-use]
r"""Get the `matrix` representation of the gate.

Returns
Expand Down Expand Up @@ -830,7 +830,7 @@ def unit_gates(self) -> list[UnitGate]:
J(target, 0),
]

def matrix(self) -> NDArray[np.complex128]: # noqa: PLR6301
def matrix(self) -> NDArray[np.complex128]: # ruff:ignore[no-self-use]
r"""Get the `matrix` representation of the gate.

Returns
Expand Down Expand Up @@ -885,7 +885,7 @@ def unit_gates(self) -> list[UnitGate]:
unit_gates.extend(macro_gate.unit_gates())
return unit_gates

def matrix(self) -> NDArray[np.complex128]: # noqa: PLR6301
def matrix(self) -> NDArray[np.complex128]: # ruff:ignore[no-self-use]
r"""Get the `matrix` representation of the gate.

Returns
Expand Down Expand Up @@ -1170,7 +1170,7 @@ def unit_gates(self) -> list[UnitGate]:
unit_gates.extend(macro_gate.unit_gates())
return unit_gates

def matrix(self) -> NDArray[np.complex128]: # noqa: PLR6301
def matrix(self) -> NDArray[np.complex128]: # ruff:ignore[no-self-use]
r"""Get the `matrix` representation of the gate.

Returns
Expand Down Expand Up @@ -1238,7 +1238,7 @@ def unit_gates(self) -> list[UnitGate]:
unit_gates.extend(macro_gate.unit_gates())
return unit_gates

def matrix(self) -> NDArray[np.complex128]: # noqa: PLR6301
def matrix(self) -> NDArray[np.complex128]: # ruff:ignore[no-self-use]
r"""Get the `matrix` representation of the gate.

Returns
Expand Down
4 changes: 2 additions & 2 deletions graphqomb/graphstate.py
Original file line number Diff line number Diff line change
Expand Up @@ -746,7 +746,7 @@ def _expand_output_local_cliffords(self) -> dict[int, LocalCliffordExpansion]:
return node_index_addition_map

@classmethod
def from_graph( # noqa: C901, PLR0912, PLR0913, PLR0917
def from_graph( # ruff:ignore[complex-structure, too-many-branches, too-many-arguments, too-many-positional-arguments]
cls,
nodes: Iterable[NodeT],
edges: Iterable[tuple[NodeT, NodeT]],
Expand Down Expand Up @@ -946,7 +946,7 @@ class ExpansionMaps(NamedTuple):
output_node_map: dict[int, LocalCliffordExpansion]


def compose( # noqa: C901, PLR0912
def compose( # ruff:ignore[complex-structure, too-many-branches]
graph1: BaseGraphState, graph2: BaseGraphState
) -> tuple[GraphState, dict[int, int], dict[int, int]]:
r"""Compose two graph states sequentially.
Expand Down
10 changes: 5 additions & 5 deletions graphqomb/greedy_scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
from graphqomb.graphstate import BaseGraphState


def greedy_minimize_time( # noqa: PLR0914
def greedy_minimize_time( # ruff:ignore[too-many-locals]
graph: BaseGraphState,
dag: Mapping[int, AbstractSet[int]],
max_qubit_count: int | None = None,
Expand Down Expand Up @@ -163,7 +163,7 @@ def greedy_minimize_time( # noqa: PLR0914
return prepare_time, measure_time


def _prepare_remaining_nodes_at_tail( # noqa: PLR0913
def _prepare_remaining_nodes_at_tail( # ruff:ignore[too-many-arguments]
current_time: int,
*,
nodes: AbstractSet[int],
Expand Down Expand Up @@ -191,7 +191,7 @@ def _prepare_remaining_nodes_at_tail( # noqa: PLR0913
alive.update(remaining)


def _phase1_measure_ready_nodes( # noqa: PLR0913
def _phase1_measure_ready_nodes( # ruff:ignore[too-many-arguments]
current_time: int,
*,
dag: Mapping[int, AbstractSet[int]],
Expand Down Expand Up @@ -251,7 +251,7 @@ def _has_initial_input_input_entanglement_wait(
return False


def _phase2_prepare_nodes_with_slack( # noqa: PLR0913
def _phase2_prepare_nodes_with_slack( # ruff:ignore[too-many-arguments]
current_time: int,
*,
nodes: AbstractSet[int],
Expand Down Expand Up @@ -364,7 +364,7 @@ def _get_prep_candidates_with_priority(
return scores


def greedy_minimize_space( # noqa: PLR0914
def greedy_minimize_space( # ruff:ignore[too-many-locals]
graph: BaseGraphState,
dag: Mapping[int, AbstractSet[int]],
) -> tuple[dict[int, int], dict[int, int]]:
Expand Down
18 changes: 9 additions & 9 deletions graphqomb/noise_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,14 +273,14 @@ class Coordinate:
@property
def xy(self) -> tuple[float, float] | None:
"""The first two dimensions as (x, y), or None if fewer than 2 dimensions."""
if len(self.values) < 2: # noqa: PLR2004
if len(self.values) < 2: # ruff:ignore[magic-value-comparison]
return None
return (self.values[0], self.values[1])

@property
def xyz(self) -> tuple[float, float, float] | None:
"""The first three dimensions as (x, y, z), or None if fewer than 3 dimensions."""
if len(self.values) < 3: # noqa: PLR2004
if len(self.values) < 3: # ruff:ignore[magic-value-comparison]
return None
return (self.values[0], self.values[1], self.values[2])

Expand Down Expand Up @@ -758,7 +758,7 @@ class NoiseModel:

"""

def on_prepare(self, event: PrepareEvent) -> Sequence[NoiseOp]: # noqa: ARG002, PLR6301
def on_prepare(self, event: PrepareEvent) -> Sequence[NoiseOp]: # ruff:ignore[unused-method-argument, no-self-use]
r"""Return noise operations to inject at qubit preparation.

Parameters
Expand All @@ -773,7 +773,7 @@ def on_prepare(self, event: PrepareEvent) -> Sequence[NoiseOp]: # noqa: ARG002,
"""
return []

def on_entangle(self, event: EntangleEvent) -> Sequence[NoiseOp]: # noqa: ARG002, PLR6301
def on_entangle(self, event: EntangleEvent) -> Sequence[NoiseOp]: # ruff:ignore[unused-method-argument, no-self-use]
r"""Return noise operations to inject at entanglement.

Parameters
Expand All @@ -788,7 +788,7 @@ def on_entangle(self, event: EntangleEvent) -> Sequence[NoiseOp]: # noqa: ARG00
"""
return []

def on_measure(self, event: MeasureEvent) -> Sequence[NoiseOp]: # noqa: ARG002, PLR6301
def on_measure(self, event: MeasureEvent) -> Sequence[NoiseOp]: # ruff:ignore[unused-method-argument, no-self-use]
r"""Return noise operations to inject at measurement.

Parameters
Expand All @@ -803,7 +803,7 @@ def on_measure(self, event: MeasureEvent) -> Sequence[NoiseOp]: # noqa: ARG002,
"""
return []

def on_idle(self, event: IdleEvent) -> Sequence[NoiseOp]: # noqa: ARG002, PLR6301
def on_idle(self, event: IdleEvent) -> Sequence[NoiseOp]: # ruff:ignore[unused-method-argument, no-self-use]
r"""Return noise operations to inject during idle periods.

Parameters
Expand All @@ -819,7 +819,7 @@ def on_idle(self, event: IdleEvent) -> Sequence[NoiseOp]: # noqa: ARG002, PLR63
return []


def noise_op_to_stim(op: NoiseOp) -> tuple[str, int]: # noqa: PLR0911, C901
def noise_op_to_stim(op: NoiseOp) -> tuple[str, int]: # ruff:ignore[too-many-return-statements, complex-structure]
r"""Convert a NoiseOp into a Stim instruction line and record delta.

Parameters
Expand Down Expand Up @@ -913,7 +913,7 @@ def _normalize_pauli_channel_2_sequence(probabilities: Sequence[float]) -> tuple
def _normalize_pauli_channel_2_targets(targets: Sequence[tuple[int, int]]) -> tuple[tuple[int, int], ...]:
normalized: list[tuple[int, int]] = []
for pair in targets:
if len(pair) != 2: # noqa: PLR2004
if len(pair) != 2: # ruff:ignore[magic-value-comparison]
msg = f"PAULI_CHANNEL_2 targets must be pairs, got: {pair!r}"
raise ValueError(msg)
normalized.append((pair[0], pair[1]))
Expand All @@ -923,7 +923,7 @@ def _normalize_pauli_channel_2_targets(targets: Sequence[tuple[int, int]]) -> tu
def _flatten_pairs(pairs: Sequence[tuple[int, int]]) -> tuple[int, ...]:
flat: list[int] = []
for pair in pairs:
if len(pair) != 2: # noqa: PLR2004
if len(pair) != 2: # ruff:ignore[magic-value-comparison]
msg = f"PAULI_CHANNEL_2 targets must be pairs, got: {pair!r}"
raise ValueError(msg)
flat.extend(pair)
Expand Down
10 changes: 5 additions & 5 deletions graphqomb/ptn_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ def _parse_node_qubit_pairs(parts: Sequence[str]) -> dict[int, int]:
result: dict[int, int] = {}
for part in parts:
pair = part.split(":")
if len(pair) != 2: # noqa: PLR2004
if len(pair) != 2: # ruff:ignore[magic-value-comparison]
msg = f"Invalid node:qubit pair: {part!r}"
raise ValueError(msg)
node_str, qidx_str = pair
Expand Down Expand Up @@ -419,7 +419,7 @@ def _parse_arrow_mapping(line: str, label: str) -> tuple[int, set[int]]:
If the mapping is malformed.
"""
parts = line.split("->")
if len(parts) != 2: # noqa: PLR2004
if len(parts) != 2: # ruff:ignore[magic-value-comparison]
msg = f"{label} must contain exactly one '->'"
raise ValueError(msg)
source_part = parts[0].strip()
Expand Down Expand Up @@ -860,7 +860,7 @@ def _parse_n_command(self, parts: Sequence[str]) -> None:
msg = "N command requires a node and optional 2D or 3D coordinates"
raise ValueError(msg)
node = _parse_int(parts[1], "node")
coord: tuple[float, ...] | None = _parse_coord(parts[2:]) if len(parts) > 2 else None # noqa: PLR2004
coord: tuple[float, ...] | None = _parse_coord(parts[2:]) if len(parts) > 2 else None # ruff:ignore[magic-value-comparison]
self.result.commands.append(N(node=node, coordinate=coord))

def _parse_e_command(self, parts: Sequence[str]) -> None:
Expand All @@ -871,7 +871,7 @@ def _parse_e_command(self, parts: Sequence[str]) -> None:
ValueError
If the command is malformed.
"""
if len(parts) != 3: # noqa: PLR2004
if len(parts) != 3: # ruff:ignore[magic-value-comparison]
msg = "E command requires exactly two nodes"
raise ValueError(msg)
node1 = _parse_int(parts[1], "node")
Expand All @@ -886,7 +886,7 @@ def _parse_m_command(self, parts: Sequence[str]) -> None:
ValueError
If the command is malformed.
"""
if len(parts) != 4: # noqa: PLR2004
if len(parts) != 4: # ruff:ignore[magic-value-comparison]
msg = "M command requires a node, basis, and angle/sign"
raise ValueError(msg)
node = _parse_int(parts[1], "node")
Expand Down
2 changes: 1 addition & 1 deletion graphqomb/qompiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
from graphqomb.graphstate import BaseGraphState


def qompile( # noqa: PLR0913
def qompile( # ruff:ignore[too-many-arguments]
graph: BaseGraphState,
xflow: Mapping[int, AbstractSet[int]],
zflow: Mapping[int, AbstractSet[int]] | None = None,
Expand Down
2 changes: 1 addition & 1 deletion graphqomb/rng.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,5 @@ def ensure_rng(rng: Generator | None = None) -> Generator:
return stored
rng = np.random.default_rng()
# MEMO: Cannot perform type check
setattr(_rng_local, "rng", rng) # noqa: B010
setattr(_rng_local, "rng", rng) # ruff:ignore[set-attr-with-constant]
return rng
2 changes: 1 addition & 1 deletion graphqomb/scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class TimeSlice(NamedTuple):
measure_nodes: set[int] #: Set of node indices to measure in this time slice.


def compress_schedule( # noqa: C901, PLR0912
def compress_schedule( # ruff:ignore[complex-structure, too-many-branches]
prepare_time: Mapping[int, int | None],
measure_time: Mapping[int, int | None],
entangle_time: Mapping[tuple[int, int], int | None] | None = None,
Expand Down
Loading
Loading