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 justfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
uvrun := "uv run"
uvrun := "uv run --all-extras"

default:
@just --list
Expand Down
10 changes: 10 additions & 0 deletions tierkreis/tierkreis/builtins/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,5 +169,15 @@ def tkr_sleep(delay_seconds: float) -> bool:
return True


@worker.task()
def tkr_encode(string: str) -> bytes:
return string.encode()


@worker.task()
def tkr_decode(bytes: bytes) -> str:
return bytes.decode()


if __name__ == "__main__":
worker.app(argv)
24 changes: 24 additions & 0 deletions tierkreis/tierkreis/builtins/stubs.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,3 +270,27 @@ def out() -> type[TKR[bool]]: # noqa: F821 # fmt: skip
@property
def namespace(self) -> str:
return "builtins"


class tkr_encode(NamedTuple):
string: TKR[str] # noqa: F821 # fmt: skip

@staticmethod
def out() -> type[TKR[bytes]]: # noqa: F821 # fmt: skip
return TKR[bytes] # noqa: F821 # fmt: skip

@property
def namespace(self) -> str:
return "builtins"


class tkr_decode(NamedTuple):
bytes: TKR[bytes] # noqa: F821 # fmt: skip

@staticmethod
def out() -> type[TKR[str]]: # noqa: F821 # fmt: skip
return TKR[str] # noqa: F821 # fmt: skip

@property
def namespace(self) -> str:
return "builtins"
7 changes: 5 additions & 2 deletions tierkreis/tierkreis/controller/executor/shell_executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,14 @@ class ShellExecutor:
Implements: :py:class:`tierkreis.controller.executor.protocol.ControllerExecutor`
"""

def __init__(self, registry_path: Path, workflow_dir: Path) -> None:
def __init__(
self, registry_path: Path, workflow_dir: Path, timeout: int = 10
) -> None:
self.launchers_path = registry_path
self.logs_path = workflow_dir / "logs"
self.errors_path = workflow_dir / "logs"
self.workflow_dir = workflow_dir
self.timeout = timeout
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this still required now that we background the command?


def run(
self,
Expand Down Expand Up @@ -61,7 +64,7 @@ def run(
)
proc.communicate(
f"({launcher_path} {worker_call_args_path} && touch {done_path}|| touch {_error_path})&".encode(),
timeout=10,
timeout=self.timeout,
)

def _create_env(
Expand Down
12 changes: 12 additions & 0 deletions tierkreis/tierkreis/pytket_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,3 +211,15 @@ def out() -> type[TKR[float]]: # noqa: F821 # fmt: skip
@property
def namespace(self) -> str:
return "pytket_worker"


class n_qubits(NamedTuple):
circuit: TKR[OpaqueType["pytket._tket.circuit.Circuit"]] # noqa: F821 # fmt: skip

@staticmethod
def out() -> type[TKR[int]]: # noqa: F821 # fmt: skip
return TKR[int] # noqa: F821 # fmt: skip

@property
def namespace(self) -> str:
return "pytket_worker"
10 changes: 8 additions & 2 deletions tierkreis_workers/pytket_worker/compile_circuit.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@
)
from pytket.placement import GraphPlacement
from pytket.qasm.qasm import circuit_from_qasm_str, circuit_to_qasm_str
from pytket.qir.conversion.api import pytket_to_qir
from pytket_qirpass import qir_to_pytket
from tierkreis.exceptions import TierkreisError


Expand Down Expand Up @@ -100,6 +98,10 @@ def compile_circuit(
raise TierkreisError("Invalid combination of input type and format.")
if isinstance(circuit, bytes):
if input_format == CircuitFormat.QIR:
try:
from pytket_qirpass import qir_to_pytket
except ModuleNotFoundError:
raise TierkreisError("Could not resolve pytket_qirpass")
circuit = qir_to_pytket(circuit)
else:
raise TierkreisError("Invalid combination of input type and format.")
Expand All @@ -124,6 +126,10 @@ def compile_circuit(
case CircuitFormat.QASM2:
return circuit_to_qasm_str(circuit)
case CircuitFormat.QIR:
try:
from pytket.qir.conversion.api import pytket_to_qir
except ModuleNotFoundError:
raise TierkreisError("Could not resolve pytket_qirpass")
ret = pytket_to_qir(circuit)
if ret is None:
raise TierkreisError("Could not transform circuit to QIR.")
Expand Down
6 changes: 5 additions & 1 deletion tierkreis_workers/pytket_worker/default_pass.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from pytket.passes.resizeregpass import scratch_reg_resize_pass
from pytket.circuit import OpType
from pytket.extensions.qiskit.backends.ibm import IBMQBackend
from pytket.extensions.quantinuum.backends.quantinuum import QuantinuumBackend
from tierkreis.exceptions import TierkreisError


def _gate_set() -> set[OpType]:
Expand Down Expand Up @@ -106,5 +106,9 @@ def default_compilation_pass_ibm(
def default_compilation_pass_quantinuum(
backend_name: str, optimization_level: int = 2
) -> BasePass:
try:
from pytket.extensions.quantinuum.backends.quantinuum import QuantinuumBackend
except ModuleNotFoundError:
raise TierkreisError("Cannot import Quantinuum Backend")
backend = QuantinuumBackend(backend_name)
return backend.default_compilation_pass(optimization_level)
22 changes: 20 additions & 2 deletions tierkreis_workers/pytket_worker/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,9 @@
from pytket.passes import BasePass
from pytket.pauli import QubitPauliString
from pytket.qasm.qasm import circuit_from_qasm_str, circuit_to_qasm_str
from pytket.qir.conversion.api import pytket_to_qir
from pytket.transform import Transform
from pytket.utils.expectations import expectation_from_counts
from pytket.utils.measurements import append_pauli_measurement
from pytket_qirpass import qir_to_pytket
from tierkreis.exceptions import TierkreisError

from tierkreis import Worker
Expand Down Expand Up @@ -318,6 +316,10 @@ def to_qir_bytes(circuit: Circuit) -> bytes:
:return: The circuit as QIR bytecode.
:rtype: bytes
"""
try:
from pytket.qir.conversion.api import pytket_to_qir
except ModuleNotFoundError:
raise TierkreisError("Could not resolve pytket.qir")
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm... do we specifically handle TierkreisError somewhere? If not then I wonder how much information this error message is adding?

