Skip to content

Commit 25c9401

Browse files
Enable type-checking for transpiler.py and test_transpiler.py (#308)
* Enable type-checking for `transpiler.py` and `test_transpiler.py` This commit adds type annotations to the transpiler module and its corresponding tests, enabling full type-checking with `mypy` while preserving existing functionality.
1 parent ad56d1f commit 25c9401

File tree

4 files changed

+103
-112
lines changed

4 files changed

+103
-112
lines changed

graphix/sim/base_backend.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from __future__ import annotations
44

55
from abc import ABC, abstractmethod
6-
from typing import TYPE_CHECKING
6+
from typing import TYPE_CHECKING, Literal
77

88
import numpy as np
99

@@ -22,6 +22,7 @@
2222
from graphix import command
2323
from graphix.fundamentals import Plane
2424
from graphix.measurements import Measurement
25+
from graphix.parameter import ExpressionOrFloat
2526
from graphix.simulator import MeasureMethod
2627

2728

@@ -160,8 +161,8 @@ def _op_mat_from_result(vec: tuple[float, float, float], result: bool, symbolic:
160161

161162

162163
def perform_measure(
163-
qubit: int, plane: Plane, angle: float, state, rng, pr_calc: bool = True, symbolic: bool = False
164-
) -> npt.NDArray:
164+
qubit: int, plane: Plane, angle: ExpressionOrFloat, state, rng, pr_calc: bool = True, symbolic: bool = False
165+
) -> Literal[0, 1]:
165166
"""Perform measurement of a qubit."""
166167
vec = plane.polar(angle)
167168
if pr_calc:

graphix/sim/statevec.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ def tensor(self, other: Statevec) -> None:
281281
total_num = len(self.dims()) + len(other.dims())
282282
self.psi = np.kron(psi_self, psi_other).reshape((2,) * total_num)
283283

284-
def cnot(self, qubits):
284+
def cnot(self, qubits) -> None:
285285
"""Apply CNOT.
286286
287287
Parameters

0 commit comments

Comments
 (0)