Skip to content

Commit

Permalink
Use latest pybind11-stubgen (#1319)
Browse files Browse the repository at this point in the history
  • Loading branch information
cqc-alec authored Mar 28, 2024
1 parent 2201605 commit cce17c7
Show file tree
Hide file tree
Showing 8 changed files with 105 additions and 106 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/build_and_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -403,8 +403,7 @@ jobs:
- name: Check type stubs are up-to-date and run mypy
if: matrix.os == 'macos-13-xlarge' && (github.event_name == 'pull_request' || github.event_name == 'workflow_dispatch')
run: |
python -m pip install -U mypy
python -m pip install pybind11-stubgen==2.3.6 # https://github.com/CQCL/tket/issues/1135
python -m pip install -U mypy pybind11-stubgen
cd pytket
./stub_generation/regenerate_stubs
git diff --quiet pytket/_tket && echo "Stubs are up-to-date" || exit 1 # fail if stubs change after regeneration
Expand Down
122 changes: 61 additions & 61 deletions pytket/pytket/_tket/circuit.pyi

Large diffs are not rendered by default.

26 changes: 13 additions & 13 deletions pytket/pytket/_tket/passes.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class BasePass:
:return: True if pass modified the circuit, else False
"""
@typing.overload
def apply(self, circuit: pytket._tket.circuit.Circuit, before_apply: typing.Callable[[pytket._tket.predicates.CompilationUnit, object], None], after_apply: typing.Callable[[pytket._tket.predicates.CompilationUnit, object], None]) -> bool:
def apply(self, circuit: pytket._tket.circuit.Circuit, before_apply: typing.Callable[[pytket._tket.predicates.CompilationUnit, typing.Any], None], after_apply: typing.Callable[[pytket._tket.predicates.CompilationUnit, typing.Any], None]) -> bool:
"""
Apply to a :py:class:`Circuit` in-place and invoke callbacks for all nested passes.
Expand Down Expand Up @@ -123,7 +123,7 @@ class RepeatUntilSatisfiedPass(BasePass):
"""
Construct from a compilation pass and a user-defined function from :py:class:`Circuit` to `bool`.
"""
def __str__(self) -> str:
def __str__(self: BasePass) -> str:
...
def get_pass(self) -> BasePass:
"""
Expand All @@ -141,7 +141,7 @@ class RepeatWithMetricPass(BasePass):
"""
Construct from a compilation pass and a metric function.
"""
def __str__(self) -> str:
def __str__(self: BasePass) -> str:
...
def get_metric(self) -> typing.Callable[[pytket._tket.circuit.Circuit], int]:
"""
Expand Down Expand Up @@ -196,7 +196,7 @@ class SequencePass(BasePass):
"""
Construct from a list of compilation passes arranged in order of application.
"""
def __str__(self) -> str:
def __str__(self: BasePass) -> str:
...
def get_sequence(self) -> list[BasePass]:
"""
Expand All @@ -212,7 +212,7 @@ def AASRouting(arc: pytket._tket.architecture.Architecture, **kwargs: Any) -> Ba
NB: The circuit needs to have at most as many qubits as the architecture has nodes. The resulting circuit will always have the same number of qubits as the architecture has nodes, even if the input circuit had fewer.
:param arc: target architecture
:param \**kwargs: parameters for routing (described above)
:param \\**kwargs: parameters for routing (described above)
:return: a pass to perform the remapping
"""
def CXMappingPass(arc: pytket._tket.architecture.Architecture, placer: pytket._tket.placement.Placement, **kwargs: Any) -> BasePass:
Expand All @@ -221,7 +221,7 @@ def CXMappingPass(arc: pytket._tket.architecture.Architecture, placer: pytket._t
:param arc: The Architecture used for connectivity information.
:param placer: The placement used for relabelling.
:param \**kwargs: Parameters for routing: (bool)directed_cx=false, (bool)delay_measures=true
:param \\**kwargs: Parameters for routing: (bool)directed_cx=false, (bool)delay_measures=true
:return: a pass to perform the remapping
"""
def CliffordPushThroughMeasures() -> BasePass:
Expand Down Expand Up @@ -258,7 +258,7 @@ def ComposePhasePolyBoxes(min_size: int = 0) -> BasePass:
- (unsigned) min_size=0: minimal number of CX gates in each phase polynominal box: groups with a smaller number of CX gates are not affected by this transformation
:param \**kwargs: parameters for composition (described above)
:param \\**kwargs: parameters for composition (described above)
:return: a pass to perform the composition
"""
def ContextSimp(allow_classical: bool = True, xcirc: pytket._tket.circuit.Circuit | None = None) -> BasePass:
Expand Down Expand Up @@ -494,13 +494,13 @@ def PlacementPass(placer: pytket._tket.placement.Placement) -> BasePass:
:return: a pass to relabel :py:class:`Circuit` Qubits to :py:class:`Architecture` Nodes
"""
@typing.overload
def RebaseCustom(gateset: set[pytket._tket.circuit.OpType], cx_replacement: pytket._tket.circuit.Circuit, tk1_replacement: typing.Callable[[typing.Union[sympy.Expr, float], typing.Union[sympy.Expr, float], typing.Union[sympy.Expr, float]], pytket._tket.circuit.Circuit]) -> BasePass:
def RebaseCustom(gateset: set[pytket._tket.circuit.OpType], cx_replacement: pytket._tket.circuit.Circuit, tk1_replacement: typing.Callable[[sympy.Expr | float, sympy.Expr | float, sympy.Expr | float], pytket._tket.circuit.Circuit]) -> BasePass:
"""
Construct a custom rebase pass, given user-defined rebases for TK1 and CX. This pass:
1. decomposes multi-qubit gates not in the set of gate types `gateset` to CX gates;
2. if CX is not in `gateset`, replaces CX gates with `cx_replacement`;
3. converts any single-qubit gates not in the gate type set to the form :math:`\mathrm{Rz}(a)\mathrm{Rx}(b)\mathrm{Rz}(c)` (in matrix-multiplication order, i.e. reverse order in the circuit);
3. converts any single-qubit gates not in the gate type set to the form :math:`\\mathrm{Rz}(a)\\mathrm{Rx}(b)\\mathrm{Rz}(c)` (in matrix-multiplication order, i.e. reverse order in the circuit);
4. applies the `tk1_replacement` function to each of these triples :math:`(a,b,c)` to generate replacement circuits.
:param gateset: the allowed operations in the rebased circuit (in addition, Measure, Reset and Collapse operations are always allowed and are left alone; conditional operations may be present; and Phase gates may also be introduced by the rebase)
Expand All @@ -509,7 +509,7 @@ def RebaseCustom(gateset: set[pytket._tket.circuit.OpType], cx_replacement: pytk
:return: a pass that rebases to the given gate set (possibly including conditional and phase operations, and Measure, Reset and Collapse)
"""
@typing.overload
def RebaseCustom(gateset: set[pytket._tket.circuit.OpType], tk2_replacement: typing.Callable[[typing.Union[sympy.Expr, float], typing.Union[sympy.Expr, float], typing.Union[sympy.Expr, float]], pytket._tket.circuit.Circuit], tk1_replacement: typing.Callable[[typing.Union[sympy.Expr, float], typing.Union[sympy.Expr, float], typing.Union[sympy.Expr, float]], pytket._tket.circuit.Circuit]) -> BasePass:
def RebaseCustom(gateset: set[pytket._tket.circuit.OpType], tk2_replacement: typing.Callable[[sympy.Expr | float, sympy.Expr | float, sympy.Expr | float], pytket._tket.circuit.Circuit], tk1_replacement: typing.Callable[[sympy.Expr | float, sympy.Expr | float, sympy.Expr | float], pytket._tket.circuit.Circuit]) -> BasePass:
"""
Construct a custom rebase pass, given user-defined rebases for TK1 and TK2. This pass:
Expand Down Expand Up @@ -555,10 +555,10 @@ def RenameQubitsPass(qubit_map: dict[pytket._tket.unit_id.Qubit, pytket._tket.un
"""
def RoundAngles(n: int, only_zeros: bool = False) -> BasePass:
"""
Round angles to the nearest :math:`\pi / 2^n`.
Round angles to the nearest :math:`\\pi / 2^n`.
:param n: precision parameter, must be >= 0 and < 32
:param only_zeros: if True, only round angles less than :math:`\pi / 2^{n+1}` to zero, leave other angles alone (default False)
:param only_zeros: if True, only round angles less than :math:`\\pi / 2^{n+1}` to zero, leave other angles alone (default False)
"""
def RoutingPass(arc: pytket._tket.architecture.Architecture) -> BasePass:
"""
Expand All @@ -580,7 +580,7 @@ def SimplifyMeasured() -> BasePass:
"""
A pass to replace all 'classical maps' followed by measure operations whose quantum output is discarded with classical operations following the measure. (A 'classical map' is a quantum operation that acts as a permutation of the computational basis states followed by a diagonal operation.)
"""
def SquashCustom(singleqs: set[pytket._tket.circuit.OpType], tk1_replacement: typing.Callable[[typing.Union[sympy.Expr, float], typing.Union[sympy.Expr, float], typing.Union[sympy.Expr, float]], pytket._tket.circuit.Circuit], always_squash_symbols: bool = False) -> BasePass:
def SquashCustom(singleqs: set[pytket._tket.circuit.OpType], tk1_replacement: typing.Callable[[sympy.Expr | float, sympy.Expr | float, sympy.Expr | float], pytket._tket.circuit.Circuit], always_squash_symbols: bool = False) -> BasePass:
"""
Squash sequences of single qubit gates from the target gate set into an optimal form given by `tk1_replacement`.
Expand Down
12 changes: 6 additions & 6 deletions pytket/pytket/_tket/pauli.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -176,22 +176,22 @@ class QubitPauliString:
:return: a list of :py:class:`Qubit`-to-:py:class:`Pauli` entries, represented as dicts.
"""
@typing.overload
def to_sparse_matrix(self) -> scipy.sparse.csc_matrix[numpy.complex128]:
def to_sparse_matrix(self) -> scipy.sparse.csc_matrix:
"""
Represents the sparse string as a dense string (without padding for extra qubits) and generates the matrix for the tensor. Uses the ILO-BE convention, so ``Qubit("a", 0)`` is more significant that ``Qubit("a", 1)`` and ``Qubit("b")`` for indexing into the matrix.
:return: a sparse matrix corresponding to the operator
"""
@typing.overload
def to_sparse_matrix(self, n_qubits: int) -> scipy.sparse.csc_matrix[numpy.complex128]:
def to_sparse_matrix(self, n_qubits: int) -> scipy.sparse.csc_matrix:
"""
Represents the sparse string as a dense string over `n_qubits` qubits (sequentially indexed from 0 in the default register) and generates the matrix for the tensor. Uses the ILO-BE convention, so ``Qubit(0)`` is the most significant bit for indexing into the matrix.
:param n_qubits: the number of qubits in the full operator
:return: a sparse matrix corresponding to the operator
"""
@typing.overload
def to_sparse_matrix(self, qubits: typing.Sequence[pytket._tket.unit_id.Qubit]) -> scipy.sparse.csc_matrix[numpy.complex128]:
def to_sparse_matrix(self, qubits: typing.Sequence[pytket._tket.unit_id.Qubit]) -> scipy.sparse.csc_matrix:
"""
Represents the sparse string as a dense string and generates the matrix for the tensor. Orders qubits according to `qubits` (padding with identities if they are not in the sparse string), so ``qubits[0]`` is the most significant bit for indexing into the matrix.
Expand Down Expand Up @@ -297,22 +297,22 @@ class QubitPauliTensor:
:return: expectation value with respect to state
"""
@typing.overload
def to_sparse_matrix(self) -> scipy.sparse.csc_matrix[numpy.complex128]:
def to_sparse_matrix(self) -> scipy.sparse.csc_matrix:
"""
Represents the sparse string as a dense string (without padding for extra qubits) and generates the matrix for the tensor. Uses the ILO-BE convention, so ``Qubit("a", 0)`` is more significant that ``Qubit("a", 1)`` and ``Qubit("b")`` for indexing into the matrix.
:return: a sparse matrix corresponding to the tensor
"""
@typing.overload
def to_sparse_matrix(self, n_qubits: int) -> scipy.sparse.csc_matrix[numpy.complex128]:
def to_sparse_matrix(self, n_qubits: int) -> scipy.sparse.csc_matrix:
"""
Represents the sparse string as a dense string over `n_qubits` qubits (sequentially indexed from 0 in the default register) and generates the matrix for the tensor. Uses the ILO-BE convention, so ``Qubit(0)`` is the most significant bit for indexing into the matrix.
:param n_qubits: the number of qubits in the full operator
:return: a sparse matrix corresponding to the operator
"""
@typing.overload
def to_sparse_matrix(self, qubits: typing.Sequence[pytket._tket.unit_id.Qubit]) -> scipy.sparse.csc_matrix[numpy.complex128]:
def to_sparse_matrix(self, qubits: typing.Sequence[pytket._tket.unit_id.Qubit]) -> scipy.sparse.csc_matrix:
"""
Represents the sparse string as a dense string and generates the matrix for the tensor. Orders qubits according to `qubits` (padding with identities if they are not in the sparse string), so ``qubits[0]`` is the most significant bit for indexing into the matrix.
Expand Down
6 changes: 3 additions & 3 deletions pytket/pytket/_tket/placement.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class GraphPlacement(Placement):
:param maximum_pattern_gates: The upper bound on the number of circuit gates used to construct the pattern graph for finding subgraph monomorphisms.
:param maximum_pattern_depth: The upper bound on the circuit depth gates are added to the pattern graph to for finding subgraph monomorphisms.
"""
def __repr__(self) -> str:
def __repr__(self: Placement) -> str:
...
def modify_config(self, **kwargs: Any) -> None:
"""
Expand All @@ -37,7 +37,7 @@ class LinePlacement(Placement):
:param maximum_line_gates: maximum number of gates in the circuit considered when constructing lines for assigning to the graph
:param maximum_line_depth: maximum depth of circuit considered when constructing lines for assigning to the graph
"""
def __repr__(self) -> str:
def __repr__(self: Placement) -> str:
...
class NoiseAwarePlacement(Placement):
"""
Expand All @@ -56,7 +56,7 @@ class NoiseAwarePlacement(Placement):
:param maximum_pattern_gates: The upper bound on the number of circuit gates used to construct the pattern graph for finding subgraph monomorphisms.
:param maximum_pattern_depth: The upper bound on the circuit depth gates are added to the pattern graph to for finding subgraph monomorphisms.
"""
def __repr__(self) -> str:
def __repr__(self: Placement) -> str:
...
def modify_config(self, **kwargs: Any) -> None:
"""
Expand Down
2 changes: 1 addition & 1 deletion pytket/pytket/_tket/transform.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ class Transform:
@staticmethod
def round_angles(n: int, only_zeros: bool = False) -> Transform:
"""
:param only_zeros: if True, only round angles less than :math:`\pi / 2^{n+1}` to zero, leave other angles alone (default False)
:param only_zeros: if True, only round angles less than :math:`\\pi / 2^{n+1}` to zero, leave other angles alone (default False)
"""
@staticmethod
def sequence(sequence: typing.Sequence[Transform]) -> Transform:
Expand Down
Loading

0 comments on commit cce17c7

Please sign in to comment.