ret = pytket_to_qir(circuit)
if not isinstance(ret, bytes):
raise TierkreisError("Error when converting Circuit to QIR.")
Expand All @@ -333,6 +335,10 @@ def from_qir_bytes(qir: bytes) -> Circuit:
:return: The corresponding pytket circuit.
:rtype: Circuit
"""
try:
from pytket_qirpass import qir_to_pytket
except ModuleNotFoundError:
raise TierkreisError("Could not resolve pytket_qirpass")
return qir_to_pytket(qir)


Expand All @@ -349,6 +355,18 @@ def expectation(backend_result: BackendResult) -> float:
return expectation


@worker.task()
def n_qubits(circuit: Circuit) -> int:
"""Wrapper for pytket.Circuit.n_qubits.

:param circuit: The pytket circuit.
:type circuit: Circuit
:return: The number of qubits in that circuit.
:rtype: int
"""
return circuit.n_qubits


def main():
worker.app(argv)

Expand Down
5 changes: 5 additions & 0 deletions tierkreis_workers/pytket_worker/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ dependencies = [
"tierkreis",
"pytket",
"pytket-qiskit",
]

[project.optional-dependencies]
#Some wheels for pyqir are restricted in their arch
qir = [
"pytket-quantinuum",
"pytket-qir",
"pytket-qirpass",
Expand Down
12 changes: 12 additions & 0 deletions tierkreis_workers/pytket_worker/stubs.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,3 +211,15 @@ def out() -> type[TKR[float]]: # noqa: F821 # fmt: skip
@property
def namespace(self) -> str:
return "pytket_worker"


class n_qubits(NamedTuple):
circuit: TKR[OpaqueType["pytket._tket.circuit.Circuit"]] # noqa: F821 # fmt: skip

@staticmethod
def out() -> type[TKR[int]]: # noqa: F821 # fmt: skip
return TKR[int] # noqa: F821 # fmt: skip

@property
def namespace(self) -> str:
return "pytket_worker"
Loading