Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/source/worker/nexus_worker.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Nexus worker
52 changes: 52 additions & 0 deletions examples/data/ghz_state_n23.qasm
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
OPENQASM 2.0;
include "qelib1.inc";
qreg q[23];
creg c[23];
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

do we need this?

creg meas[23];
h q[0];
cx q[0],q[1];
cx q[1],q[2];
cx q[2],q[3];
cx q[3],q[4];
cx q[4],q[5];
cx q[5],q[6];
cx q[6],q[7];
cx q[7],q[8];
cx q[8],q[9];
cx q[9],q[10];
cx q[10],q[11];
cx q[11],q[12];
cx q[12],q[13];
cx q[13],q[14];
cx q[14],q[15];
cx q[15],q[16];
cx q[16],q[17];
cx q[17],q[18];
cx q[18],q[19];
cx q[19],q[20];
cx q[20],q[21];
cx q[21],q[22];
barrier q[0],q[1],q[2],q[3],q[4],q[5],q[6],q[7],q[8],q[9],q[10],q[11],q[12],q[13],q[14],q[15],q[16],q[17],q[18],q[19],q[20],q[21],q[22];
measure q[0] -> meas[0];
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I think its possible to do measure q -> meas

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

No doubt you have a better idea than me. I'm using this (from https://github.com/pnnl/QASMBench/tree/master/medium/ghz_state_n23).

measure q[1] -> meas[1];
measure q[2] -> meas[2];
measure q[3] -> meas[3];
measure q[4] -> meas[4];
measure q[5] -> meas[5];
measure q[6] -> meas[6];
measure q[7] -> meas[7];
measure q[8] -> meas[8];
measure q[9] -> meas[9];
measure q[10] -> meas[10];
measure q[11] -> meas[11];
measure q[12] -> meas[12];
measure q[13] -> meas[13];
measure q[14] -> meas[14];
measure q[15] -> meas[15];
measure q[16] -> meas[16];
measure q[17] -> meas[17];
measure q[18] -> meas[18];
measure q[19] -> meas[19];
measure q[20] -> meas[20];
measure q[21] -> meas[21];
measure q[22] -> meas[22];
11 changes: 11 additions & 0 deletions examples/data/simple.qasm
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
OPENQASM 2.0;
include "hqslib1.inc";

qreg q[2];
creg c[2];
U1q(0.20000000000000012*pi,0.0*pi) q[0];
U1q(0.5*pi,0.5*pi) q[1];
RZZ(0.5*pi) q[0],q[1];
measure q[0] -> c[0];
U1q(0.5*pi,0.0*pi) q[1];
measure q[1] -> c[1];
41 changes: 0 additions & 41 deletions examples/example_workers/nexus_worker/stubs.py

This file was deleted.

4 changes: 2 additions & 2 deletions examples/hamiltonian_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@

from tierkreis.builtins.stubs import untuple, itimes, iadd, unzip, zip_impl
from tierkreis.graphs.fold import FoldFunctionInput, FoldGraphInputs, fold_graph
from example_workers.pytket_worker.stubs import (
from tierkreis.pytket_worker import (
append_pauli_measurement_impl,
optimise_phase_gadgets,
expectation,
)

from example_workers.aer_worker.stubs import submit_single
from tierkreis.aer_worker import submit_single
from example_workers.substitution_worker.stubs import substitute

root_loc = Loc()
Expand Down
40 changes: 40 additions & 0 deletions examples/nexus_polling.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
from pathlib import Path
from uuid import UUID
from qnexus import AerConfig
from pytket.qasm.qasm import circuit_from_qasm

from tierkreis.consts import PACKAGE_PATH
from tierkreis.controller import run_graph
from tierkreis.graphs.nexus.submit_poll import nexus_submit_and_poll
from tierkreis.storage import FileStorage, read_outputs
from tierkreis.executor import UvExecutor

aer_config = AerConfig()
circuit = circuit_from_qasm(Path(__file__).parent / "data" / "ghz_state_n23.qasm")
circuits = [circuit]


def main():
g = nexus_submit_and_poll()
storage = FileStorage(UUID(int=107), do_cleanup=True)
executor = UvExecutor(PACKAGE_PATH / ".." / "tierkreis_workers", storage.logs_path)

run_graph(
storage,
executor,
g,
{
"project_name": "2025-tkr-test",
"job_name": "job-1",
"circuits": circuits,
"n_shots": [30] * len(circuits),
"backend_config": aer_config,
},
polling_interval_seconds=0.1,
)
res = read_outputs(g, storage)
print(res)


if __name__ == "__main__":
main()
4 changes: 2 additions & 2 deletions examples/qsci_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
energy_from_results,
state_prep,
)
from example_workers.aer_worker.stubs import submit_single
from example_workers.pytket_worker.stubs import compile_circuit_quantinuum
from tierkreis.aer_worker import submit_single
from tierkreis.pytket_worker import compile_circuit_quantinuum

root_loc = Loc()

Expand Down
4 changes: 2 additions & 2 deletions examples/symbolic_circuits.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@
from tierkreis.controller.executor.uv_executor import UvExecutor

from example_workers.substitution_worker.stubs import substitute
from example_workers.pytket_worker.stubs import (
from tierkreis.pytket_worker import (
add_measure_all,
optimise_phase_gadgets,
expectation,
)
from example_workers.aer_worker.stubs import submit_single
from tierkreis.aer_worker import submit_single

root_loc = Loc()

Expand Down
6 changes: 3 additions & 3 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,6 @@ generate:
mkdir -p examples/example_workers/aer_worker
mkdir -p examples/example_workers/nexus_worker
mkdir -p examples/example_workers/pytket_worker
cp 'tierkreis_workers/aer_worker/stubs.py' examples/example_workers/aer_worker/stubs.py
cp 'tierkreis_workers/nexus_worker/stubs.py' examples/example_workers/nexus_worker/stubs.py
cp 'tierkreis_workers/pytket_worker/stubs.py' examples/example_workers/pytket_worker/stubs.py
cp 'tierkreis_workers/aer_worker/stubs.py' tierkreis/tierkreis/aer_worker.py
cp 'tierkreis_workers/nexus_worker/stubs.py' tierkreis/tierkreis/nexus_worker.py
cp 'tierkreis_workers/pytket_worker/stubs.py' tierkreis/tierkreis/pytket_worker.py
11 changes: 7 additions & 4 deletions tierkreis/tests/controller/test_codegen.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from types import NoneType
import pytest
from tierkreis.codegen import format_ptype
from tierkreis.codegen import format_generic_type
from tierkreis.controller.data.types import PType
from tierkreis.idl.models import GenericType

formats: list[tuple[type[PType], str]] = [
(bool, "bool"),
Expand All @@ -11,15 +12,17 @@
(bytes, "bytes"),
(NoneType, "NoneType"),
(list[str], "list[str]"),
(list[str | list[str | int]], "list[str | list[str | int]]"),
(list[str | list[str | int]], "list[Union[str, list[Union[str, int]]]]"),
(tuple[str], "tuple[str]"),
(
tuple[str | list[str | int], NoneType],
"tuple[str | list[str | int], NoneType]",
"tuple[Union[str, list[Union[str, int]]], NoneType]",
),
]


@pytest.mark.parametrize("ttype,expected", formats)
def test_format_ttype(ttype: type[PType], expected: str):
assert format_ptype(ttype) == expected
generic_type = GenericType.from_type(ttype)

assert format_generic_type(generic_type, False, False) == expected
2 changes: 1 addition & 1 deletion tierkreis/tests/errors/failing_worker/uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions tierkreis/tests/idl/namespace1.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ class B(NamedTuple):
age: int


@portmapping
class C[T: PType](NamedTuple):
a: list[int]
b: B
Expand All @@ -29,7 +28,7 @@ def foo(a: int, b: str) -> A: ...
@worker.task()
def bar() -> B: ...
@worker.task()
def z[T: PType](a: C[T]) -> C[T]: ...
def z[T: PType](c: C[T]) -> C[T]: ...


expected_namespace = worker.namespace
3 changes: 1 addition & 2 deletions tierkreis/tests/idl/namespace1.tsp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ model B {
age: uint8;
}

@portmapping
model C<T> {
a: Array<integer>;
b: B;
Expand All @@ -18,5 +17,5 @@ model C<T> {
interface TestNamespace {
foo(a: integer, b: string): A;
bar(): B;
z<T>(a: C<T>): C<T>;
z<T>(c: C<T>): C<T>;
}
56 changes: 56 additions & 0 deletions tierkreis/tests/idl/stubs_output.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
"""Code generated from TestNamespace namespace. Please do not edit."""

from typing import NamedTuple, Protocol
from tierkreis.controller.data.models import TKR
from tierkreis.controller.data.types import PType, Struct


class A(NamedTuple):
age: TKR[int] # noqa: F821 # fmt: skip
name: TKR[dict[str, str]] # noqa: F821 # fmt: skip


class B(Struct, Protocol):
age: int # noqa: F821 # fmt: skip
name: dict[str, str] # noqa: F821 # fmt: skip


class C[T: PType](Struct, Protocol):
a: list[int] # noqa: F821 # fmt: skip
b: B # noqa: F821 # fmt: skip
t: T # noqa: F821 # fmt: skip


class foo(NamedTuple):
a: TKR[int] # noqa: F821 # fmt: skip
b: TKR[str] # noqa: F821 # fmt: skip

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

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


class bar(NamedTuple):
@staticmethod
def out() -> type[TKR[B]]: # noqa: F821 # fmt: skip
return TKR[B] # noqa: F821 # fmt: skip

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


class z[T: PType](NamedTuple):
c: TKR[C[T]] # noqa: F821 # fmt: skip

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

@property
def namespace(self) -> str:
return "TestNamespace"
8 changes: 8 additions & 0 deletions tierkreis/tests/idl/test_idl.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from tierkreis.namespace import Namespace
from tierkreis.idl.type_symbols import type_symbol
import tests.idl.namespace1
from tierkreis.worker.worker import Worker

type_symbols = [
("uint8", GenericType(int, [])),
Expand Down Expand Up @@ -43,6 +44,13 @@ def test_namespace(path: Path, expected: Namespace):
namespace = Namespace.from_spec_file(path)
assert format_namespace(namespace) == format_namespace(expected)

# Write stubs to file.
# This file will be subject to linting.
# Also a change in this file can indicate an unexpectedly breaking change.
worker = Worker("dummy_worker")
worker.namespace = namespace
worker.write_stubs(Path(__file__).parent / "stubs_output.py")


@pytest.mark.parametrize("type_symb", type_symbols_for_failure)
def test_parser_fail(type_symb: str):
Expand Down
12 changes: 12 additions & 0 deletions tierkreis/tierkreis/builtins/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from random import randint
import statistics
from sys import argv
from time import sleep
from typing import NamedTuple, Sequence

from tierkreis.controller.data.location import WorkerCallArgs
Expand Down Expand Up @@ -36,6 +37,11 @@ def igt(a: int, b: int) -> bool:
return a > b


@worker.task()
def neg(a: bool) -> bool:
return not a


@worker.task()
def impl_and(a: bool, b: bool) -> bool:
logger.debug(f"and {a} {b}")
Expand Down Expand Up @@ -157,5 +163,11 @@ def rand_int(a: int, b: int) -> int:
return randint(a, b)


@worker.task()
def tkr_sleep(delay_seconds: float) -> bool:
sleep(delay_seconds)
return True


if __name__ == "__main__":
worker.app(argv)
Loading