diff --git a/docs/source/examples/example_workers/qsci_worker/api/api.py b/docs/source/examples/example_workers/qsci_worker/api/api.py index 6afcb8136..2dd8a7ad8 100644 --- a/docs/source/examples/example_workers/qsci_worker/api/api.py +++ b/docs/source/examples/example_workers/qsci_worker/api/api.py @@ -1,9 +1,12 @@ """Code generated from qsci_worker namespace. Please do not edit.""" -from typing import NamedTuple, Protocol -from tierkreis.controller.data.models import TKR, OpaqueType +from typing import Literal, NamedTuple, Protocol +from tierkreis.controller.data.models import TKR from tierkreis.controller.data.types import Struct +type Circuit = Literal["pytket._tket.circuit.Circuit"] +type BackendResult = Literal["pytket.backends.backendresult.BackendResult"] + class CompleteActiveSpace(Struct, Protocol): n: int # noqa: F821 # fmt: skip @@ -32,8 +35,8 @@ class state_prep(NamedTuple): cas_hsim: TKR[CompleteActiveSpace] # noqa: F821 # fmt: skip @staticmethod - def out() -> type[TKR[OpaqueType["pytket._tket.circuit.Circuit"]]]: # noqa: F821 # fmt: skip - return TKR[OpaqueType["pytket._tket.circuit.Circuit"]] # noqa: F821 # fmt: skip + def out() -> type[TKR[Circuit]]: # noqa: F821 # fmt: skip + return TKR[Circuit] # noqa: F821 # fmt: skip @property def namespace(self) -> str: @@ -43,7 +46,7 @@ def namespace(self) -> str: class circuits_from_hamiltonians(NamedTuple): ham_init: TKR[Hamiltonian] # noqa: F821 # fmt: skip ham_hsim: TKR[Hamiltonian] # noqa: F821 # fmt: skip - adapt_circuit: TKR[OpaqueType["pytket._tket.circuit.Circuit"]] # noqa: F821 # fmt: skip + adapt_circuit: TKR[Circuit] # noqa: F821 # fmt: skip t_step_list: TKR[list[float]] # noqa: F821 # fmt: skip cas_init: TKR[CompleteActiveSpace] # noqa: F821 # fmt: skip cas_hsim: TKR[CompleteActiveSpace] # noqa: F821 # fmt: skip @@ -51,8 +54,8 @@ class circuits_from_hamiltonians(NamedTuple): max_cx_gates: TKR[int] # noqa: F821 # fmt: skip @staticmethod - def out() -> type[TKR[list[OpaqueType["pytket._tket.circuit.Circuit"]]]]: # noqa: F821 # fmt: skip - return TKR[list[OpaqueType["pytket._tket.circuit.Circuit"]]] # noqa: F821 # fmt: skip + def out() -> type[TKR[list[Circuit]]]: # noqa: F821 # fmt: skip + return TKR[list[Circuit]] # noqa: F821 # fmt: skip @property def namespace(self) -> str: @@ -61,7 +64,7 @@ def namespace(self) -> str: class energy_from_results(NamedTuple): ham_hsim: TKR[Hamiltonian] # noqa: F821 # fmt: skip - backend_results: TKR[list[OpaqueType["pytket.backends.backendresult.BackendResult"]]] # noqa: F821 # fmt: skip + backend_results: TKR[list[BackendResult]] # noqa: F821 # fmt: skip mo_occ: TKR[list[int]] # noqa: F821 # fmt: skip cas_init: TKR[CompleteActiveSpace] # noqa: F821 # fmt: skip cas_hsim: TKR[CompleteActiveSpace] # noqa: F821 # fmt: skip diff --git a/docs/source/examples/example_workers/scipy_worker/api/api.py b/docs/source/examples/example_workers/scipy_worker/api/api.py index b8abe1959..0bb6c6f70 100644 --- a/docs/source/examples/example_workers/scipy_worker/api/api.py +++ b/docs/source/examples/example_workers/scipy_worker/api/api.py @@ -1,17 +1,19 @@ """Code generated from scipy_worker namespace. Please do not edit.""" -from typing import NamedTuple, Protocol, Union -from tierkreis.controller.data.models import TKR, OpaqueType +from typing import Literal, NamedTuple, Protocol, Union +from tierkreis.controller.data.models import TKR from tierkreis.controller.data.types import Struct +type ndarray = Literal["numpy.ndarray"] + class PointedArray(Struct, Protocol): - a: OpaqueType["numpy.ndarray"] # noqa: F821 # fmt: skip + a: ndarray # noqa: F821 # fmt: skip p: int # noqa: F821 # fmt: skip class add_point(NamedTuple): - a: TKR[OpaqueType["numpy.ndarray"]] # noqa: F821 # fmt: skip + a: TKR[ndarray] # noqa: F821 # fmt: skip p: TKR[int] # noqa: F821 # fmt: skip @staticmethod @@ -41,8 +43,8 @@ class linspace(NamedTuple): num: TKR[int] | None = None # noqa: F821 # fmt: skip @staticmethod - def out() -> type[TKR[OpaqueType["numpy.ndarray"]]]: # noqa: F821 # fmt: skip - return TKR[OpaqueType["numpy.ndarray"]] # noqa: F821 # fmt: skip + def out() -> type[TKR[ndarray]]: # noqa: F821 # fmt: skip + return TKR[ndarray] # noqa: F821 # fmt: skip @property def namespace(self) -> str: @@ -50,11 +52,11 @@ def namespace(self) -> str: class transpose(NamedTuple): - a: TKR[OpaqueType["numpy.ndarray"]] # noqa: F821 # fmt: skip + a: TKR[ndarray] # noqa: F821 # fmt: skip @staticmethod - def out() -> type[TKR[OpaqueType["numpy.ndarray"]]]: # noqa: F821 # fmt: skip - return TKR[OpaqueType["numpy.ndarray"]] # noqa: F821 # fmt: skip + def out() -> type[TKR[ndarray]]: # noqa: F821 # fmt: skip + return TKR[ndarray] # noqa: F821 # fmt: skip @property def namespace(self) -> str: @@ -62,12 +64,12 @@ def namespace(self) -> str: class reshape(NamedTuple): - a: TKR[OpaqueType["numpy.ndarray"]] # noqa: F821 # fmt: skip + a: TKR[ndarray] # noqa: F821 # fmt: skip shape: TKR[Union[int, list[int]]] # noqa: F821 # fmt: skip @staticmethod - def out() -> type[TKR[OpaqueType["numpy.ndarray"]]]: # noqa: F821 # fmt: skip - return TKR[OpaqueType["numpy.ndarray"]] # noqa: F821 # fmt: skip + def out() -> type[TKR[ndarray]]: # noqa: F821 # fmt: skip + return TKR[ndarray] # noqa: F821 # fmt: skip @property def namespace(self) -> str: diff --git a/docs/source/examples/example_workers/substitution_worker/api/api.py b/docs/source/examples/example_workers/substitution_worker/api/api.py index 3d9801f3f..c54850067 100644 --- a/docs/source/examples/example_workers/substitution_worker/api/api.py +++ b/docs/source/examples/example_workers/substitution_worker/api/api.py @@ -1,18 +1,20 @@ """Code generated from substitution_worker namespace. Please do not edit.""" -from typing import NamedTuple -from tierkreis.controller.data.models import TKR, OpaqueType +from typing import Literal, NamedTuple +from tierkreis.controller.data.models import TKR + +type Circuit = Literal["pytket._tket.circuit.Circuit"] class substitute(NamedTuple): - circuit: TKR[OpaqueType["pytket._tket.circuit.Circuit"]] # noqa: F821 # fmt: skip + circuit: TKR[Circuit] # noqa: F821 # fmt: skip a: TKR[float] # noqa: F821 # fmt: skip b: TKR[float] # noqa: F821 # fmt: skip c: TKR[float] # noqa: F821 # fmt: skip @staticmethod - def out() -> type[TKR[OpaqueType["pytket._tket.circuit.Circuit"]]]: # noqa: F821 # fmt: skip - return TKR[OpaqueType["pytket._tket.circuit.Circuit"]] # noqa: F821 # fmt: skip + def out() -> type[TKR[Circuit]]: # noqa: F821 # fmt: skip + return TKR[Circuit] # noqa: F821 # fmt: skip @property def namespace(self) -> str: diff --git a/docs/source/examples/hamiltonian.ipynb b/docs/source/examples/hamiltonian.ipynb index 177d13f5a..7abcc86fc 100644 --- a/docs/source/examples/hamiltonian.ipynb +++ b/docs/source/examples/hamiltonian.ipynb @@ -1,376 +1,377 @@ { - "cells": [ - { - "cell_type": "markdown", - "id": "d56e6c6d", - "metadata": {}, - "source": [ - "# Hamiltonian Simulation\n", - "\n", - "In this example we're going to apply the previously learned concept to run a hamiltonian simulation.\n", - "As before we are going to define a symbolic circuit as an ansatz." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "3563e447", - "metadata": {}, - "outputs": [], - "source": [ - "%pip install tierkreis pytket" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "bfbaa4df", - "metadata": {}, - "outputs": [], - "source": [ - "from pytket._tket.circuit import Circuit, fresh_symbol\n", - "\n", - "\n", - "def build_ansatz() -> Circuit:\n", - " a = fresh_symbol(\"a\")\n", - " b = fresh_symbol(\"b\")\n", - " c = fresh_symbol(\"c\")\n", - " circ = Circuit(4)\n", - " circ.CX(0, 1)\n", - " circ.CX(1, 2)\n", - " circ.CX(2, 3)\n", - " circ.Rz(a, 3)\n", - " circ.CX(2, 3)\n", - " circ.CX(1, 2)\n", - " circ.CX(0, 1)\n", - " circ.Rz(b, 0)\n", - " circ.CX(0, 1)\n", - " circ.CX(1, 2)\n", - " circ.CX(2, 3)\n", - " circ.Rz(c, 3)\n", - " circ.CX(2, 3)\n", - " circ.CX(1, 2)\n", - " circ.CX(0, 1)\n", - " return circ" - ] - }, - { - "cell_type": "markdown", - "id": "d1993864", - "metadata": {}, - "source": [ - "We are going to simulate a hamiltonian given as a list of Pauli strings and their weights.\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "f5d2e7be", - "metadata": {}, - "outputs": [], - "source": [ - "from tierkreis.builder import GraphBuilder\n", - "from tierkreis.controller.data.models import TKR\n", - "from typing import NamedTuple, Literal\n", - "\n", - "from substitution_worker import substitute\n", - "\n", - "\n", - "class SymbolicExecutionInputs(NamedTuple):\n", - " a: TKR[float]\n", - " b: TKR[float]\n", - " c: TKR[float]\n", - " ham: TKR[list[tuple[Literal[\"pytket._tket.pauli.QubitPauliString\"], float]]]\n", - " ansatz: TKR[Literal[\"pytket._tket.circuit.Circuit\"]]\n", - "\n", - "\n", - "simulation_graph = GraphBuilder(SymbolicExecutionInputs, TKR[float])\n", - "substituted_circuit = simulation_graph.task(\n", - " substitute(\n", - " simulation_graph.inputs.ansatz,\n", - " simulation_graph.inputs.a,\n", - " simulation_graph.inputs.b,\n", - " simulation_graph.inputs.c,\n", - " )\n", - ")" - ] - }, - { - "cell_type": "markdown", - "id": "161a5e02", - "metadata": {}, - "source": [ - "We will evaluate this circuit with an observable based on a Pauli string" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "39b21062", - "metadata": {}, - "outputs": [], - "source": [ - "from tierkreis.pytket_worker import (\n", - " append_pauli_measurement_impl,\n", - " optimise_phase_gadgets,\n", - " expectation,\n", - ")\n", - "from tierkreis.aer_worker import submit_single\n", - "\n", - "\n", - "class SubmitInputs(NamedTuple):\n", - " circuit: TKR[Literal[\"pytket._tket.circuit.Circuit\"]]\n", - " pauli_string: TKR[Literal[\"pytket._tket.pauli.QubitPauliString\"]]\n", - " n_shots: TKR[int]\n", - "\n", - "\n", - "def exp_val():\n", - " g = GraphBuilder(SubmitInputs, TKR[float])\n", - "\n", - " circuit = g.inputs.circuit\n", - " pauli_string = g.inputs.pauli_string\n", - " n_shots = g.inputs.n_shots\n", - "\n", - " measurement_circuit = g.task(append_pauli_measurement_impl(circuit, pauli_string))\n", - "\n", - " compiled_circuit = g.task(optimise_phase_gadgets(measurement_circuit))\n", - "\n", - " backend_result = g.task(submit_single(compiled_circuit, n_shots))\n", - " av = g.task(expectation(backend_result))\n", - " g.outputs(av)\n", - " return g" - ] - }, - { - "cell_type": "markdown", - "id": "c7f5f9a1", - "metadata": {}, - "source": [ - "Since `exp_val` runs independently for each Pauli string we can implement this using a map, \n", - "but we need to prepare the inputs first." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "021e0e5b", - "metadata": {}, - "outputs": [], - "source": [ - "from tierkreis.builtins import unzip\n", - "from tierkreis.controller.data.models import TKR\n", - "\n", - "pauli_strings_list, parameters_list = simulation_graph.task(\n", - " unzip(simulation_graph.inputs.ham)\n", - ")\n", - "input_circuits = simulation_graph.map(\n", - " lambda x: SubmitInputs(substituted_circuit, x, simulation_graph.const(100)),\n", - " pauli_strings_list,\n", - ")\n", - "exp_values = simulation_graph.map(exp_val(), input_circuits)" - ] - }, - { - "cell_type": "markdown", - "id": "7788777e", - "metadata": {}, - "source": [ - "To estimate the energy, we can take a weighted sum of the expectation values.\n", - "For this we want to compute a reduction (\\(x,y) \\z --> x*y+z) which we implement as a fold function." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "cd24e08c", - "metadata": {}, - "outputs": [], - "source": [ - "from tierkreis.builtins import add, times, untuple\n", - "from tierkreis.graphs.fold import FoldFunctionInput\n", - "\n", - "ComputeTermsInputs = FoldFunctionInput[\n", - " tuple[float, float], float\n", - "] # (value, accum) -> new_accum\n", - "\n", - "\n", - "def compute_terms():\n", - " g = GraphBuilder(ComputeTermsInputs, TKR[float])\n", - "\n", - " res_0, res_1 = g.task(untuple(g.inputs.value))\n", - " prod = g.task(times(res_0, res_1))\n", - " sum = g.task(add(g.inputs.accum, prod))\n", - "\n", - " g.outputs(sum)\n", - " return g" - ] - }, - { - "cell_type": "markdown", - "id": "af57c8ac", - "metadata": {}, - "source": [ - "Preparing the inputs for the fold graph we are going to use tuples (x=exp_val, y=weight) and defining the start value z=0." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "9bab0de3", - "metadata": {}, - "outputs": [], - "source": [ - "from tierkreis.builtins import tkr_zip\n", - "from tierkreis.graphs.fold import FoldGraphInputs, fold_graph\n", - "\n", - "tuple_values = simulation_graph.task(tkr_zip(exp_values, parameters_list))\n", - "fold_inputs = FoldGraphInputs(simulation_graph.const(0.0), tuple_values)" - ] - }, - { - "cell_type": "markdown", - "id": "da997ea2", - "metadata": {}, - "source": [ - "applying the fold operation yields the final output" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "d7c6fa18", - "metadata": {}, - "outputs": [], - "source": [ - "computed = simulation_graph.eval(fold_graph(compute_terms()), fold_inputs)\n", - "simulation_graph.outputs(computed)" - ] - }, - { - "cell_type": "markdown", - "id": "5999c0a5", - "metadata": {}, - "source": [ - "As before we now have to set up tierkreis storage and executors" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "aec32e19", - "metadata": {}, - "outputs": [], - "source": [ - "from pathlib import Path\n", - "from uuid import UUID\n", - "\n", - "from tierkreis.consts import PACKAGE_PATH\n", - "from tierkreis.controller.executor.multiple import MultipleExecutor\n", - "from tierkreis.storage import FileStorage\n", - "from tierkreis.controller.executor.uv_executor import UvExecutor\n", - "\n", - "storage = FileStorage(UUID(int=102), name=\"hamiltonian\")\n", - "example_executor = UvExecutor(\n", - " registry_path=Path().parent / \"example_workers\", logs_path=storage.logs_path\n", - ")\n", - "common_executor = UvExecutor(\n", - " registry_path=PACKAGE_PATH.parent / \"tierkreis_workers\", logs_path=storage.logs_path\n", - ")\n", - "multi_executor = MultipleExecutor(\n", - " common_executor,\n", - " executors={\"custom\": example_executor},\n", - " assignments={\"substitution_worker\": \"custom\"},\n", - ")" - ] - }, - { - "cell_type": "markdown", - "id": "20848215", - "metadata": {}, - "source": [ - "and provide the inputs" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "2d3b86c0", - "metadata": {}, - "outputs": [], - "source": [ - "from pytket._tket.unit_id import Qubit\n", - "from pytket.pauli import Pauli, QubitPauliString\n", - "\n", - "qubits = [Qubit(0), Qubit(1), Qubit(2), Qubit(3)]\n", - "hamiltonian = [\n", - " (QubitPauliString(qubits, [Pauli.X, Pauli.Y, Pauli.X, Pauli.I]).to_list(), 0.1),\n", - " (QubitPauliString(qubits, [Pauli.Y, Pauli.Z, Pauli.X, Pauli.Z]).to_list(), 0.5),\n", - " (QubitPauliString(qubits, [Pauli.X, Pauli.Y, Pauli.Z, Pauli.I]).to_list(), 0.3),\n", - " (QubitPauliString(qubits, [Pauli.Z, Pauli.Y, Pauli.X, Pauli.Y]).to_list(), 0.6),\n", - "]\n", - "inputs = {\n", - " \"ansatz\": build_ansatz().to_dict(),\n", - " \"a\": 0.2,\n", - " \"b\": 0.55,\n", - " \"c\": 0.75,\n", - " \"ham\": hamiltonian,\n", - "}" - ] - }, - { - "cell_type": "markdown", - "id": "037d98b1", - "metadata": {}, - "source": [ - "before we can run the simulation:" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "53446615", - "metadata": {}, - "outputs": [], - "source": [ - "from tierkreis.controller import run_graph\n", - "from tierkreis.storage import read_outputs\n", - "\n", - "\n", - "storage.clean_graph_files()\n", - "run_graph(\n", - " storage,\n", - " multi_executor,\n", - " simulation_graph,\n", - " inputs,\n", - " polling_interval_seconds=0.2,\n", - ")\n", - "output = read_outputs(simulation_graph, storage)\n", - "print(output)" - ] - } - ], - "metadata": { - "execution": { - "timeout": -1 - }, - "kernelspec": { - "display_name": "Python 3", - "language": "python", - "name": "python3" - }, - "language_info": { - "codemirror_mode": { - "name": "ipython", - "version": 3 - }, - "file_extension": ".py", - "mimetype": "text/x-python", - "name": "python", - "nbconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": "3.13.11" - } + "cells": [ + { + "cell_type": "markdown", + "id": "d56e6c6d", + "metadata": {}, + "source": [ + "# Hamiltonian Simulation\n", + "\n", + "In this example we're going to apply the previously learned concept to run a hamiltonian simulation.\n", + "As before we are going to define a symbolic circuit as an ansatz." + ] }, - "nbformat": 4, - "nbformat_minor": 5 + { + "cell_type": "code", + "execution_count": null, + "id": "3563e447", + "metadata": {}, + "outputs": [], + "source": [ + "%pip install tierkreis pytket" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "bfbaa4df", + "metadata": {}, + "outputs": [], + "source": [ + "from pytket._tket.circuit import Circuit, fresh_symbol\n", + "\n", + "\n", + "def build_ansatz() -> Circuit:\n", + " a = fresh_symbol(\"a\")\n", + " b = fresh_symbol(\"b\")\n", + " c = fresh_symbol(\"c\")\n", + " circ = Circuit(4)\n", + " circ.CX(0, 1)\n", + " circ.CX(1, 2)\n", + " circ.CX(2, 3)\n", + " circ.Rz(a, 3)\n", + " circ.CX(2, 3)\n", + " circ.CX(1, 2)\n", + " circ.CX(0, 1)\n", + " circ.Rz(b, 0)\n", + " circ.CX(0, 1)\n", + " circ.CX(1, 2)\n", + " circ.CX(2, 3)\n", + " circ.Rz(c, 3)\n", + " circ.CX(2, 3)\n", + " circ.CX(1, 2)\n", + " circ.CX(0, 1)\n", + " return circ" + ] + }, + { + "cell_type": "markdown", + "id": "d1993864", + "metadata": {}, + "source": [ + "We are going to simulate a hamiltonian given as a list of Pauli strings and their weights.\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "f5d2e7be", + "metadata": {}, + "outputs": [], + "source": [ + "from tierkreis.builder import GraphBuilder\n", + "from tierkreis.controller.data.models import TKR\n", + "from typing import NamedTuple, Literal\n", + "\n", + "from substitution_worker import substitute\n", + "\n", + "\n", + "class SymbolicExecutionInputs(NamedTuple):\n", + " a: TKR[float]\n", + " b: TKR[float]\n", + " c: TKR[float]\n", + " ham: TKR[list[tuple[Literal[\"pytket._tket.pauli.QubitPauliString\"], float]]]\n", + " ansatz: TKR[Literal[\"pytket._tket.circuit.Circuit\"]]\n", + "\n", + "\n", + "simulation_graph = GraphBuilder(SymbolicExecutionInputs, TKR[float])\n", + "substituted_circuit = simulation_graph.task(\n", + " substitute(\n", + " simulation_graph.inputs.ansatz,\n", + " simulation_graph.inputs.a,\n", + " simulation_graph.inputs.b,\n", + " simulation_graph.inputs.c,\n", + " )\n", + ")" + ] + }, + { + "cell_type": "markdown", + "id": "161a5e02", + "metadata": {}, + "source": [ + "We will evaluate this circuit with an observable based on a Pauli string" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "39b21062", + "metadata": {}, + "outputs": [], + "source": [ + "from tierkreis.pytket_worker import (\n", + " append_pauli_measurement_impl,\n", + " optimise_phase_gadgets,\n", + " expectation,\n", + " Circuit as WorkerCircuit,\n", + ")\n", + "from tierkreis.aer_worker import submit_single\n", + "\n", + "\n", + "class SubmitInputs(NamedTuple):\n", + " circuit: TKR[WorkerCircuit]\n", + " pauli_string: TKR[Literal[\"pytket._tket.pauli.QubitPauliString\"]]\n", + " n_shots: TKR[int]\n", + "\n", + "\n", + "def exp_val():\n", + " g = GraphBuilder(SubmitInputs, TKR[float])\n", + "\n", + " circuit = g.inputs.circuit\n", + " pauli_string = g.inputs.pauli_string\n", + " n_shots = g.inputs.n_shots\n", + "\n", + " measurement_circuit = g.task(append_pauli_measurement_impl(circuit, pauli_string))\n", + "\n", + " compiled_circuit = g.task(optimise_phase_gadgets(measurement_circuit))\n", + "\n", + " backend_result = g.task(submit_single(compiled_circuit, n_shots))\n", + " av = g.task(expectation(backend_result))\n", + " g.outputs(av)\n", + " return g" + ] + }, + { + "cell_type": "markdown", + "id": "c7f5f9a1", + "metadata": {}, + "source": [ + "Since `exp_val` runs independently for each Pauli string we can implement this using a map, \n", + "but we need to prepare the inputs first." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "021e0e5b", + "metadata": {}, + "outputs": [], + "source": [ + "from tierkreis.builtins import unzip\n", + "from tierkreis.controller.data.models import TKR\n", + "\n", + "pauli_strings_list, parameters_list = simulation_graph.task(\n", + " unzip(simulation_graph.inputs.ham)\n", + ")\n", + "input_circuits = simulation_graph.map(\n", + " lambda x: SubmitInputs(substituted_circuit, x, simulation_graph.const(100)),\n", + " pauli_strings_list,\n", + ")\n", + "exp_values = simulation_graph.map(exp_val(), input_circuits)" + ] + }, + { + "cell_type": "markdown", + "id": "7788777e", + "metadata": {}, + "source": [ + "To estimate the energy, we can take a weighted sum of the expectation values.\n", + "For this we want to compute a reduction (\\(x,y) \\z --> x*y+z) which we implement as a fold function." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "cd24e08c", + "metadata": {}, + "outputs": [], + "source": [ + "from tierkreis.builtins import add, times, untuple\n", + "from tierkreis.graphs.fold import FoldFunctionInput\n", + "\n", + "ComputeTermsInputs = FoldFunctionInput[\n", + " tuple[float, float], float\n", + "] # (value, accum) -> new_accum\n", + "\n", + "\n", + "def compute_terms():\n", + " g = GraphBuilder(ComputeTermsInputs, TKR[float])\n", + "\n", + " res_0, res_1 = g.task(untuple(g.inputs.value))\n", + " prod = g.task(times(res_0, res_1))\n", + " sum = g.task(add(g.inputs.accum, prod))\n", + "\n", + " g.outputs(sum)\n", + " return g" + ] + }, + { + "cell_type": "markdown", + "id": "af57c8ac", + "metadata": {}, + "source": [ + "Preparing the inputs for the fold graph we are going to use tuples (x=exp_val, y=weight) and defining the start value z=0." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "9bab0de3", + "metadata": {}, + "outputs": [], + "source": [ + "from tierkreis.builtins import tkr_zip\n", + "from tierkreis.graphs.fold import FoldGraphInputs, fold_graph\n", + "\n", + "tuple_values = simulation_graph.task(tkr_zip(exp_values, parameters_list))\n", + "fold_inputs = FoldGraphInputs(simulation_graph.const(0.0), tuple_values)" + ] + }, + { + "cell_type": "markdown", + "id": "da997ea2", + "metadata": {}, + "source": [ + "applying the fold operation yields the final output" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "d7c6fa18", + "metadata": {}, + "outputs": [], + "source": [ + "computed = simulation_graph.eval(fold_graph(compute_terms()), fold_inputs)\n", + "simulation_graph.outputs(computed)" + ] + }, + { + "cell_type": "markdown", + "id": "5999c0a5", + "metadata": {}, + "source": [ + "As before we now have to set up tierkreis storage and executors" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "aec32e19", + "metadata": {}, + "outputs": [], + "source": [ + "from pathlib import Path\n", + "from uuid import UUID\n", + "\n", + "from tierkreis.consts import PACKAGE_PATH\n", + "from tierkreis.controller.executor.multiple import MultipleExecutor\n", + "from tierkreis.storage import FileStorage\n", + "from tierkreis.controller.executor.uv_executor import UvExecutor\n", + "\n", + "storage = FileStorage(UUID(int=102), name=\"hamiltonian\")\n", + "example_executor = UvExecutor(\n", + " registry_path=Path().parent / \"example_workers\", logs_path=storage.logs_path\n", + ")\n", + "common_executor = UvExecutor(\n", + " registry_path=PACKAGE_PATH.parent / \"tierkreis_workers\", logs_path=storage.logs_path\n", + ")\n", + "multi_executor = MultipleExecutor(\n", + " common_executor,\n", + " executors={\"custom\": example_executor},\n", + " assignments={\"substitution_worker\": \"custom\"},\n", + ")" + ] + }, + { + "cell_type": "markdown", + "id": "20848215", + "metadata": {}, + "source": [ + "and provide the inputs" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "2d3b86c0", + "metadata": {}, + "outputs": [], + "source": [ + "from pytket._tket.unit_id import Qubit\n", + "from pytket.pauli import Pauli, QubitPauliString\n", + "\n", + "qubits = [Qubit(0), Qubit(1), Qubit(2), Qubit(3)]\n", + "hamiltonian = [\n", + " (QubitPauliString(qubits, [Pauli.X, Pauli.Y, Pauli.X, Pauli.I]).to_list(), 0.1),\n", + " (QubitPauliString(qubits, [Pauli.Y, Pauli.Z, Pauli.X, Pauli.Z]).to_list(), 0.5),\n", + " (QubitPauliString(qubits, [Pauli.X, Pauli.Y, Pauli.Z, Pauli.I]).to_list(), 0.3),\n", + " (QubitPauliString(qubits, [Pauli.Z, Pauli.Y, Pauli.X, Pauli.Y]).to_list(), 0.6),\n", + "]\n", + "inputs = {\n", + " \"ansatz\": build_ansatz().to_dict(),\n", + " \"a\": 0.2,\n", + " \"b\": 0.55,\n", + " \"c\": 0.75,\n", + " \"ham\": hamiltonian,\n", + "}" + ] + }, + { + "cell_type": "markdown", + "id": "037d98b1", + "metadata": {}, + "source": [ + "before we can run the simulation:" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "53446615", + "metadata": {}, + "outputs": [], + "source": [ + "from tierkreis.controller import run_graph\n", + "from tierkreis.storage import read_outputs\n", + "\n", + "\n", + "storage.clean_graph_files()\n", + "run_graph(\n", + " storage,\n", + " multi_executor,\n", + " simulation_graph,\n", + " inputs,\n", + " polling_interval_seconds=0.2,\n", + ")\n", + "output = read_outputs(simulation_graph, storage)\n", + "print(output)" + ] + } + ], + "metadata": { + "execution": { + "timeout": -1 + }, + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.13.11" + } + }, + "nbformat": 4, + "nbformat_minor": 5 } diff --git a/docs/source/examples/qsci.ipynb b/docs/source/examples/qsci.ipynb index 7a2f1b25f..a1ca62dc9 100644 --- a/docs/source/examples/qsci.ipynb +++ b/docs/source/examples/qsci.ipynb @@ -345,15 +345,15 @@ "from tierkreis.aer_worker import submit_single\n", "from tierkreis.builder import GraphBuilder\n", "from tierkreis.controller.data.models import TKR, OpaqueType\n", - "from tierkreis.quantinuum_worker import compile_circuit_quantinuum\n", + "from tierkreis.quantinuum_worker import compile_circuit_quantinuum, Circuit as WorkerCircuit\n", "\n", "\n", "def _compile_and_run() -> GraphBuilder[\n", - " TKR[OpaqueType[\"pytket._tket.circuit.Circuit\"]], # noqa: F821\n", + " TKR[WorkerCircuit], # noqa: F821\n", " TKR[OpaqueType[\"pytket.backends.backendresult.BackendResult\"]], # noqa: F821\n", "]:\n", " g = GraphBuilder(\n", - " TKR[OpaqueType[\"pytket._tket.circuit.Circuit\"]],\n", + " TKR[WorkerCircuit],\n", " TKR[OpaqueType[\"pytket.backends.backendresult.BackendResult\"]],\n", " )\n", "\n", diff --git a/tierkreis/tests/workers/graph/stubs.py b/tierkreis/tests/workers/graph/stubs.py index 9217da5c0..58a208be1 100644 --- a/tierkreis/tests/workers/graph/stubs.py +++ b/tierkreis/tests/workers/graph/stubs.py @@ -1,13 +1,15 @@ """Code generated from graph namespace. Please do not edit.""" -from typing import NamedTuple -from tierkreis.controller.data.models import TKR, OpaqueType +from typing import Literal, NamedTuple +from tierkreis.controller.data.models import TKR + +type GraphData = Literal["tierkreis.controller.data.graph.GraphData"] class doubler_plus_graph(NamedTuple): @staticmethod - def out() -> type[TKR[OpaqueType["tierkreis.controller.data.graph.GraphData"]]]: # noqa: F821 # fmt: skip - return TKR[OpaqueType["tierkreis.controller.data.graph.GraphData"]] # noqa: F821 # fmt: skip + def out() -> type[TKR[GraphData]]: # noqa: F821 # fmt: skip + return TKR[GraphData] # noqa: F821 # fmt: skip @property def namespace(self) -> str: @@ -15,12 +17,12 @@ def namespace(self) -> str: class graph_of_graph(NamedTuple): - f: TKR[OpaqueType["tierkreis.controller.data.graph.GraphData"]] # noqa: F821 # fmt: skip + f: TKR[GraphData] # noqa: F821 # fmt: skip n: TKR[int] # noqa: F821 # fmt: skip @staticmethod - def out() -> type[TKR[OpaqueType["tierkreis.controller.data.graph.GraphData"]]]: # noqa: F821 # fmt: skip - return TKR[OpaqueType["tierkreis.controller.data.graph.GraphData"]] # noqa: F821 # fmt: skip + def out() -> type[TKR[GraphData]]: # noqa: F821 # fmt: skip + return TKR[GraphData] # noqa: F821 # fmt: skip @property def namespace(self) -> str: @@ -29,8 +31,8 @@ def namespace(self) -> str: class apply_twice(NamedTuple): @staticmethod - def out() -> type[TKR[OpaqueType["tierkreis.controller.data.graph.GraphData"]]]: # noqa: F821 # fmt: skip - return TKR[OpaqueType["tierkreis.controller.data.graph.GraphData"]] # noqa: F821 # fmt: skip + def out() -> type[TKR[GraphData]]: # noqa: F821 # fmt: skip + return TKR[GraphData] # noqa: F821 # fmt: skip @property def namespace(self) -> str: diff --git a/tierkreis/tierkreis/aer_worker.py b/tierkreis/tierkreis/aer_worker.py index 489897422..c6ca46d34 100644 --- a/tierkreis/tierkreis/aer_worker.py +++ b/tierkreis/tierkreis/aer_worker.py @@ -1,20 +1,23 @@ """Code generated from aer_worker namespace. Please do not edit.""" -from typing import NamedTuple, Union +from typing import Literal, NamedTuple, Union from types import NoneType -from tierkreis.controller.data.models import TKR, OpaqueType +from tierkreis.controller.data.models import TKR + +type Circuit = Literal["pytket._tket.circuit.Circuit"] +type BackendResult = Literal["pytket.backends.backendresult.BackendResult"] class get_compiled_circuit(NamedTuple): - circuit: TKR[OpaqueType["pytket._tket.circuit.Circuit"]] # noqa: F821 # fmt: skip + circuit: TKR[Circuit] # noqa: F821 # fmt: skip optimisation_level: TKR[int] | None = None # noqa: F821 # fmt: skip timeout: TKR[int] | None = None # noqa: F821 # fmt: skip simulation_method: TKR[str] | None = None # noqa: F821 # fmt: skip n_qubits: TKR[int] | None = None # noqa: F821 # fmt: skip @staticmethod - def out() -> type[TKR[OpaqueType["pytket._tket.circuit.Circuit"]]]: # noqa: F821 # fmt: skip - return TKR[OpaqueType["pytket._tket.circuit.Circuit"]] # noqa: F821 # fmt: skip + def out() -> type[TKR[Circuit]]: # noqa: F821 # fmt: skip + return TKR[Circuit] # noqa: F821 # fmt: skip @property def namespace(self) -> str: @@ -22,15 +25,15 @@ def namespace(self) -> str: class run_circuit(NamedTuple): - circuit: TKR[OpaqueType["pytket._tket.circuit.Circuit"]] # noqa: F821 # fmt: skip + circuit: TKR[Circuit] # noqa: F821 # fmt: skip n_shots: TKR[int] # noqa: F821 # fmt: skip simulation_method: TKR[str] | None = None # noqa: F821 # fmt: skip n_qubits: TKR[int] | None = None # noqa: F821 # fmt: skip seed: TKR[Union[int, NoneType]] | None = None # noqa: F821 # fmt: skip @staticmethod - def out() -> type[TKR[OpaqueType["pytket.backends.backendresult.BackendResult"]]]: # noqa: F821 # fmt: skip - return TKR[OpaqueType["pytket.backends.backendresult.BackendResult"]] # noqa: F821 # fmt: skip + def out() -> type[TKR[BackendResult]]: # noqa: F821 # fmt: skip + return TKR[BackendResult] # noqa: F821 # fmt: skip @property def namespace(self) -> str: @@ -38,15 +41,15 @@ def namespace(self) -> str: class run_circuits(NamedTuple): - circuits: TKR[list[OpaqueType["pytket._tket.circuit.Circuit"]]] # noqa: F821 # fmt: skip + circuits: TKR[list[Circuit]] # noqa: F821 # fmt: skip n_shots: TKR[list[int]] # noqa: F821 # fmt: skip simulation_method: TKR[str] | None = None # noqa: F821 # fmt: skip n_qubits: TKR[int] | None = None # noqa: F821 # fmt: skip seed: TKR[Union[int, NoneType]] | None = None # noqa: F821 # fmt: skip @staticmethod - def out() -> type[TKR[list[OpaqueType["pytket.backends.backendresult.BackendResult"]]]]: # noqa: F821 # fmt: skip - return TKR[list[OpaqueType["pytket.backends.backendresult.BackendResult"]]] # noqa: F821 # fmt: skip + def out() -> type[TKR[list[BackendResult]]]: # noqa: F821 # fmt: skip + return TKR[list[BackendResult]] # noqa: F821 # fmt: skip @property def namespace(self) -> str: @@ -54,7 +57,7 @@ def namespace(self) -> str: class to_qasm3_str(NamedTuple): - circuit: TKR[OpaqueType["pytket._tket.circuit.Circuit"]] # noqa: F821 # fmt: skip + circuit: TKR[Circuit] # noqa: F821 # fmt: skip @staticmethod def out() -> type[TKR[str]]: # noqa: F821 # fmt: skip @@ -66,12 +69,12 @@ def namespace(self) -> str: class submit(NamedTuple): - circuits: TKR[list[OpaqueType["pytket._tket.circuit.Circuit"]]] # noqa: F821 # fmt: skip + circuits: TKR[list[Circuit]] # noqa: F821 # fmt: skip n_shots: TKR[int] # noqa: F821 # fmt: skip @staticmethod - def out() -> type[TKR[list[OpaqueType["pytket.backends.backendresult.BackendResult"]]]]: # noqa: F821 # fmt: skip - return TKR[list[OpaqueType["pytket.backends.backendresult.BackendResult"]]] # noqa: F821 # fmt: skip + def out() -> type[TKR[list[BackendResult]]]: # noqa: F821 # fmt: skip + return TKR[list[BackendResult]] # noqa: F821 # fmt: skip @property def namespace(self) -> str: @@ -79,12 +82,12 @@ def namespace(self) -> str: class submit_single(NamedTuple): - circuit: TKR[OpaqueType["pytket._tket.circuit.Circuit"]] # noqa: F821 # fmt: skip + circuit: TKR[Circuit] # noqa: F821 # fmt: skip n_shots: TKR[int] # noqa: F821 # fmt: skip @staticmethod - def out() -> type[TKR[OpaqueType["pytket.backends.backendresult.BackendResult"]]]: # noqa: F821 # fmt: skip - return TKR[OpaqueType["pytket.backends.backendresult.BackendResult"]] # noqa: F821 # fmt: skip + def out() -> type[TKR[BackendResult]]: # noqa: F821 # fmt: skip + return TKR[BackendResult] # noqa: F821 # fmt: skip @property def namespace(self) -> str: diff --git a/tierkreis/tierkreis/codegen.py b/tierkreis/tierkreis/codegen.py index 4ff70dad0..e347136fc 100644 --- a/tierkreis/tierkreis/codegen.py +++ b/tierkreis/tierkreis/codegen.py @@ -1,13 +1,6 @@ """Code generation utilities for Tierkreis stubs.""" -from inspect import isclass - -from pydantic import BaseModel - from tierkreis.controller.data.types import ( - DictConvertible, - ListConvertible, - NdarraySurrogate, _is_union, ) from tierkreis.idl.models import GenericType, Method, Model, TypedArg @@ -26,12 +19,6 @@ def format_ptype(ptype: type | str) -> str: if isinstance(ptype, str): return ptype - if isclass(ptype) and issubclass( - ptype, - (DictConvertible, ListConvertible, NdarraySurrogate, BaseModel), - ): - return f'OpaqueType["{ptype.__module__}.{ptype.__qualname__}"]' - if _is_union(ptype): return "Union" @@ -116,6 +103,14 @@ class {generic_type_str}({bases_str}): """ +def format_opaque_alias(name: str, fqname: str) -> str: + return f'type {name} = Literal["{fqname}"]' + + +def format_opaque_aliases(aliases: dict[str, str]) -> str: + return "\n".join([format_opaque_alias(x, y) for x, y in aliases.items()]) + + def format_method(namespace_name: str, fn: Method) -> str: """Format a method to a string. diff --git a/tierkreis/tierkreis/controller/data/types.py b/tierkreis/tierkreis/controller/data/types.py index 33ff544f1..5dbee056e 100644 --- a/tierkreis/tierkreis/controller/data/types.py +++ b/tierkreis/tierkreis/controller/data/types.py @@ -192,6 +192,20 @@ def _is_tuple(o: object) -> TypeIs[type[tuple[Any, ...]]]: return get_origin(o) is tuple +def is_opaque(o: object) -> bool: + """Is the given object an opaque type? + + I.e. should its contents be hidden from the graph builder?""" + if isinstance(o, (BaseModel, DictConvertible, ListConvertible, NdarraySurrogate)): + return True + if isclass(o) and issubclass( + o, (BaseModel, DictConvertible, ListConvertible, NdarraySurrogate) + ): + return True + + return False + + def is_ptype(annotation: Any) -> TypeIs[type[PType]]: """Check if a type annotation is a PType. diff --git a/tierkreis/tierkreis/ibmq_worker.py b/tierkreis/tierkreis/ibmq_worker.py index 57e3b7dae..6cc832d3f 100644 --- a/tierkreis/tierkreis/ibmq_worker.py +++ b/tierkreis/tierkreis/ibmq_worker.py @@ -1,15 +1,20 @@ """Code generated from ibmq_worker namespace. Please do not edit.""" -from typing import NamedTuple, Sequence -from tierkreis.controller.data.models import TKR, OpaqueType +from typing import Literal, NamedTuple, Sequence +from tierkreis.controller.data.models import TKR + +type BackendInfo = Literal["pytket.backends.backendinfo.BackendInfo"] +type BasePass = Literal["pytket._tket.passes.BasePass"] +type Circuit = Literal["pytket._tket.circuit.Circuit"] +type BackendResult = Literal["pytket.backends.backendresult.BackendResult"] class get_backend_info(NamedTuple): device_name: TKR[str] # noqa: F821 # fmt: skip @staticmethod - def out() -> type[TKR[OpaqueType["pytket.backends.backendinfo.BackendInfo"]]]: # noqa: F821 # fmt: skip - return TKR[OpaqueType["pytket.backends.backendinfo.BackendInfo"]] # noqa: F821 # fmt: skip + def out() -> type[TKR[BackendInfo]]: # noqa: F821 # fmt: skip + return TKR[BackendInfo] # noqa: F821 # fmt: skip @property def namespace(self) -> str: @@ -17,12 +22,12 @@ def namespace(self) -> str: class backend_pass_from_info(NamedTuple): - backend_info: TKR[OpaqueType["pytket.backends.backendinfo.BackendInfo"]] # noqa: F821 # fmt: skip + backend_info: TKR[BackendInfo] # noqa: F821 # fmt: skip optimisation_level: TKR[int] | None = None # noqa: F821 # fmt: skip @staticmethod - def out() -> type[TKR[OpaqueType["pytket._tket.passes.BasePass"]]]: # noqa: F821 # fmt: skip - return TKR[OpaqueType["pytket._tket.passes.BasePass"]] # noqa: F821 # fmt: skip + def out() -> type[TKR[BasePass]]: # noqa: F821 # fmt: skip + return TKR[BasePass] # noqa: F821 # fmt: skip @property def namespace(self) -> str: @@ -34,8 +39,8 @@ class backend_default_compilation_pass(NamedTuple): optimisation_level: TKR[int] | None = None # noqa: F821 # fmt: skip @staticmethod - def out() -> type[TKR[OpaqueType["pytket._tket.passes.BasePass"]]]: # noqa: F821 # fmt: skip - return TKR[OpaqueType["pytket._tket.passes.BasePass"]] # noqa: F821 # fmt: skip + def out() -> type[TKR[BasePass]]: # noqa: F821 # fmt: skip + return TKR[BasePass] # noqa: F821 # fmt: skip @property def namespace(self) -> str: @@ -47,8 +52,8 @@ class fixed_pass(NamedTuple): optimisation_level: TKR[int] | None = None # noqa: F821 # fmt: skip @staticmethod - def out() -> type[TKR[OpaqueType["pytket._tket.passes.BasePass"]]]: # noqa: F821 # fmt: skip - return TKR[OpaqueType["pytket._tket.passes.BasePass"]] # noqa: F821 # fmt: skip + def out() -> type[TKR[BasePass]]: # noqa: F821 # fmt: skip + return TKR[BasePass] # noqa: F821 # fmt: skip @property def namespace(self) -> str: @@ -56,13 +61,13 @@ def namespace(self) -> str: class compile(NamedTuple): - circuit: TKR[OpaqueType["pytket._tket.circuit.Circuit"]] # noqa: F821 # fmt: skip + circuit: TKR[Circuit] # noqa: F821 # fmt: skip device_name: TKR[str] # noqa: F821 # fmt: skip optimisation_level: TKR[int] | None = None # noqa: F821 # fmt: skip @staticmethod - def out() -> type[TKR[OpaqueType["pytket._tket.circuit.Circuit"]]]: # noqa: F821 # fmt: skip - return TKR[OpaqueType["pytket._tket.circuit.Circuit"]] # noqa: F821 # fmt: skip + def out() -> type[TKR[Circuit]]: # noqa: F821 # fmt: skip + return TKR[Circuit] # noqa: F821 # fmt: skip @property def namespace(self) -> str: @@ -70,13 +75,13 @@ def namespace(self) -> str: class compile_circuit_ibmq(NamedTuple): - circuit: TKR[OpaqueType["pytket._tket.circuit.Circuit"]] # noqa: F821 # fmt: skip + circuit: TKR[Circuit] # noqa: F821 # fmt: skip device_name: TKR[str] # noqa: F821 # fmt: skip optimisation_level: TKR[int] | None = None # noqa: F821 # fmt: skip @staticmethod - def out() -> type[TKR[OpaqueType["pytket._tket.circuit.Circuit"]]]: # noqa: F821 # fmt: skip - return TKR[OpaqueType["pytket._tket.circuit.Circuit"]] # noqa: F821 # fmt: skip + def out() -> type[TKR[Circuit]]: # noqa: F821 # fmt: skip + return TKR[Circuit] # noqa: F821 # fmt: skip @property def namespace(self) -> str: @@ -84,13 +89,13 @@ def namespace(self) -> str: class compile_circuits_ibmq(NamedTuple): - circuits: TKR[list[OpaqueType["pytket._tket.circuit.Circuit"]]] # noqa: F821 # fmt: skip + circuits: TKR[list[Circuit]] # noqa: F821 # fmt: skip device_name: TKR[str] # noqa: F821 # fmt: skip optimisation_level: TKR[int] | None = None # noqa: F821 # fmt: skip @staticmethod - def out() -> type[TKR[list[OpaqueType["pytket._tket.circuit.Circuit"]]]]: # noqa: F821 # fmt: skip - return TKR[list[OpaqueType["pytket._tket.circuit.Circuit"]]] # noqa: F821 # fmt: skip + def out() -> type[TKR[list[Circuit]]]: # noqa: F821 # fmt: skip + return TKR[list[Circuit]] # noqa: F821 # fmt: skip @property def namespace(self) -> str: @@ -98,13 +103,13 @@ def namespace(self) -> str: class run_circuit(NamedTuple): - circuit: TKR[OpaqueType["pytket._tket.circuit.Circuit"]] # noqa: F821 # fmt: skip + circuit: TKR[Circuit] # noqa: F821 # fmt: skip n_shots: TKR[int] # noqa: F821 # fmt: skip device_name: TKR[str] # noqa: F821 # fmt: skip @staticmethod - def out() -> type[TKR[OpaqueType["pytket.backends.backendresult.BackendResult"]]]: # noqa: F821 # fmt: skip - return TKR[OpaqueType["pytket.backends.backendresult.BackendResult"]] # noqa: F821 # fmt: skip + def out() -> type[TKR[BackendResult]]: # noqa: F821 # fmt: skip + return TKR[BackendResult] # noqa: F821 # fmt: skip @property def namespace(self) -> str: diff --git a/tierkreis/tierkreis/idl/models.py b/tierkreis/tierkreis/idl/models.py index 2b05a2e7c..5499876c6 100644 --- a/tierkreis/tierkreis/idl/models.py +++ b/tierkreis/tierkreis/idl/models.py @@ -5,8 +5,12 @@ from types import NoneType from typing import Annotated, Self, get_args, get_origin + from tierkreis.controller.data.core import RestrictedNamedTuple -from tierkreis.controller.data.types import _is_generic +from tierkreis.controller.data.types import ( + _is_generic, + is_opaque, +) type ElementaryType = ( type[int | float | bytes | str | bool | NoneType | Mapping | Sequence] @@ -49,6 +53,28 @@ def from_type(cls, t: type) -> "Self": [subargs.append(cls.from_type(x)) for x in args if not _is_generic(x)] return cls(origin, subargs) + @classmethod + def _included_opaque_type_names(cls, t: "GenericType") -> "dict[str, str]": + if is_opaque(t.origin): + outs = { + t.origin.__qualname__: f"{t.origin.__module__}.{t.origin.__qualname__}" + } + else: + outs = dict() + [ + outs.update(cls._included_opaque_type_names(x)) + for x in t.args + if isinstance(x, cls) + ] + return outs + + def included_opaque_type_names(self) -> "dict[str, str]": + """Find the opaque types in this type. + + Am opaque type is one of (BaseModel, DictConvertible, ListConvertible, NdarraySurrogate) + """ + return GenericType._included_opaque_type_names(self) + @classmethod def _included_structs(cls, t: "GenericType") -> "set[GenericType]": outs = set({t}) if isinstance(t.origin, (RestrictedNamedTuple, str)) else set() diff --git a/tierkreis/tierkreis/namespace.py b/tierkreis/tierkreis/namespace.py index 6a4041d94..d265750a2 100644 --- a/tierkreis/tierkreis/namespace.py +++ b/tierkreis/tierkreis/namespace.py @@ -9,9 +9,14 @@ from pathlib import Path from typing import Self -from tierkreis.codegen import format_method, format_model + +from tierkreis.codegen import format_method, format_model, format_opaque_aliases from tierkreis.controller.data.models import PModel, is_portmapping -from tierkreis.controller.data.types import Struct, has_default, is_ptype +from tierkreis.controller.data.types import ( + Struct, + has_default, + is_ptype, +) from tierkreis.exceptions import TierkreisError from tierkreis.idl.models import GenericType, Interface, Method, Model, TypedArg from tierkreis.idl.spec import spec @@ -32,6 +37,7 @@ class Namespace: name: str methods: list[Method] = field(default_factory=list) models: set[Model] = field(default_factory=set) + opaque_type_lookup: dict[str, str] = field(default_factory=dict) def add_struct(self, generic_type: GenericType) -> None: """Add a struct to the namespace. @@ -77,17 +83,25 @@ def add_function(self, func: WorkerFunction) -> None: """ sig = self._validate_signature(func) + args = [ + TypedArg(k, GenericType.from_type(t.annotation), has_default(t)) + for k, t in sig.parameters.items() + ] + return_type = GenericType.from_type(sig.return_annotation) method = Method( GenericType(func.__name__, [str(x) for x in func.__type_params__]), - [ - TypedArg(k, GenericType.from_type(t.annotation), has_default(t)) - for k, t in sig.parameters.items() - ], - GenericType.from_type(sig.return_annotation), + args, + return_type, is_portmapping(sig.return_annotation), ) self.methods.append(method) + [ + self.opaque_type_lookup.update(arg.t.included_opaque_type_names()) + for arg in args + ] + self.opaque_type_lookup.update(return_type.included_opaque_type_names()) + for annotation_type in func.__annotations__.values(): [ self.add_struct(struct) @@ -126,6 +140,7 @@ def stubs(self) -> str: :return: The generated stubs as string. :rtype: str """ + aliases_str = format_opaque_aliases(self.opaque_type_lookup) functions = [format_method(self.name, method) for method in self.methods] functions_str = "\n\n".join(functions) models_str = "\n\n".join([format_model(model) for model in sorted(self.models)]) @@ -137,6 +152,8 @@ def stubs(self) -> str: from tierkreis.controller.data.models import TKR, OpaqueType from tierkreis.controller.data.types import PType, Struct +{aliases_str} + {models_str} {functions_str} diff --git a/tierkreis/tierkreis/nexus_worker.py b/tierkreis/tierkreis/nexus_worker.py index f0a3f772e..4dbc8c38b 100644 --- a/tierkreis/tierkreis/nexus_worker.py +++ b/tierkreis/tierkreis/nexus_worker.py @@ -1,16 +1,42 @@ """Code generated from nexus_worker namespace. Please do not edit.""" -from typing import NamedTuple, Union -from tierkreis.controller.data.models import TKR, OpaqueType +from typing import Literal, NamedTuple, Union +from tierkreis.controller.data.models import TKR + +type Circuit = Literal["pytket._tket.circuit.Circuit"] +type CircuitRef = Literal["qnexus.models.references.CircuitRef"] +type HUGRRef = Literal["qnexus.models.references.HUGRRef"] +type QIRRef = Literal["qnexus.models.references.QIRRef"] +type AerConfig = Literal["quantinuum_schemas.models.backend_config.AerConfig"] +type AerStateConfig = Literal["quantinuum_schemas.models.backend_config.AerStateConfig"] +type AerUnitaryConfig = Literal[ + "quantinuum_schemas.models.backend_config.AerUnitaryConfig" +] +type BraketConfig = Literal["quantinuum_schemas.models.backend_config.BraketConfig"] +type QuantinuumConfig = Literal[ + "quantinuum_schemas.models.backend_config.QuantinuumConfig" +] +type IBMQConfig = Literal["quantinuum_schemas.models.backend_config.IBMQConfig"] +type IBMQEmulatorConfig = Literal[ + "quantinuum_schemas.models.backend_config.IBMQEmulatorConfig" +] +type QulacsConfig = Literal["quantinuum_schemas.models.backend_config.QulacsConfig"] +type SeleneConfig = Literal["quantinuum_schemas.models.backend_config.SeleneConfig"] +type SelenePlusConfig = Literal[ + "quantinuum_schemas.models.backend_config.SelenePlusConfig" +] +type HeliosConfig = Literal["quantinuum_schemas.models.backend_config.HeliosConfig"] +type ExecuteJobRef = Literal["qnexus.models.references.ExecuteJobRef"] +type BackendResult = Literal["pytket.backends.backendresult.BackendResult"] class upload_circuit(NamedTuple): project_name: TKR[str] # noqa: F821 # fmt: skip - circ: TKR[OpaqueType["pytket._tket.circuit.Circuit"]] # noqa: F821 # fmt: skip + circ: TKR[Circuit] # noqa: F821 # fmt: skip @staticmethod - def out() -> type[TKR[Union[OpaqueType["qnexus.models.references.CircuitRef"], OpaqueType["qnexus.models.references.HUGRRef"], OpaqueType["qnexus.models.references.QIRRef"]]]]: # noqa: F821 # fmt: skip - return TKR[Union[OpaqueType["qnexus.models.references.CircuitRef"], OpaqueType["qnexus.models.references.HUGRRef"], OpaqueType["qnexus.models.references.QIRRef"]]] # noqa: F821 # fmt: skip + def out() -> type[TKR[Union[CircuitRef, HUGRRef, QIRRef]]]: # noqa: F821 # fmt: skip + return TKR[Union[CircuitRef, HUGRRef, QIRRef]] # noqa: F821 # fmt: skip @property def namespace(self) -> str: @@ -20,13 +46,13 @@ def namespace(self) -> str: class start_execute_job(NamedTuple): project_name: TKR[str] # noqa: F821 # fmt: skip job_name: TKR[str] # noqa: F821 # fmt: skip - circuits: TKR[list[Union[OpaqueType["qnexus.models.references.CircuitRef"], OpaqueType["qnexus.models.references.HUGRRef"], OpaqueType["qnexus.models.references.QIRRef"]]]] # noqa: F821 # fmt: skip + circuits: TKR[list[Union[CircuitRef, HUGRRef, QIRRef]]] # noqa: F821 # fmt: skip n_shots: TKR[list[int]] # noqa: F821 # fmt: skip - backend_config: TKR[Union[OpaqueType["quantinuum_schemas.models.backend_config.AerConfig"], OpaqueType["quantinuum_schemas.models.backend_config.AerStateConfig"], OpaqueType["quantinuum_schemas.models.backend_config.AerUnitaryConfig"], OpaqueType["quantinuum_schemas.models.backend_config.BraketConfig"], OpaqueType["quantinuum_schemas.models.backend_config.QuantinuumConfig"], OpaqueType["quantinuum_schemas.models.backend_config.IBMQConfig"], OpaqueType["quantinuum_schemas.models.backend_config.IBMQEmulatorConfig"], OpaqueType["quantinuum_schemas.models.backend_config.QulacsConfig"], OpaqueType["quantinuum_schemas.models.backend_config.SeleneConfig"], OpaqueType["quantinuum_schemas.models.backend_config.SelenePlusConfig"], OpaqueType["quantinuum_schemas.models.backend_config.HeliosConfig"]]] # noqa: F821 # fmt: skip + backend_config: TKR[Union[AerConfig, AerStateConfig, AerUnitaryConfig, BraketConfig, QuantinuumConfig, IBMQConfig, IBMQEmulatorConfig, QulacsConfig, SeleneConfig, SelenePlusConfig, HeliosConfig]] # noqa: F821 # fmt: skip @staticmethod - def out() -> type[TKR[OpaqueType["qnexus.models.references.ExecuteJobRef"]]]: # noqa: F821 # fmt: skip - return TKR[OpaqueType["qnexus.models.references.ExecuteJobRef"]] # noqa: F821 # fmt: skip + def out() -> type[TKR[ExecuteJobRef]]: # noqa: F821 # fmt: skip + return TKR[ExecuteJobRef] # noqa: F821 # fmt: skip @property def namespace(self) -> str: @@ -34,7 +60,7 @@ def namespace(self) -> str: class is_running(NamedTuple): - execute_ref: TKR[OpaqueType["qnexus.models.references.ExecuteJobRef"]] # noqa: F821 # fmt: skip + execute_ref: TKR[ExecuteJobRef] # noqa: F821 # fmt: skip @staticmethod def out() -> type[TKR[bool]]: # noqa: F821 # fmt: skip @@ -46,11 +72,11 @@ def namespace(self) -> str: class get_results(NamedTuple): - execute_ref: TKR[OpaqueType["qnexus.models.references.ExecuteJobRef"]] # noqa: F821 # fmt: skip + execute_ref: TKR[ExecuteJobRef] # noqa: F821 # fmt: skip @staticmethod - def out() -> type[TKR[list[OpaqueType["pytket.backends.backendresult.BackendResult"]]]]: # noqa: F821 # fmt: skip - return TKR[list[OpaqueType["pytket.backends.backendresult.BackendResult"]]] # noqa: F821 # fmt: skip + def out() -> type[TKR[list[BackendResult]]]: # noqa: F821 # fmt: skip + return TKR[list[BackendResult]] # noqa: F821 # fmt: skip @property def namespace(self) -> str: @@ -58,7 +84,7 @@ def namespace(self) -> str: class check_status(NamedTuple): - execute_ref: TKR[OpaqueType["qnexus.models.references.ExecuteJobRef"]] # noqa: F821 # fmt: skip + execute_ref: TKR[ExecuteJobRef] # noqa: F821 # fmt: skip @staticmethod def out() -> type[TKR[str]]: # noqa: F821 # fmt: skip @@ -70,12 +96,12 @@ def namespace(self) -> str: class submit(NamedTuple): - circuits: TKR[list[OpaqueType["pytket._tket.circuit.Circuit"]]] # noqa: F821 # fmt: skip + circuits: TKR[list[Circuit]] # noqa: F821 # fmt: skip n_shots: TKR[int] # noqa: F821 # fmt: skip @staticmethod - def out() -> type[TKR[OpaqueType["qnexus.models.references.ExecuteJobRef"]]]: # noqa: F821 # fmt: skip - return TKR[OpaqueType["qnexus.models.references.ExecuteJobRef"]] # noqa: F821 # fmt: skip + def out() -> type[TKR[ExecuteJobRef]]: # noqa: F821 # fmt: skip + return TKR[ExecuteJobRef] # noqa: F821 # fmt: skip @property def namespace(self) -> str: diff --git a/tierkreis/tierkreis/pytket_worker.py b/tierkreis/tierkreis/pytket_worker.py index 3ada52093..aec1b713b 100644 --- a/tierkreis/tierkreis/pytket_worker.py +++ b/tierkreis/tierkreis/pytket_worker.py @@ -1,16 +1,41 @@ """Code generated from pytket_worker namespace. Please do not edit.""" -from typing import NamedTuple, Union +from typing import Literal, NamedTuple, Union from types import NoneType -from tierkreis.controller.data.models import TKR, OpaqueType +from tierkreis.controller.data.models import TKR + +type AerConfig = Literal["quantinuum_schemas.models.backend_config.AerConfig"] +type AerStateConfig = Literal["quantinuum_schemas.models.backend_config.AerStateConfig"] +type AerUnitaryConfig = Literal[ + "quantinuum_schemas.models.backend_config.AerUnitaryConfig" +] +type BraketConfig = Literal["quantinuum_schemas.models.backend_config.BraketConfig"] +type QuantinuumConfig = Literal[ + "quantinuum_schemas.models.backend_config.QuantinuumConfig" +] +type IBMQConfig = Literal["quantinuum_schemas.models.backend_config.IBMQConfig"] +type IBMQEmulatorConfig = Literal[ + "quantinuum_schemas.models.backend_config.IBMQEmulatorConfig" +] +type QulacsConfig = Literal["quantinuum_schemas.models.backend_config.QulacsConfig"] +type SeleneConfig = Literal["quantinuum_schemas.models.backend_config.SeleneConfig"] +type SelenePlusConfig = Literal[ + "quantinuum_schemas.models.backend_config.SelenePlusConfig" +] +type HeliosConfig = Literal["quantinuum_schemas.models.backend_config.HeliosConfig"] +type BackendInfo = Literal["pytket.backends.backendinfo.BackendInfo"] +type Circuit = Literal["pytket._tket.circuit.Circuit"] +type QubitPauliString = Literal["pytket._tket.pauli.QubitPauliString"] +type BasePass = Literal["pytket._tket.passes.BasePass"] +type BackendResult = Literal["pytket.backends.backendresult.BackendResult"] class get_backend_info(NamedTuple): - config: TKR[Union[OpaqueType["quantinuum_schemas.models.backend_config.AerConfig"], OpaqueType["quantinuum_schemas.models.backend_config.AerStateConfig"], OpaqueType["quantinuum_schemas.models.backend_config.AerUnitaryConfig"], OpaqueType["quantinuum_schemas.models.backend_config.BraketConfig"], OpaqueType["quantinuum_schemas.models.backend_config.QuantinuumConfig"], OpaqueType["quantinuum_schemas.models.backend_config.IBMQConfig"], OpaqueType["quantinuum_schemas.models.backend_config.IBMQEmulatorConfig"], OpaqueType["quantinuum_schemas.models.backend_config.QulacsConfig"], OpaqueType["quantinuum_schemas.models.backend_config.SeleneConfig"], OpaqueType["quantinuum_schemas.models.backend_config.SelenePlusConfig"], OpaqueType["quantinuum_schemas.models.backend_config.HeliosConfig"]]] # noqa: F821 # fmt: skip + config: TKR[Union[AerConfig, AerStateConfig, AerUnitaryConfig, BraketConfig, QuantinuumConfig, IBMQConfig, IBMQEmulatorConfig, QulacsConfig, SeleneConfig, SelenePlusConfig, HeliosConfig]] # noqa: F821 # fmt: skip @staticmethod - def out() -> type[TKR[OpaqueType["pytket.backends.backendinfo.BackendInfo"]]]: # noqa: F821 # fmt: skip - return TKR[OpaqueType["pytket.backends.backendinfo.BackendInfo"]] # noqa: F821 # fmt: skip + def out() -> type[TKR[BackendInfo]]: # noqa: F821 # fmt: skip + return TKR[BackendInfo] # noqa: F821 # fmt: skip @property def namespace(self) -> str: @@ -18,7 +43,7 @@ def namespace(self) -> str: class device_name_from_info(NamedTuple): - backend_info: TKR[OpaqueType["pytket.backends.backendinfo.BackendInfo"]] # noqa: F821 # fmt: skip + backend_info: TKR[BackendInfo] # noqa: F821 # fmt: skip @staticmethod def out() -> type[TKR[Union[str, NoneType]]]: # noqa: F821 # fmt: skip @@ -30,15 +55,15 @@ def namespace(self) -> str: class compile_using_info(NamedTuple): - circuit: TKR[OpaqueType["pytket._tket.circuit.Circuit"]] # noqa: F821 # fmt: skip - backend_info: TKR[OpaqueType["pytket.backends.backendinfo.BackendInfo"]] # noqa: F821 # fmt: skip - config: TKR[Union[OpaqueType["quantinuum_schemas.models.backend_config.AerConfig"], OpaqueType["quantinuum_schemas.models.backend_config.AerStateConfig"], OpaqueType["quantinuum_schemas.models.backend_config.AerUnitaryConfig"], OpaqueType["quantinuum_schemas.models.backend_config.BraketConfig"], OpaqueType["quantinuum_schemas.models.backend_config.QuantinuumConfig"], OpaqueType["quantinuum_schemas.models.backend_config.IBMQConfig"], OpaqueType["quantinuum_schemas.models.backend_config.IBMQEmulatorConfig"], OpaqueType["quantinuum_schemas.models.backend_config.QulacsConfig"], OpaqueType["quantinuum_schemas.models.backend_config.SeleneConfig"], OpaqueType["quantinuum_schemas.models.backend_config.SelenePlusConfig"], OpaqueType["quantinuum_schemas.models.backend_config.HeliosConfig"]]] # noqa: F821 # fmt: skip + circuit: TKR[Circuit] # noqa: F821 # fmt: skip + backend_info: TKR[BackendInfo] # noqa: F821 # fmt: skip + config: TKR[Union[AerConfig, AerStateConfig, AerUnitaryConfig, BraketConfig, QuantinuumConfig, IBMQConfig, IBMQEmulatorConfig, QulacsConfig, SeleneConfig, SelenePlusConfig, HeliosConfig]] # noqa: F821 # fmt: skip optimisation_level: TKR[int] | None = None # noqa: F821 # fmt: skip timeout: TKR[int] | None = None # noqa: F821 # fmt: skip @staticmethod - def out() -> type[TKR[OpaqueType["pytket._tket.circuit.Circuit"]]]: # noqa: F821 # fmt: skip - return TKR[OpaqueType["pytket._tket.circuit.Circuit"]] # noqa: F821 # fmt: skip + def out() -> type[TKR[Circuit]]: # noqa: F821 # fmt: skip + return TKR[Circuit] # noqa: F821 # fmt: skip @property def namespace(self) -> str: @@ -46,11 +71,11 @@ def namespace(self) -> str: class add_measure_all(NamedTuple): - circuit: TKR[OpaqueType["pytket._tket.circuit.Circuit"]] # noqa: F821 # fmt: skip + circuit: TKR[Circuit] # noqa: F821 # fmt: skip @staticmethod - def out() -> type[TKR[OpaqueType["pytket._tket.circuit.Circuit"]]]: # noqa: F821 # fmt: skip - return TKR[OpaqueType["pytket._tket.circuit.Circuit"]] # noqa: F821 # fmt: skip + def out() -> type[TKR[Circuit]]: # noqa: F821 # fmt: skip + return TKR[Circuit] # noqa: F821 # fmt: skip @property def namespace(self) -> str: @@ -58,12 +83,12 @@ def namespace(self) -> str: class append_pauli_measurement_impl(NamedTuple): - circuit: TKR[OpaqueType["pytket._tket.circuit.Circuit"]] # noqa: F821 # fmt: skip - pauli_string: TKR[OpaqueType["pytket._tket.pauli.QubitPauliString"]] # noqa: F821 # fmt: skip + circuit: TKR[Circuit] # noqa: F821 # fmt: skip + pauli_string: TKR[QubitPauliString] # noqa: F821 # fmt: skip @staticmethod - def out() -> type[TKR[OpaqueType["pytket._tket.circuit.Circuit"]]]: # noqa: F821 # fmt: skip - return TKR[OpaqueType["pytket._tket.circuit.Circuit"]] # noqa: F821 # fmt: skip + def out() -> type[TKR[Circuit]]: # noqa: F821 # fmt: skip + return TKR[Circuit] # noqa: F821 # fmt: skip @property def namespace(self) -> str: @@ -71,11 +96,11 @@ def namespace(self) -> str: class optimise_phase_gadgets(NamedTuple): - circuit: TKR[OpaqueType["pytket._tket.circuit.Circuit"]] # noqa: F821 # fmt: skip + circuit: TKR[Circuit] # noqa: F821 # fmt: skip @staticmethod - def out() -> type[TKR[OpaqueType["pytket._tket.circuit.Circuit"]]]: # noqa: F821 # fmt: skip - return TKR[OpaqueType["pytket._tket.circuit.Circuit"]] # noqa: F821 # fmt: skip + def out() -> type[TKR[Circuit]]: # noqa: F821 # fmt: skip + return TKR[Circuit] # noqa: F821 # fmt: skip @property def namespace(self) -> str: @@ -83,12 +108,12 @@ def namespace(self) -> str: class apply_pass(NamedTuple): - circuit: TKR[OpaqueType["pytket._tket.circuit.Circuit"]] # noqa: F821 # fmt: skip - compiler_pass: TKR[OpaqueType["pytket._tket.passes.BasePass"]] # noqa: F821 # fmt: skip + circuit: TKR[Circuit] # noqa: F821 # fmt: skip + compiler_pass: TKR[BasePass] # noqa: F821 # fmt: skip @staticmethod - def out() -> type[TKR[OpaqueType["pytket._tket.circuit.Circuit"]]]: # noqa: F821 # fmt: skip - return TKR[OpaqueType["pytket._tket.circuit.Circuit"]] # noqa: F821 # fmt: skip + def out() -> type[TKR[Circuit]]: # noqa: F821 # fmt: skip + return TKR[Circuit] # noqa: F821 # fmt: skip @property def namespace(self) -> str: @@ -96,17 +121,17 @@ def namespace(self) -> str: class compile_generic_with_fixed_pass(NamedTuple): - circuit: TKR[Union[OpaqueType["pytket._tket.circuit.Circuit"], str, bytes]] # noqa: F821 # fmt: skip + circuit: TKR[Union[Circuit, str, bytes]] # noqa: F821 # fmt: skip input_format: TKR[str] | None = None # noqa: F821 # fmt: skip optimisation_level: TKR[int] | None = None # noqa: F821 # fmt: skip gate_set: TKR[Union[list[str], NoneType]] | None = None # noqa: F821 # fmt: skip coupling_map: TKR[Union[list[tuple[int, int]], NoneType]] | None = None # noqa: F821 # fmt: skip output_format: TKR[str] | None = None # noqa: F821 # fmt: skip - optimisation_pass: TKR[Union[OpaqueType["pytket._tket.passes.BasePass"], NoneType]] | None = None # noqa: F821 # fmt: skip + optimisation_pass: TKR[Union[BasePass, NoneType]] | None = None # noqa: F821 # fmt: skip @staticmethod - def out() -> type[TKR[Union[OpaqueType["pytket._tket.circuit.Circuit"], str, bytes]]]: # noqa: F821 # fmt: skip - return TKR[Union[OpaqueType["pytket._tket.circuit.Circuit"], str, bytes]] # noqa: F821 # fmt: skip + def out() -> type[TKR[Union[Circuit, str, bytes]]]: # noqa: F821 # fmt: skip + return TKR[Union[Circuit, str, bytes]] # noqa: F821 # fmt: skip @property def namespace(self) -> str: @@ -114,7 +139,7 @@ def namespace(self) -> str: class to_qasm2_str(NamedTuple): - circuit: TKR[OpaqueType["pytket._tket.circuit.Circuit"]] # noqa: F821 # fmt: skip + circuit: TKR[Circuit] # noqa: F821 # fmt: skip header: TKR[str] | None = None # noqa: F821 # fmt: skip @staticmethod @@ -130,8 +155,8 @@ class from_qasm2_str(NamedTuple): qasm: TKR[str] # noqa: F821 # fmt: skip @staticmethod - def out() -> type[TKR[OpaqueType["pytket._tket.circuit.Circuit"]]]: # noqa: F821 # fmt: skip - return TKR[OpaqueType["pytket._tket.circuit.Circuit"]] # noqa: F821 # fmt: skip + def out() -> type[TKR[Circuit]]: # noqa: F821 # fmt: skip + return TKR[Circuit] # noqa: F821 # fmt: skip @property def namespace(self) -> str: @@ -139,7 +164,7 @@ def namespace(self) -> str: class to_qir_bytes(NamedTuple): - circuit: TKR[OpaqueType["pytket._tket.circuit.Circuit"]] # noqa: F821 # fmt: skip + circuit: TKR[Circuit] # noqa: F821 # fmt: skip @staticmethod def out() -> type[TKR[bytes]]: # noqa: F821 # fmt: skip @@ -154,8 +179,8 @@ class from_qir_bytes(NamedTuple): qir: TKR[bytes] # noqa: F821 # fmt: skip @staticmethod - def out() -> type[TKR[OpaqueType["pytket._tket.circuit.Circuit"]]]: # noqa: F821 # fmt: skip - return TKR[OpaqueType["pytket._tket.circuit.Circuit"]] # noqa: F821 # fmt: skip + def out() -> type[TKR[Circuit]]: # noqa: F821 # fmt: skip + return TKR[Circuit] # noqa: F821 # fmt: skip @property def namespace(self) -> str: @@ -163,7 +188,7 @@ def namespace(self) -> str: class expectation(NamedTuple): - backend_result: TKR[OpaqueType["pytket.backends.backendresult.BackendResult"]] # noqa: F821 # fmt: skip + backend_result: TKR[BackendResult] # noqa: F821 # fmt: skip @staticmethod def out() -> type[TKR[float]]: # noqa: F821 # fmt: skip @@ -175,7 +200,7 @@ def namespace(self) -> str: class n_qubits(NamedTuple): - circuit: TKR[OpaqueType["pytket._tket.circuit.Circuit"]] # noqa: F821 # fmt: skip + circuit: TKR[Circuit] # noqa: F821 # fmt: skip @staticmethod def out() -> type[TKR[int]]: # noqa: F821 # fmt: skip @@ -187,7 +212,7 @@ def namespace(self) -> str: class backend_result_to_dict(NamedTuple): - backend_result: TKR[OpaqueType["pytket.backends.backendresult.BackendResult"]] # noqa: F821 # fmt: skip + backend_result: TKR[BackendResult] # noqa: F821 # fmt: skip @staticmethod def out() -> type[TKR[dict[str, list[str]]]]: # noqa: F821 # fmt: skip @@ -202,8 +227,8 @@ class backend_result_from_dict(NamedTuple): data: TKR[dict[str, list[str]]] # noqa: F821 # fmt: skip @staticmethod - def out() -> type[TKR[OpaqueType["pytket.backends.backendresult.BackendResult"]]]: # noqa: F821 # fmt: skip - return TKR[OpaqueType["pytket.backends.backendresult.BackendResult"]] # noqa: F821 # fmt: skip + def out() -> type[TKR[BackendResult]]: # noqa: F821 # fmt: skip + return TKR[BackendResult] # noqa: F821 # fmt: skip @property def namespace(self) -> str: diff --git a/tierkreis/tierkreis/quantinuum_worker.py b/tierkreis/tierkreis/quantinuum_worker.py index ed0eb5704..d0e134914 100644 --- a/tierkreis/tierkreis/quantinuum_worker.py +++ b/tierkreis/tierkreis/quantinuum_worker.py @@ -1,15 +1,20 @@ """Code generated from quantinuum_worker namespace. Please do not edit.""" -from typing import NamedTuple -from tierkreis.controller.data.models import TKR, OpaqueType +from typing import Literal, NamedTuple +from tierkreis.controller.data.models import TKR + +type BackendInfo = Literal["pytket.backends.backendinfo.BackendInfo"] +type Circuit = Literal["pytket._tket.circuit.Circuit"] +type BasePass = Literal["pytket._tket.passes.BasePass"] +type BackendResult = Literal["pytket.backends.backendresult.BackendResult"] class get_backend_info(NamedTuple): device_name: TKR[str] # noqa: F821 # fmt: skip @staticmethod - def out() -> type[TKR[OpaqueType["pytket.backends.backendinfo.BackendInfo"]]]: # noqa: F821 # fmt: skip - return TKR[OpaqueType["pytket.backends.backendinfo.BackendInfo"]] # noqa: F821 # fmt: skip + def out() -> type[TKR[BackendInfo]]: # noqa: F821 # fmt: skip + return TKR[BackendInfo] # noqa: F821 # fmt: skip @property def namespace(self) -> str: @@ -17,13 +22,13 @@ def namespace(self) -> str: class compile_using_info(NamedTuple): - circuit: TKR[OpaqueType["pytket._tket.circuit.Circuit"]] # noqa: F821 # fmt: skip - backend_info: TKR[OpaqueType["pytket.backends.backendinfo.BackendInfo"]] # noqa: F821 # fmt: skip + circuit: TKR[Circuit] # noqa: F821 # fmt: skip + backend_info: TKR[BackendInfo] # noqa: F821 # fmt: skip optimisation_level: TKR[int] | None = None # noqa: F821 # fmt: skip @staticmethod - def out() -> type[TKR[OpaqueType["pytket._tket.circuit.Circuit"]]]: # noqa: F821 # fmt: skip - return TKR[OpaqueType["pytket._tket.circuit.Circuit"]] # noqa: F821 # fmt: skip + def out() -> type[TKR[Circuit]]: # noqa: F821 # fmt: skip + return TKR[Circuit] # noqa: F821 # fmt: skip @property def namespace(self) -> str: @@ -31,12 +36,12 @@ def namespace(self) -> str: class backend_pass_from_info(NamedTuple): - backend_info: TKR[OpaqueType["pytket.backends.backendinfo.BackendInfo"]] # noqa: F821 # fmt: skip + backend_info: TKR[BackendInfo] # noqa: F821 # fmt: skip optimisation_level: TKR[int] | None = None # noqa: F821 # fmt: skip @staticmethod - def out() -> type[TKR[OpaqueType["pytket._tket.passes.BasePass"]]]: # noqa: F821 # fmt: skip - return TKR[OpaqueType["pytket._tket.passes.BasePass"]] # noqa: F821 # fmt: skip + def out() -> type[TKR[BasePass]]: # noqa: F821 # fmt: skip + return TKR[BasePass] # noqa: F821 # fmt: skip @property def namespace(self) -> str: @@ -45,8 +50,8 @@ def namespace(self) -> str: class fixed_pass(NamedTuple): @staticmethod - def out() -> type[TKR[OpaqueType["pytket._tket.passes.BasePass"]]]: # noqa: F821 # fmt: skip - return TKR[OpaqueType["pytket._tket.passes.BasePass"]] # noqa: F821 # fmt: skip + def out() -> type[TKR[BasePass]]: # noqa: F821 # fmt: skip + return TKR[BasePass] # noqa: F821 # fmt: skip @property def namespace(self) -> str: @@ -54,11 +59,11 @@ def namespace(self) -> str: class compile_circuit_quantinuum(NamedTuple): - circuit: TKR[OpaqueType["pytket._tket.circuit.Circuit"]] # noqa: F821 # fmt: skip + circuit: TKR[Circuit] # noqa: F821 # fmt: skip @staticmethod - def out() -> type[TKR[OpaqueType["pytket._tket.circuit.Circuit"]]]: # noqa: F821 # fmt: skip - return TKR[OpaqueType["pytket._tket.circuit.Circuit"]] # noqa: F821 # fmt: skip + def out() -> type[TKR[Circuit]]: # noqa: F821 # fmt: skip + return TKR[Circuit] # noqa: F821 # fmt: skip @property def namespace(self) -> str: @@ -66,11 +71,11 @@ def namespace(self) -> str: class compile_circuits_quantinuum(NamedTuple): - circuits: TKR[list[OpaqueType["pytket._tket.circuit.Circuit"]]] # noqa: F821 # fmt: skip + circuits: TKR[list[Circuit]] # noqa: F821 # fmt: skip @staticmethod - def out() -> type[TKR[list[OpaqueType["pytket._tket.circuit.Circuit"]]]]: # noqa: F821 # fmt: skip - return TKR[list[OpaqueType["pytket._tket.circuit.Circuit"]]] # noqa: F821 # fmt: skip + def out() -> type[TKR[list[Circuit]]]: # noqa: F821 # fmt: skip + return TKR[list[Circuit]] # noqa: F821 # fmt: skip @property def namespace(self) -> str: @@ -78,13 +83,13 @@ def namespace(self) -> str: class run_circuit(NamedTuple): - circuit: TKR[OpaqueType["pytket._tket.circuit.Circuit"]] # noqa: F821 # fmt: skip + circuit: TKR[Circuit] # noqa: F821 # fmt: skip n_shots: TKR[int] # noqa: F821 # fmt: skip device_name: TKR[str] # noqa: F821 # fmt: skip @staticmethod - def out() -> type[TKR[OpaqueType["pytket.backends.backendresult.BackendResult"]]]: # noqa: F821 # fmt: skip - return TKR[OpaqueType["pytket.backends.backendresult.BackendResult"]] # noqa: F821 # fmt: skip + def out() -> type[TKR[BackendResult]]: # noqa: F821 # fmt: skip + return TKR[BackendResult] # noqa: F821 # fmt: skip @property def namespace(self) -> str: diff --git a/tierkreis/tierkreis/qulacs_worker.py b/tierkreis/tierkreis/qulacs_worker.py index 441f87f69..a8b3680b7 100644 --- a/tierkreis/tierkreis/qulacs_worker.py +++ b/tierkreis/tierkreis/qulacs_worker.py @@ -1,19 +1,22 @@ """Code generated from qulacs_worker namespace. Please do not edit.""" -from typing import NamedTuple, Union +from typing import Literal, NamedTuple, Union from types import NoneType -from tierkreis.controller.data.models import TKR, OpaqueType +from tierkreis.controller.data.models import TKR + +type Circuit = Literal["pytket._tket.circuit.Circuit"] +type BackendResult = Literal["pytket.backends.backendresult.BackendResult"] class get_compiled_circuit(NamedTuple): - circuit: TKR[OpaqueType["pytket._tket.circuit.Circuit"]] # noqa: F821 # fmt: skip + circuit: TKR[Circuit] # noqa: F821 # fmt: skip optimisation_level: TKR[int] | None = None # noqa: F821 # fmt: skip result_type: TKR[str] | None = None # noqa: F821 # fmt: skip gpu_sim: TKR[bool] | None = None # noqa: F821 # fmt: skip @staticmethod - def out() -> type[TKR[OpaqueType["pytket._tket.circuit.Circuit"]]]: # noqa: F821 # fmt: skip - return TKR[OpaqueType["pytket._tket.circuit.Circuit"]] # noqa: F821 # fmt: skip + def out() -> type[TKR[Circuit]]: # noqa: F821 # fmt: skip + return TKR[Circuit] # noqa: F821 # fmt: skip @property def namespace(self) -> str: @@ -21,15 +24,15 @@ def namespace(self) -> str: class run_circuit(NamedTuple): - circuit: TKR[OpaqueType["pytket._tket.circuit.Circuit"]] # noqa: F821 # fmt: skip + circuit: TKR[Circuit] # noqa: F821 # fmt: skip n_shots: TKR[int] # noqa: F821 # fmt: skip result_type: TKR[str] | None = None # noqa: F821 # fmt: skip gpu_sim: TKR[bool] | None = None # noqa: F821 # fmt: skip seed: TKR[Union[int, NoneType]] | None = None # noqa: F821 # fmt: skip @staticmethod - def out() -> type[TKR[OpaqueType["pytket.backends.backendresult.BackendResult"]]]: # noqa: F821 # fmt: skip - return TKR[OpaqueType["pytket.backends.backendresult.BackendResult"]] # noqa: F821 # fmt: skip + def out() -> type[TKR[BackendResult]]: # noqa: F821 # fmt: skip + return TKR[BackendResult] # noqa: F821 # fmt: skip @property def namespace(self) -> str: @@ -37,15 +40,15 @@ def namespace(self) -> str: class run_circuits(NamedTuple): - circuits: TKR[list[OpaqueType["pytket._tket.circuit.Circuit"]]] # noqa: F821 # fmt: skip + circuits: TKR[list[Circuit]] # noqa: F821 # fmt: skip n_shots: TKR[list[int]] # noqa: F821 # fmt: skip result_type: TKR[str] | None = None # noqa: F821 # fmt: skip gpu_sim: TKR[bool] | None = None # noqa: F821 # fmt: skip seed: TKR[Union[int, NoneType]] | None = None # noqa: F821 # fmt: skip @staticmethod - def out() -> type[TKR[list[OpaqueType["pytket.backends.backendresult.BackendResult"]]]]: # noqa: F821 # fmt: skip - return TKR[list[OpaqueType["pytket.backends.backendresult.BackendResult"]]] # noqa: F821 # fmt: skip + def out() -> type[TKR[list[BackendResult]]]: # noqa: F821 # fmt: skip + return TKR[list[BackendResult]] # noqa: F821 # fmt: skip @property def namespace(self) -> str: diff --git a/tierkreis_workers/aer_worker/api/api.py b/tierkreis_workers/aer_worker/api/api.py index 489897422..c6ca46d34 100644 --- a/tierkreis_workers/aer_worker/api/api.py +++ b/tierkreis_workers/aer_worker/api/api.py @@ -1,20 +1,23 @@ """Code generated from aer_worker namespace. Please do not edit.""" -from typing import NamedTuple, Union +from typing import Literal, NamedTuple, Union from types import NoneType -from tierkreis.controller.data.models import TKR, OpaqueType +from tierkreis.controller.data.models import TKR + +type Circuit = Literal["pytket._tket.circuit.Circuit"] +type BackendResult = Literal["pytket.backends.backendresult.BackendResult"] class get_compiled_circuit(NamedTuple): - circuit: TKR[OpaqueType["pytket._tket.circuit.Circuit"]] # noqa: F821 # fmt: skip + circuit: TKR[Circuit] # noqa: F821 # fmt: skip optimisation_level: TKR[int] | None = None # noqa: F821 # fmt: skip timeout: TKR[int] | None = None # noqa: F821 # fmt: skip simulation_method: TKR[str] | None = None # noqa: F821 # fmt: skip n_qubits: TKR[int] | None = None # noqa: F821 # fmt: skip @staticmethod - def out() -> type[TKR[OpaqueType["pytket._tket.circuit.Circuit"]]]: # noqa: F821 # fmt: skip - return TKR[OpaqueType["pytket._tket.circuit.Circuit"]] # noqa: F821 # fmt: skip + def out() -> type[TKR[Circuit]]: # noqa: F821 # fmt: skip + return TKR[Circuit] # noqa: F821 # fmt: skip @property def namespace(self) -> str: @@ -22,15 +25,15 @@ def namespace(self) -> str: class run_circuit(NamedTuple): - circuit: TKR[OpaqueType["pytket._tket.circuit.Circuit"]] # noqa: F821 # fmt: skip + circuit: TKR[Circuit] # noqa: F821 # fmt: skip n_shots: TKR[int] # noqa: F821 # fmt: skip simulation_method: TKR[str] | None = None # noqa: F821 # fmt: skip n_qubits: TKR[int] | None = None # noqa: F821 # fmt: skip seed: TKR[Union[int, NoneType]] | None = None # noqa: F821 # fmt: skip @staticmethod - def out() -> type[TKR[OpaqueType["pytket.backends.backendresult.BackendResult"]]]: # noqa: F821 # fmt: skip - return TKR[OpaqueType["pytket.backends.backendresult.BackendResult"]] # noqa: F821 # fmt: skip + def out() -> type[TKR[BackendResult]]: # noqa: F821 # fmt: skip + return TKR[BackendResult] # noqa: F821 # fmt: skip @property def namespace(self) -> str: @@ -38,15 +41,15 @@ def namespace(self) -> str: class run_circuits(NamedTuple): - circuits: TKR[list[OpaqueType["pytket._tket.circuit.Circuit"]]] # noqa: F821 # fmt: skip + circuits: TKR[list[Circuit]] # noqa: F821 # fmt: skip n_shots: TKR[list[int]] # noqa: F821 # fmt: skip simulation_method: TKR[str] | None = None # noqa: F821 # fmt: skip n_qubits: TKR[int] | None = None # noqa: F821 # fmt: skip seed: TKR[Union[int, NoneType]] | None = None # noqa: F821 # fmt: skip @staticmethod - def out() -> type[TKR[list[OpaqueType["pytket.backends.backendresult.BackendResult"]]]]: # noqa: F821 # fmt: skip - return TKR[list[OpaqueType["pytket.backends.backendresult.BackendResult"]]] # noqa: F821 # fmt: skip + def out() -> type[TKR[list[BackendResult]]]: # noqa: F821 # fmt: skip + return TKR[list[BackendResult]] # noqa: F821 # fmt: skip @property def namespace(self) -> str: @@ -54,7 +57,7 @@ def namespace(self) -> str: class to_qasm3_str(NamedTuple): - circuit: TKR[OpaqueType["pytket._tket.circuit.Circuit"]] # noqa: F821 # fmt: skip + circuit: TKR[Circuit] # noqa: F821 # fmt: skip @staticmethod def out() -> type[TKR[str]]: # noqa: F821 # fmt: skip @@ -66,12 +69,12 @@ def namespace(self) -> str: class submit(NamedTuple): - circuits: TKR[list[OpaqueType["pytket._tket.circuit.Circuit"]]] # noqa: F821 # fmt: skip + circuits: TKR[list[Circuit]] # noqa: F821 # fmt: skip n_shots: TKR[int] # noqa: F821 # fmt: skip @staticmethod - def out() -> type[TKR[list[OpaqueType["pytket.backends.backendresult.BackendResult"]]]]: # noqa: F821 # fmt: skip - return TKR[list[OpaqueType["pytket.backends.backendresult.BackendResult"]]] # noqa: F821 # fmt: skip + def out() -> type[TKR[list[BackendResult]]]: # noqa: F821 # fmt: skip + return TKR[list[BackendResult]] # noqa: F821 # fmt: skip @property def namespace(self) -> str: @@ -79,12 +82,12 @@ def namespace(self) -> str: class submit_single(NamedTuple): - circuit: TKR[OpaqueType["pytket._tket.circuit.Circuit"]] # noqa: F821 # fmt: skip + circuit: TKR[Circuit] # noqa: F821 # fmt: skip n_shots: TKR[int] # noqa: F821 # fmt: skip @staticmethod - def out() -> type[TKR[OpaqueType["pytket.backends.backendresult.BackendResult"]]]: # noqa: F821 # fmt: skip - return TKR[OpaqueType["pytket.backends.backendresult.BackendResult"]] # noqa: F821 # fmt: skip + def out() -> type[TKR[BackendResult]]: # noqa: F821 # fmt: skip + return TKR[BackendResult] # noqa: F821 # fmt: skip @property def namespace(self) -> str: diff --git a/tierkreis_workers/ibmq_worker/api/api.py b/tierkreis_workers/ibmq_worker/api/api.py index 57e3b7dae..6cc832d3f 100644 --- a/tierkreis_workers/ibmq_worker/api/api.py +++ b/tierkreis_workers/ibmq_worker/api/api.py @@ -1,15 +1,20 @@ """Code generated from ibmq_worker namespace. Please do not edit.""" -from typing import NamedTuple, Sequence -from tierkreis.controller.data.models import TKR, OpaqueType +from typing import Literal, NamedTuple, Sequence +from tierkreis.controller.data.models import TKR + +type BackendInfo = Literal["pytket.backends.backendinfo.BackendInfo"] +type BasePass = Literal["pytket._tket.passes.BasePass"] +type Circuit = Literal["pytket._tket.circuit.Circuit"] +type BackendResult = Literal["pytket.backends.backendresult.BackendResult"] class get_backend_info(NamedTuple): device_name: TKR[str] # noqa: F821 # fmt: skip @staticmethod - def out() -> type[TKR[OpaqueType["pytket.backends.backendinfo.BackendInfo"]]]: # noqa: F821 # fmt: skip - return TKR[OpaqueType["pytket.backends.backendinfo.BackendInfo"]] # noqa: F821 # fmt: skip + def out() -> type[TKR[BackendInfo]]: # noqa: F821 # fmt: skip + return TKR[BackendInfo] # noqa: F821 # fmt: skip @property def namespace(self) -> str: @@ -17,12 +22,12 @@ def namespace(self) -> str: class backend_pass_from_info(NamedTuple): - backend_info: TKR[OpaqueType["pytket.backends.backendinfo.BackendInfo"]] # noqa: F821 # fmt: skip + backend_info: TKR[BackendInfo] # noqa: F821 # fmt: skip optimisation_level: TKR[int] | None = None # noqa: F821 # fmt: skip @staticmethod - def out() -> type[TKR[OpaqueType["pytket._tket.passes.BasePass"]]]: # noqa: F821 # fmt: skip - return TKR[OpaqueType["pytket._tket.passes.BasePass"]] # noqa: F821 # fmt: skip + def out() -> type[TKR[BasePass]]: # noqa: F821 # fmt: skip + return TKR[BasePass] # noqa: F821 # fmt: skip @property def namespace(self) -> str: @@ -34,8 +39,8 @@ class backend_default_compilation_pass(NamedTuple): optimisation_level: TKR[int] | None = None # noqa: F821 # fmt: skip @staticmethod - def out() -> type[TKR[OpaqueType["pytket._tket.passes.BasePass"]]]: # noqa: F821 # fmt: skip - return TKR[OpaqueType["pytket._tket.passes.BasePass"]] # noqa: F821 # fmt: skip + def out() -> type[TKR[BasePass]]: # noqa: F821 # fmt: skip + return TKR[BasePass] # noqa: F821 # fmt: skip @property def namespace(self) -> str: @@ -47,8 +52,8 @@ class fixed_pass(NamedTuple): optimisation_level: TKR[int] | None = None # noqa: F821 # fmt: skip @staticmethod - def out() -> type[TKR[OpaqueType["pytket._tket.passes.BasePass"]]]: # noqa: F821 # fmt: skip - return TKR[OpaqueType["pytket._tket.passes.BasePass"]] # noqa: F821 # fmt: skip + def out() -> type[TKR[BasePass]]: # noqa: F821 # fmt: skip + return TKR[BasePass] # noqa: F821 # fmt: skip @property def namespace(self) -> str: @@ -56,13 +61,13 @@ def namespace(self) -> str: class compile(NamedTuple): - circuit: TKR[OpaqueType["pytket._tket.circuit.Circuit"]] # noqa: F821 # fmt: skip + circuit: TKR[Circuit] # noqa: F821 # fmt: skip device_name: TKR[str] # noqa: F821 # fmt: skip optimisation_level: TKR[int] | None = None # noqa: F821 # fmt: skip @staticmethod - def out() -> type[TKR[OpaqueType["pytket._tket.circuit.Circuit"]]]: # noqa: F821 # fmt: skip - return TKR[OpaqueType["pytket._tket.circuit.Circuit"]] # noqa: F821 # fmt: skip + def out() -> type[TKR[Circuit]]: # noqa: F821 # fmt: skip + return TKR[Circuit] # noqa: F821 # fmt: skip @property def namespace(self) -> str: @@ -70,13 +75,13 @@ def namespace(self) -> str: class compile_circuit_ibmq(NamedTuple): - circuit: TKR[OpaqueType["pytket._tket.circuit.Circuit"]] # noqa: F821 # fmt: skip + circuit: TKR[Circuit] # noqa: F821 # fmt: skip device_name: TKR[str] # noqa: F821 # fmt: skip optimisation_level: TKR[int] | None = None # noqa: F821 # fmt: skip @staticmethod - def out() -> type[TKR[OpaqueType["pytket._tket.circuit.Circuit"]]]: # noqa: F821 # fmt: skip - return TKR[OpaqueType["pytket._tket.circuit.Circuit"]] # noqa: F821 # fmt: skip + def out() -> type[TKR[Circuit]]: # noqa: F821 # fmt: skip + return TKR[Circuit] # noqa: F821 # fmt: skip @property def namespace(self) -> str: @@ -84,13 +89,13 @@ def namespace(self) -> str: class compile_circuits_ibmq(NamedTuple): - circuits: TKR[list[OpaqueType["pytket._tket.circuit.Circuit"]]] # noqa: F821 # fmt: skip + circuits: TKR[list[Circuit]] # noqa: F821 # fmt: skip device_name: TKR[str] # noqa: F821 # fmt: skip optimisation_level: TKR[int] | None = None # noqa: F821 # fmt: skip @staticmethod - def out() -> type[TKR[list[OpaqueType["pytket._tket.circuit.Circuit"]]]]: # noqa: F821 # fmt: skip - return TKR[list[OpaqueType["pytket._tket.circuit.Circuit"]]] # noqa: F821 # fmt: skip + def out() -> type[TKR[list[Circuit]]]: # noqa: F821 # fmt: skip + return TKR[list[Circuit]] # noqa: F821 # fmt: skip @property def namespace(self) -> str: @@ -98,13 +103,13 @@ def namespace(self) -> str: class run_circuit(NamedTuple): - circuit: TKR[OpaqueType["pytket._tket.circuit.Circuit"]] # noqa: F821 # fmt: skip + circuit: TKR[Circuit] # noqa: F821 # fmt: skip n_shots: TKR[int] # noqa: F821 # fmt: skip device_name: TKR[str] # noqa: F821 # fmt: skip @staticmethod - def out() -> type[TKR[OpaqueType["pytket.backends.backendresult.BackendResult"]]]: # noqa: F821 # fmt: skip - return TKR[OpaqueType["pytket.backends.backendresult.BackendResult"]] # noqa: F821 # fmt: skip + def out() -> type[TKR[BackendResult]]: # noqa: F821 # fmt: skip + return TKR[BackendResult] # noqa: F821 # fmt: skip @property def namespace(self) -> str: diff --git a/tierkreis_workers/nexus_worker/api/api.py b/tierkreis_workers/nexus_worker/api/api.py index f0a3f772e..4dbc8c38b 100644 --- a/tierkreis_workers/nexus_worker/api/api.py +++ b/tierkreis_workers/nexus_worker/api/api.py @@ -1,16 +1,42 @@ """Code generated from nexus_worker namespace. Please do not edit.""" -from typing import NamedTuple, Union -from tierkreis.controller.data.models import TKR, OpaqueType +from typing import Literal, NamedTuple, Union +from tierkreis.controller.data.models import TKR + +type Circuit = Literal["pytket._tket.circuit.Circuit"] +type CircuitRef = Literal["qnexus.models.references.CircuitRef"] +type HUGRRef = Literal["qnexus.models.references.HUGRRef"] +type QIRRef = Literal["qnexus.models.references.QIRRef"] +type AerConfig = Literal["quantinuum_schemas.models.backend_config.AerConfig"] +type AerStateConfig = Literal["quantinuum_schemas.models.backend_config.AerStateConfig"] +type AerUnitaryConfig = Literal[ + "quantinuum_schemas.models.backend_config.AerUnitaryConfig" +] +type BraketConfig = Literal["quantinuum_schemas.models.backend_config.BraketConfig"] +type QuantinuumConfig = Literal[ + "quantinuum_schemas.models.backend_config.QuantinuumConfig" +] +type IBMQConfig = Literal["quantinuum_schemas.models.backend_config.IBMQConfig"] +type IBMQEmulatorConfig = Literal[ + "quantinuum_schemas.models.backend_config.IBMQEmulatorConfig" +] +type QulacsConfig = Literal["quantinuum_schemas.models.backend_config.QulacsConfig"] +type SeleneConfig = Literal["quantinuum_schemas.models.backend_config.SeleneConfig"] +type SelenePlusConfig = Literal[ + "quantinuum_schemas.models.backend_config.SelenePlusConfig" +] +type HeliosConfig = Literal["quantinuum_schemas.models.backend_config.HeliosConfig"] +type ExecuteJobRef = Literal["qnexus.models.references.ExecuteJobRef"] +type BackendResult = Literal["pytket.backends.backendresult.BackendResult"] class upload_circuit(NamedTuple): project_name: TKR[str] # noqa: F821 # fmt: skip - circ: TKR[OpaqueType["pytket._tket.circuit.Circuit"]] # noqa: F821 # fmt: skip + circ: TKR[Circuit] # noqa: F821 # fmt: skip @staticmethod - def out() -> type[TKR[Union[OpaqueType["qnexus.models.references.CircuitRef"], OpaqueType["qnexus.models.references.HUGRRef"], OpaqueType["qnexus.models.references.QIRRef"]]]]: # noqa: F821 # fmt: skip - return TKR[Union[OpaqueType["qnexus.models.references.CircuitRef"], OpaqueType["qnexus.models.references.HUGRRef"], OpaqueType["qnexus.models.references.QIRRef"]]] # noqa: F821 # fmt: skip + def out() -> type[TKR[Union[CircuitRef, HUGRRef, QIRRef]]]: # noqa: F821 # fmt: skip + return TKR[Union[CircuitRef, HUGRRef, QIRRef]] # noqa: F821 # fmt: skip @property def namespace(self) -> str: @@ -20,13 +46,13 @@ def namespace(self) -> str: class start_execute_job(NamedTuple): project_name: TKR[str] # noqa: F821 # fmt: skip job_name: TKR[str] # noqa: F821 # fmt: skip - circuits: TKR[list[Union[OpaqueType["qnexus.models.references.CircuitRef"], OpaqueType["qnexus.models.references.HUGRRef"], OpaqueType["qnexus.models.references.QIRRef"]]]] # noqa: F821 # fmt: skip + circuits: TKR[list[Union[CircuitRef, HUGRRef, QIRRef]]] # noqa: F821 # fmt: skip n_shots: TKR[list[int]] # noqa: F821 # fmt: skip - backend_config: TKR[Union[OpaqueType["quantinuum_schemas.models.backend_config.AerConfig"], OpaqueType["quantinuum_schemas.models.backend_config.AerStateConfig"], OpaqueType["quantinuum_schemas.models.backend_config.AerUnitaryConfig"], OpaqueType["quantinuum_schemas.models.backend_config.BraketConfig"], OpaqueType["quantinuum_schemas.models.backend_config.QuantinuumConfig"], OpaqueType["quantinuum_schemas.models.backend_config.IBMQConfig"], OpaqueType["quantinuum_schemas.models.backend_config.IBMQEmulatorConfig"], OpaqueType["quantinuum_schemas.models.backend_config.QulacsConfig"], OpaqueType["quantinuum_schemas.models.backend_config.SeleneConfig"], OpaqueType["quantinuum_schemas.models.backend_config.SelenePlusConfig"], OpaqueType["quantinuum_schemas.models.backend_config.HeliosConfig"]]] # noqa: F821 # fmt: skip + backend_config: TKR[Union[AerConfig, AerStateConfig, AerUnitaryConfig, BraketConfig, QuantinuumConfig, IBMQConfig, IBMQEmulatorConfig, QulacsConfig, SeleneConfig, SelenePlusConfig, HeliosConfig]] # noqa: F821 # fmt: skip @staticmethod - def out() -> type[TKR[OpaqueType["qnexus.models.references.ExecuteJobRef"]]]: # noqa: F821 # fmt: skip - return TKR[OpaqueType["qnexus.models.references.ExecuteJobRef"]] # noqa: F821 # fmt: skip + def out() -> type[TKR[ExecuteJobRef]]: # noqa: F821 # fmt: skip + return TKR[ExecuteJobRef] # noqa: F821 # fmt: skip @property def namespace(self) -> str: @@ -34,7 +60,7 @@ def namespace(self) -> str: class is_running(NamedTuple): - execute_ref: TKR[OpaqueType["qnexus.models.references.ExecuteJobRef"]] # noqa: F821 # fmt: skip + execute_ref: TKR[ExecuteJobRef] # noqa: F821 # fmt: skip @staticmethod def out() -> type[TKR[bool]]: # noqa: F821 # fmt: skip @@ -46,11 +72,11 @@ def namespace(self) -> str: class get_results(NamedTuple): - execute_ref: TKR[OpaqueType["qnexus.models.references.ExecuteJobRef"]] # noqa: F821 # fmt: skip + execute_ref: TKR[ExecuteJobRef] # noqa: F821 # fmt: skip @staticmethod - def out() -> type[TKR[list[OpaqueType["pytket.backends.backendresult.BackendResult"]]]]: # noqa: F821 # fmt: skip - return TKR[list[OpaqueType["pytket.backends.backendresult.BackendResult"]]] # noqa: F821 # fmt: skip + def out() -> type[TKR[list[BackendResult]]]: # noqa: F821 # fmt: skip + return TKR[list[BackendResult]] # noqa: F821 # fmt: skip @property def namespace(self) -> str: @@ -58,7 +84,7 @@ def namespace(self) -> str: class check_status(NamedTuple): - execute_ref: TKR[OpaqueType["qnexus.models.references.ExecuteJobRef"]] # noqa: F821 # fmt: skip + execute_ref: TKR[ExecuteJobRef] # noqa: F821 # fmt: skip @staticmethod def out() -> type[TKR[str]]: # noqa: F821 # fmt: skip @@ -70,12 +96,12 @@ def namespace(self) -> str: class submit(NamedTuple): - circuits: TKR[list[OpaqueType["pytket._tket.circuit.Circuit"]]] # noqa: F821 # fmt: skip + circuits: TKR[list[Circuit]] # noqa: F821 # fmt: skip n_shots: TKR[int] # noqa: F821 # fmt: skip @staticmethod - def out() -> type[TKR[OpaqueType["qnexus.models.references.ExecuteJobRef"]]]: # noqa: F821 # fmt: skip - return TKR[OpaqueType["qnexus.models.references.ExecuteJobRef"]] # noqa: F821 # fmt: skip + def out() -> type[TKR[ExecuteJobRef]]: # noqa: F821 # fmt: skip + return TKR[ExecuteJobRef] # noqa: F821 # fmt: skip @property def namespace(self) -> str: diff --git a/tierkreis_workers/pytket_worker/api/api.py b/tierkreis_workers/pytket_worker/api/api.py index 3ada52093..aec1b713b 100644 --- a/tierkreis_workers/pytket_worker/api/api.py +++ b/tierkreis_workers/pytket_worker/api/api.py @@ -1,16 +1,41 @@ """Code generated from pytket_worker namespace. Please do not edit.""" -from typing import NamedTuple, Union +from typing import Literal, NamedTuple, Union from types import NoneType -from tierkreis.controller.data.models import TKR, OpaqueType +from tierkreis.controller.data.models import TKR + +type AerConfig = Literal["quantinuum_schemas.models.backend_config.AerConfig"] +type AerStateConfig = Literal["quantinuum_schemas.models.backend_config.AerStateConfig"] +type AerUnitaryConfig = Literal[ + "quantinuum_schemas.models.backend_config.AerUnitaryConfig" +] +type BraketConfig = Literal["quantinuum_schemas.models.backend_config.BraketConfig"] +type QuantinuumConfig = Literal[ + "quantinuum_schemas.models.backend_config.QuantinuumConfig" +] +type IBMQConfig = Literal["quantinuum_schemas.models.backend_config.IBMQConfig"] +type IBMQEmulatorConfig = Literal[ + "quantinuum_schemas.models.backend_config.IBMQEmulatorConfig" +] +type QulacsConfig = Literal["quantinuum_schemas.models.backend_config.QulacsConfig"] +type SeleneConfig = Literal["quantinuum_schemas.models.backend_config.SeleneConfig"] +type SelenePlusConfig = Literal[ + "quantinuum_schemas.models.backend_config.SelenePlusConfig" +] +type HeliosConfig = Literal["quantinuum_schemas.models.backend_config.HeliosConfig"] +type BackendInfo = Literal["pytket.backends.backendinfo.BackendInfo"] +type Circuit = Literal["pytket._tket.circuit.Circuit"] +type QubitPauliString = Literal["pytket._tket.pauli.QubitPauliString"] +type BasePass = Literal["pytket._tket.passes.BasePass"] +type BackendResult = Literal["pytket.backends.backendresult.BackendResult"] class get_backend_info(NamedTuple): - config: TKR[Union[OpaqueType["quantinuum_schemas.models.backend_config.AerConfig"], OpaqueType["quantinuum_schemas.models.backend_config.AerStateConfig"], OpaqueType["quantinuum_schemas.models.backend_config.AerUnitaryConfig"], OpaqueType["quantinuum_schemas.models.backend_config.BraketConfig"], OpaqueType["quantinuum_schemas.models.backend_config.QuantinuumConfig"], OpaqueType["quantinuum_schemas.models.backend_config.IBMQConfig"], OpaqueType["quantinuum_schemas.models.backend_config.IBMQEmulatorConfig"], OpaqueType["quantinuum_schemas.models.backend_config.QulacsConfig"], OpaqueType["quantinuum_schemas.models.backend_config.SeleneConfig"], OpaqueType["quantinuum_schemas.models.backend_config.SelenePlusConfig"], OpaqueType["quantinuum_schemas.models.backend_config.HeliosConfig"]]] # noqa: F821 # fmt: skip + config: TKR[Union[AerConfig, AerStateConfig, AerUnitaryConfig, BraketConfig, QuantinuumConfig, IBMQConfig, IBMQEmulatorConfig, QulacsConfig, SeleneConfig, SelenePlusConfig, HeliosConfig]] # noqa: F821 # fmt: skip @staticmethod - def out() -> type[TKR[OpaqueType["pytket.backends.backendinfo.BackendInfo"]]]: # noqa: F821 # fmt: skip - return TKR[OpaqueType["pytket.backends.backendinfo.BackendInfo"]] # noqa: F821 # fmt: skip + def out() -> type[TKR[BackendInfo]]: # noqa: F821 # fmt: skip + return TKR[BackendInfo] # noqa: F821 # fmt: skip @property def namespace(self) -> str: @@ -18,7 +43,7 @@ def namespace(self) -> str: class device_name_from_info(NamedTuple): - backend_info: TKR[OpaqueType["pytket.backends.backendinfo.BackendInfo"]] # noqa: F821 # fmt: skip + backend_info: TKR[BackendInfo] # noqa: F821 # fmt: skip @staticmethod def out() -> type[TKR[Union[str, NoneType]]]: # noqa: F821 # fmt: skip @@ -30,15 +55,15 @@ def namespace(self) -> str: class compile_using_info(NamedTuple): - circuit: TKR[OpaqueType["pytket._tket.circuit.Circuit"]] # noqa: F821 # fmt: skip - backend_info: TKR[OpaqueType["pytket.backends.backendinfo.BackendInfo"]] # noqa: F821 # fmt: skip - config: TKR[Union[OpaqueType["quantinuum_schemas.models.backend_config.AerConfig"], OpaqueType["quantinuum_schemas.models.backend_config.AerStateConfig"], OpaqueType["quantinuum_schemas.models.backend_config.AerUnitaryConfig"], OpaqueType["quantinuum_schemas.models.backend_config.BraketConfig"], OpaqueType["quantinuum_schemas.models.backend_config.QuantinuumConfig"], OpaqueType["quantinuum_schemas.models.backend_config.IBMQConfig"], OpaqueType["quantinuum_schemas.models.backend_config.IBMQEmulatorConfig"], OpaqueType["quantinuum_schemas.models.backend_config.QulacsConfig"], OpaqueType["quantinuum_schemas.models.backend_config.SeleneConfig"], OpaqueType["quantinuum_schemas.models.backend_config.SelenePlusConfig"], OpaqueType["quantinuum_schemas.models.backend_config.HeliosConfig"]]] # noqa: F821 # fmt: skip + circuit: TKR[Circuit] # noqa: F821 # fmt: skip + backend_info: TKR[BackendInfo] # noqa: F821 # fmt: skip + config: TKR[Union[AerConfig, AerStateConfig, AerUnitaryConfig, BraketConfig, QuantinuumConfig, IBMQConfig, IBMQEmulatorConfig, QulacsConfig, SeleneConfig, SelenePlusConfig, HeliosConfig]] # noqa: F821 # fmt: skip optimisation_level: TKR[int] | None = None # noqa: F821 # fmt: skip timeout: TKR[int] | None = None # noqa: F821 # fmt: skip @staticmethod - def out() -> type[TKR[OpaqueType["pytket._tket.circuit.Circuit"]]]: # noqa: F821 # fmt: skip - return TKR[OpaqueType["pytket._tket.circuit.Circuit"]] # noqa: F821 # fmt: skip + def out() -> type[TKR[Circuit]]: # noqa: F821 # fmt: skip + return TKR[Circuit] # noqa: F821 # fmt: skip @property def namespace(self) -> str: @@ -46,11 +71,11 @@ def namespace(self) -> str: class add_measure_all(NamedTuple): - circuit: TKR[OpaqueType["pytket._tket.circuit.Circuit"]] # noqa: F821 # fmt: skip + circuit: TKR[Circuit] # noqa: F821 # fmt: skip @staticmethod - def out() -> type[TKR[OpaqueType["pytket._tket.circuit.Circuit"]]]: # noqa: F821 # fmt: skip - return TKR[OpaqueType["pytket._tket.circuit.Circuit"]] # noqa: F821 # fmt: skip + def out() -> type[TKR[Circuit]]: # noqa: F821 # fmt: skip + return TKR[Circuit] # noqa: F821 # fmt: skip @property def namespace(self) -> str: @@ -58,12 +83,12 @@ def namespace(self) -> str: class append_pauli_measurement_impl(NamedTuple): - circuit: TKR[OpaqueType["pytket._tket.circuit.Circuit"]] # noqa: F821 # fmt: skip - pauli_string: TKR[OpaqueType["pytket._tket.pauli.QubitPauliString"]] # noqa: F821 # fmt: skip + circuit: TKR[Circuit] # noqa: F821 # fmt: skip + pauli_string: TKR[QubitPauliString] # noqa: F821 # fmt: skip @staticmethod - def out() -> type[TKR[OpaqueType["pytket._tket.circuit.Circuit"]]]: # noqa: F821 # fmt: skip - return TKR[OpaqueType["pytket._tket.circuit.Circuit"]] # noqa: F821 # fmt: skip + def out() -> type[TKR[Circuit]]: # noqa: F821 # fmt: skip + return TKR[Circuit] # noqa: F821 # fmt: skip @property def namespace(self) -> str: @@ -71,11 +96,11 @@ def namespace(self) -> str: class optimise_phase_gadgets(NamedTuple): - circuit: TKR[OpaqueType["pytket._tket.circuit.Circuit"]] # noqa: F821 # fmt: skip + circuit: TKR[Circuit] # noqa: F821 # fmt: skip @staticmethod - def out() -> type[TKR[OpaqueType["pytket._tket.circuit.Circuit"]]]: # noqa: F821 # fmt: skip - return TKR[OpaqueType["pytket._tket.circuit.Circuit"]] # noqa: F821 # fmt: skip + def out() -> type[TKR[Circuit]]: # noqa: F821 # fmt: skip + return TKR[Circuit] # noqa: F821 # fmt: skip @property def namespace(self) -> str: @@ -83,12 +108,12 @@ def namespace(self) -> str: class apply_pass(NamedTuple): - circuit: TKR[OpaqueType["pytket._tket.circuit.Circuit"]] # noqa: F821 # fmt: skip - compiler_pass: TKR[OpaqueType["pytket._tket.passes.BasePass"]] # noqa: F821 # fmt: skip + circuit: TKR[Circuit] # noqa: F821 # fmt: skip + compiler_pass: TKR[BasePass] # noqa: F821 # fmt: skip @staticmethod - def out() -> type[TKR[OpaqueType["pytket._tket.circuit.Circuit"]]]: # noqa: F821 # fmt: skip - return TKR[OpaqueType["pytket._tket.circuit.Circuit"]] # noqa: F821 # fmt: skip + def out() -> type[TKR[Circuit]]: # noqa: F821 # fmt: skip + return TKR[Circuit] # noqa: F821 # fmt: skip @property def namespace(self) -> str: @@ -96,17 +121,17 @@ def namespace(self) -> str: class compile_generic_with_fixed_pass(NamedTuple): - circuit: TKR[Union[OpaqueType["pytket._tket.circuit.Circuit"], str, bytes]] # noqa: F821 # fmt: skip + circuit: TKR[Union[Circuit, str, bytes]] # noqa: F821 # fmt: skip input_format: TKR[str] | None = None # noqa: F821 # fmt: skip optimisation_level: TKR[int] | None = None # noqa: F821 # fmt: skip gate_set: TKR[Union[list[str], NoneType]] | None = None # noqa: F821 # fmt: skip coupling_map: TKR[Union[list[tuple[int, int]], NoneType]] | None = None # noqa: F821 # fmt: skip output_format: TKR[str] | None = None # noqa: F821 # fmt: skip - optimisation_pass: TKR[Union[OpaqueType["pytket._tket.passes.BasePass"], NoneType]] | None = None # noqa: F821 # fmt: skip + optimisation_pass: TKR[Union[BasePass, NoneType]] | None = None # noqa: F821 # fmt: skip @staticmethod - def out() -> type[TKR[Union[OpaqueType["pytket._tket.circuit.Circuit"], str, bytes]]]: # noqa: F821 # fmt: skip - return TKR[Union[OpaqueType["pytket._tket.circuit.Circuit"], str, bytes]] # noqa: F821 # fmt: skip + def out() -> type[TKR[Union[Circuit, str, bytes]]]: # noqa: F821 # fmt: skip + return TKR[Union[Circuit, str, bytes]] # noqa: F821 # fmt: skip @property def namespace(self) -> str: @@ -114,7 +139,7 @@ def namespace(self) -> str: class to_qasm2_str(NamedTuple): - circuit: TKR[OpaqueType["pytket._tket.circuit.Circuit"]] # noqa: F821 # fmt: skip + circuit: TKR[Circuit] # noqa: F821 # fmt: skip header: TKR[str] | None = None # noqa: F821 # fmt: skip @staticmethod @@ -130,8 +155,8 @@ class from_qasm2_str(NamedTuple): qasm: TKR[str] # noqa: F821 # fmt: skip @staticmethod - def out() -> type[TKR[OpaqueType["pytket._tket.circuit.Circuit"]]]: # noqa: F821 # fmt: skip - return TKR[OpaqueType["pytket._tket.circuit.Circuit"]] # noqa: F821 # fmt: skip + def out() -> type[TKR[Circuit]]: # noqa: F821 # fmt: skip + return TKR[Circuit] # noqa: F821 # fmt: skip @property def namespace(self) -> str: @@ -139,7 +164,7 @@ def namespace(self) -> str: class to_qir_bytes(NamedTuple): - circuit: TKR[OpaqueType["pytket._tket.circuit.Circuit"]] # noqa: F821 # fmt: skip + circuit: TKR[Circuit] # noqa: F821 # fmt: skip @staticmethod def out() -> type[TKR[bytes]]: # noqa: F821 # fmt: skip @@ -154,8 +179,8 @@ class from_qir_bytes(NamedTuple): qir: TKR[bytes] # noqa: F821 # fmt: skip @staticmethod - def out() -> type[TKR[OpaqueType["pytket._tket.circuit.Circuit"]]]: # noqa: F821 # fmt: skip - return TKR[OpaqueType["pytket._tket.circuit.Circuit"]] # noqa: F821 # fmt: skip + def out() -> type[TKR[Circuit]]: # noqa: F821 # fmt: skip + return TKR[Circuit] # noqa: F821 # fmt: skip @property def namespace(self) -> str: @@ -163,7 +188,7 @@ def namespace(self) -> str: class expectation(NamedTuple): - backend_result: TKR[OpaqueType["pytket.backends.backendresult.BackendResult"]] # noqa: F821 # fmt: skip + backend_result: TKR[BackendResult] # noqa: F821 # fmt: skip @staticmethod def out() -> type[TKR[float]]: # noqa: F821 # fmt: skip @@ -175,7 +200,7 @@ def namespace(self) -> str: class n_qubits(NamedTuple): - circuit: TKR[OpaqueType["pytket._tket.circuit.Circuit"]] # noqa: F821 # fmt: skip + circuit: TKR[Circuit] # noqa: F821 # fmt: skip @staticmethod def out() -> type[TKR[int]]: # noqa: F821 # fmt: skip @@ -187,7 +212,7 @@ def namespace(self) -> str: class backend_result_to_dict(NamedTuple): - backend_result: TKR[OpaqueType["pytket.backends.backendresult.BackendResult"]] # noqa: F821 # fmt: skip + backend_result: TKR[BackendResult] # noqa: F821 # fmt: skip @staticmethod def out() -> type[TKR[dict[str, list[str]]]]: # noqa: F821 # fmt: skip @@ -202,8 +227,8 @@ class backend_result_from_dict(NamedTuple): data: TKR[dict[str, list[str]]] # noqa: F821 # fmt: skip @staticmethod - def out() -> type[TKR[OpaqueType["pytket.backends.backendresult.BackendResult"]]]: # noqa: F821 # fmt: skip - return TKR[OpaqueType["pytket.backends.backendresult.BackendResult"]] # noqa: F821 # fmt: skip + def out() -> type[TKR[BackendResult]]: # noqa: F821 # fmt: skip + return TKR[BackendResult] # noqa: F821 # fmt: skip @property def namespace(self) -> str: diff --git a/tierkreis_workers/quantinuum_worker/api/api.py b/tierkreis_workers/quantinuum_worker/api/api.py index ed0eb5704..d0e134914 100644 --- a/tierkreis_workers/quantinuum_worker/api/api.py +++ b/tierkreis_workers/quantinuum_worker/api/api.py @@ -1,15 +1,20 @@ """Code generated from quantinuum_worker namespace. Please do not edit.""" -from typing import NamedTuple -from tierkreis.controller.data.models import TKR, OpaqueType +from typing import Literal, NamedTuple +from tierkreis.controller.data.models import TKR + +type BackendInfo = Literal["pytket.backends.backendinfo.BackendInfo"] +type Circuit = Literal["pytket._tket.circuit.Circuit"] +type BasePass = Literal["pytket._tket.passes.BasePass"] +type BackendResult = Literal["pytket.backends.backendresult.BackendResult"] class get_backend_info(NamedTuple): device_name: TKR[str] # noqa: F821 # fmt: skip @staticmethod - def out() -> type[TKR[OpaqueType["pytket.backends.backendinfo.BackendInfo"]]]: # noqa: F821 # fmt: skip - return TKR[OpaqueType["pytket.backends.backendinfo.BackendInfo"]] # noqa: F821 # fmt: skip + def out() -> type[TKR[BackendInfo]]: # noqa: F821 # fmt: skip + return TKR[BackendInfo] # noqa: F821 # fmt: skip @property def namespace(self) -> str: @@ -17,13 +22,13 @@ def namespace(self) -> str: class compile_using_info(NamedTuple): - circuit: TKR[OpaqueType["pytket._tket.circuit.Circuit"]] # noqa: F821 # fmt: skip - backend_info: TKR[OpaqueType["pytket.backends.backendinfo.BackendInfo"]] # noqa: F821 # fmt: skip + circuit: TKR[Circuit] # noqa: F821 # fmt: skip + backend_info: TKR[BackendInfo] # noqa: F821 # fmt: skip optimisation_level: TKR[int] | None = None # noqa: F821 # fmt: skip @staticmethod - def out() -> type[TKR[OpaqueType["pytket._tket.circuit.Circuit"]]]: # noqa: F821 # fmt: skip - return TKR[OpaqueType["pytket._tket.circuit.Circuit"]] # noqa: F821 # fmt: skip + def out() -> type[TKR[Circuit]]: # noqa: F821 # fmt: skip + return TKR[Circuit] # noqa: F821 # fmt: skip @property def namespace(self) -> str: @@ -31,12 +36,12 @@ def namespace(self) -> str: class backend_pass_from_info(NamedTuple): - backend_info: TKR[OpaqueType["pytket.backends.backendinfo.BackendInfo"]] # noqa: F821 # fmt: skip + backend_info: TKR[BackendInfo] # noqa: F821 # fmt: skip optimisation_level: TKR[int] | None = None # noqa: F821 # fmt: skip @staticmethod - def out() -> type[TKR[OpaqueType["pytket._tket.passes.BasePass"]]]: # noqa: F821 # fmt: skip - return TKR[OpaqueType["pytket._tket.passes.BasePass"]] # noqa: F821 # fmt: skip + def out() -> type[TKR[BasePass]]: # noqa: F821 # fmt: skip + return TKR[BasePass] # noqa: F821 # fmt: skip @property def namespace(self) -> str: @@ -45,8 +50,8 @@ def namespace(self) -> str: class fixed_pass(NamedTuple): @staticmethod - def out() -> type[TKR[OpaqueType["pytket._tket.passes.BasePass"]]]: # noqa: F821 # fmt: skip - return TKR[OpaqueType["pytket._tket.passes.BasePass"]] # noqa: F821 # fmt: skip + def out() -> type[TKR[BasePass]]: # noqa: F821 # fmt: skip + return TKR[BasePass] # noqa: F821 # fmt: skip @property def namespace(self) -> str: @@ -54,11 +59,11 @@ def namespace(self) -> str: class compile_circuit_quantinuum(NamedTuple): - circuit: TKR[OpaqueType["pytket._tket.circuit.Circuit"]] # noqa: F821 # fmt: skip + circuit: TKR[Circuit] # noqa: F821 # fmt: skip @staticmethod - def out() -> type[TKR[OpaqueType["pytket._tket.circuit.Circuit"]]]: # noqa: F821 # fmt: skip - return TKR[OpaqueType["pytket._tket.circuit.Circuit"]] # noqa: F821 # fmt: skip + def out() -> type[TKR[Circuit]]: # noqa: F821 # fmt: skip + return TKR[Circuit] # noqa: F821 # fmt: skip @property def namespace(self) -> str: @@ -66,11 +71,11 @@ def namespace(self) -> str: class compile_circuits_quantinuum(NamedTuple): - circuits: TKR[list[OpaqueType["pytket._tket.circuit.Circuit"]]] # noqa: F821 # fmt: skip + circuits: TKR[list[Circuit]] # noqa: F821 # fmt: skip @staticmethod - def out() -> type[TKR[list[OpaqueType["pytket._tket.circuit.Circuit"]]]]: # noqa: F821 # fmt: skip - return TKR[list[OpaqueType["pytket._tket.circuit.Circuit"]]] # noqa: F821 # fmt: skip + def out() -> type[TKR[list[Circuit]]]: # noqa: F821 # fmt: skip + return TKR[list[Circuit]] # noqa: F821 # fmt: skip @property def namespace(self) -> str: @@ -78,13 +83,13 @@ def namespace(self) -> str: class run_circuit(NamedTuple): - circuit: TKR[OpaqueType["pytket._tket.circuit.Circuit"]] # noqa: F821 # fmt: skip + circuit: TKR[Circuit] # noqa: F821 # fmt: skip n_shots: TKR[int] # noqa: F821 # fmt: skip device_name: TKR[str] # noqa: F821 # fmt: skip @staticmethod - def out() -> type[TKR[OpaqueType["pytket.backends.backendresult.BackendResult"]]]: # noqa: F821 # fmt: skip - return TKR[OpaqueType["pytket.backends.backendresult.BackendResult"]] # noqa: F821 # fmt: skip + def out() -> type[TKR[BackendResult]]: # noqa: F821 # fmt: skip + return TKR[BackendResult] # noqa: F821 # fmt: skip @property def namespace(self) -> str: diff --git a/tierkreis_workers/qulacs_worker/api/api.py b/tierkreis_workers/qulacs_worker/api/api.py index 441f87f69..a8b3680b7 100644 --- a/tierkreis_workers/qulacs_worker/api/api.py +++ b/tierkreis_workers/qulacs_worker/api/api.py @@ -1,19 +1,22 @@ """Code generated from qulacs_worker namespace. Please do not edit.""" -from typing import NamedTuple, Union +from typing import Literal, NamedTuple, Union from types import NoneType -from tierkreis.controller.data.models import TKR, OpaqueType +from tierkreis.controller.data.models import TKR + +type Circuit = Literal["pytket._tket.circuit.Circuit"] +type BackendResult = Literal["pytket.backends.backendresult.BackendResult"] class get_compiled_circuit(NamedTuple): - circuit: TKR[OpaqueType["pytket._tket.circuit.Circuit"]] # noqa: F821 # fmt: skip + circuit: TKR[Circuit] # noqa: F821 # fmt: skip optimisation_level: TKR[int] | None = None # noqa: F821 # fmt: skip result_type: TKR[str] | None = None # noqa: F821 # fmt: skip gpu_sim: TKR[bool] | None = None # noqa: F821 # fmt: skip @staticmethod - def out() -> type[TKR[OpaqueType["pytket._tket.circuit.Circuit"]]]: # noqa: F821 # fmt: skip - return TKR[OpaqueType["pytket._tket.circuit.Circuit"]] # noqa: F821 # fmt: skip + def out() -> type[TKR[Circuit]]: # noqa: F821 # fmt: skip + return TKR[Circuit] # noqa: F821 # fmt: skip @property def namespace(self) -> str: @@ -21,15 +24,15 @@ def namespace(self) -> str: class run_circuit(NamedTuple): - circuit: TKR[OpaqueType["pytket._tket.circuit.Circuit"]] # noqa: F821 # fmt: skip + circuit: TKR[Circuit] # noqa: F821 # fmt: skip n_shots: TKR[int] # noqa: F821 # fmt: skip result_type: TKR[str] | None = None # noqa: F821 # fmt: skip gpu_sim: TKR[bool] | None = None # noqa: F821 # fmt: skip seed: TKR[Union[int, NoneType]] | None = None # noqa: F821 # fmt: skip @staticmethod - def out() -> type[TKR[OpaqueType["pytket.backends.backendresult.BackendResult"]]]: # noqa: F821 # fmt: skip - return TKR[OpaqueType["pytket.backends.backendresult.BackendResult"]] # noqa: F821 # fmt: skip + def out() -> type[TKR[BackendResult]]: # noqa: F821 # fmt: skip + return TKR[BackendResult] # noqa: F821 # fmt: skip @property def namespace(self) -> str: @@ -37,15 +40,15 @@ def namespace(self) -> str: class run_circuits(NamedTuple): - circuits: TKR[list[OpaqueType["pytket._tket.circuit.Circuit"]]] # noqa: F821 # fmt: skip + circuits: TKR[list[Circuit]] # noqa: F821 # fmt: skip n_shots: TKR[list[int]] # noqa: F821 # fmt: skip result_type: TKR[str] | None = None # noqa: F821 # fmt: skip gpu_sim: TKR[bool] | None = None # noqa: F821 # fmt: skip seed: TKR[Union[int, NoneType]] | None = None # noqa: F821 # fmt: skip @staticmethod - def out() -> type[TKR[list[OpaqueType["pytket.backends.backendresult.BackendResult"]]]]: # noqa: F821 # fmt: skip - return TKR[list[OpaqueType["pytket.backends.backendresult.BackendResult"]]] # noqa: F821 # fmt: skip + def out() -> type[TKR[list[BackendResult]]]: # noqa: F821 # fmt: skip + return TKR[list[BackendResult]] # noqa: F821 # fmt: skip @property def namespace(self) -> str: