-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add missing typing hints (#352)
Adds typing info for the currently binded classes and methods. Also binds a couple classes that where missing. Fixes #342.
- Loading branch information
Showing
10 changed files
with
331 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
from .circuit import Tk2Circuit | ||
from pytket._tket.circuit import Circuit | ||
|
||
from pathlib import Path | ||
|
||
class BadgerOptimiser: | ||
@staticmethod | ||
def load_precompiled(filename: Path) -> BadgerOptimiser: | ||
"""Load a precompiled rewriter from a file.""" | ||
|
||
@staticmethod | ||
def compile_eccs(filename: Path) -> BadgerOptimiser: | ||
"""Compile a set of ECCs and create a new rewriter .""" | ||
|
||
def optimise( | ||
self, | ||
circ: Tk2Circuit | Circuit, | ||
timeout: int | None = None, | ||
progress_timeout: int | None = None, | ||
n_threads: int | None = None, | ||
split_circ: bool = False, | ||
queue_size: int | None = None, | ||
log_progress: Path | None = None, | ||
) -> Tk2Circuit | Circuit: | ||
"""Optimise a circuit. | ||
:param circ: The circuit to optimise. | ||
:param timeout: Maximum time to spend on the optimisation. | ||
:param progress_timeout: Maximum time to wait between new best results. | ||
:param n_threads: Number of threads to use. | ||
:param split_circ: Split the circuit into subcircuits and optimise them separately. | ||
:param queue_size: Maximum number of circuits to keep in the queue of candidates. | ||
:param log_progress: Log progress to a CSV file. | ||
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
from pathlib import Path | ||
|
||
from .optimiser import BadgerOptimiser | ||
from .circuit import Tk2Circuit | ||
from pytket._tket.circuit import Circuit | ||
|
||
class CircuitChunks: | ||
def reassemble(self) -> Circuit | Tk2Circuit: | ||
"""Reassemble the circuit from its chunks.""" | ||
|
||
def circuits(self) -> list[Circuit | Tk2Circuit]: | ||
"""Returns clones of the split circuits.""" | ||
|
||
def update_circuit(self, index: int, circ: Circuit | Tk2Circuit) -> None: | ||
"""Replace a circuit chunk with a new version.""" | ||
|
||
class PullForwardError(Exception): | ||
"""Error from a `PullForward` operation.""" | ||
|
||
def greedy_depth_reduce(circ: Circuit | Tk2Circuit) -> tuple[Circuit | Tk2Circuit, int]: | ||
"""Greedy depth reduction of a circuit. | ||
Returns the reduced circuit and the depth reduction. | ||
""" | ||
|
||
def badger_optimise( | ||
circ: Circuit | Tk2Circuit, | ||
optimiser: BadgerOptimiser, | ||
max_threads: int | None = None, | ||
timeout: int | None = None, | ||
progress_timeout: int | None = None, | ||
log_dir: Path | None = None, | ||
rebase: bool = False, | ||
) -> Circuit | Tk2Circuit: | ||
"""Optimise a circuit using the Badger optimiser. | ||
HyperTKET's best attempt at optimising a circuit using circuit rewriting | ||
and the given Badger optimiser. | ||
By default, the input circuit will be rebased to Nam, i.e. CX + Rz + H before | ||
optimising. This can be deactivated by setting `rebase` to `false`, in which | ||
case the circuit is expected to be in the Nam gate set. | ||
Will use at most `max_threads` threads (plus a constant) and take at most | ||
`timeout` seconds (plus a constant). Default to the number of cpus and | ||
15min respectively. | ||
Log files will be written to the directory `log_dir` if specified. | ||
""" | ||
|
||
def chunks(c: Circuit | Tk2Circuit, max_chunk_size: int) -> CircuitChunks: | ||
"""Split a circuit into chunks of at most `max_chunk_size` gates.""" |
Oops, something went wrong.