Skip to content
Open
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
Binary file not shown.
Binary file not shown.
24 changes: 24 additions & 0 deletions test_files/guppy_optimization/1q_squash/qsystem_chain.opt.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# /// script
# requires-python = ">=3.13"
# dependencies = [
# "guppylang >=0.21.6",
# ]
# ///

from pathlib import Path
from sys import argv

from guppylang import guppy
from guppylang.std.quantum import qubit
from guppylang.std.qsystem import rz, phased_x
from guppylang.std.angles import angle


@guppy
def qsystem_chain(q: qubit) -> None:
phased_x(q, angle(0.368713), angle(1.66415))
rz(q, angle(0.870616))


program = qsystem_chain.compile_function()
Path(argv[0]).with_suffix(".hugr").write_bytes(program.to_bytes())
46 changes: 46 additions & 0 deletions test_files/guppy_optimization/1q_squash/qsystem_chain.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# /// script
# requires-python = ">=3.13"
# dependencies = [
# "guppylang >=0.21.6",
# ]
# ///

from pathlib import Path
from sys import argv

from guppylang import guppy
from guppylang.std.quantum import qubit
from guppylang.std.qsystem import rz, phased_x
from guppylang.std.angles import angle


@guppy
def qsystem_chain(q: qubit) -> None:
phased_x(q, angle(0.91), angle(0.5))
phased_x(q, angle(0.53), angle(0))
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Maybe I should make these angles a bit friendlier. I have included the pytket code below though.

The argument order for the phased X gate should be the same as pytket

phased_x(q, angle(3.29), angle(0.5))
phased_x(q, angle(0.81), angle(0))
rz(q, angle(0.62))


program = qsystem_chain.compile_function()
Path(argv[0]).with_suffix(".hugr").write_bytes(program.to_bytes())

# pytket code to generate this example.
# For the optimised version replace the call to AutoRebase with AutoSquash.

# from pytket import Circuit, OpType
# from pytket.passes import AutoSquash, AutoRebase
#
# circ = Circuit(1)
#
# circ.Ry(0.91, 0)
# circ.Rx(0.53, 0)
# circ.Ry(-0.71, 0)
# circ.Rx(0.81, 0)
# circ.Rz(0.62, 0)
#
# When you switch to AutoSquash, remove ZZPhase from the set
# AutoRebase({OpType.Rz, OpType.PhasedX, OpType.ZZPhase}).apply(circ)
#
# print(circ.get_commands())
Binary file not shown.
Binary file not shown.
22 changes: 22 additions & 0 deletions test_files/guppy_optimization/1q_squash/rz_chain.opt.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# /// script
# requires-python = ">=3.13"
# dependencies = [
# "guppylang >=0.21.6",
# ]
# ///

from pathlib import Path
from sys import argv

from guppylang import guppy
from guppylang.std.quantum import rz, qubit
from guppylang.std.angles import angle


@guppy
def rz_chain(q: qubit) -> None:
rz(q, angle(3 / 2))


program = rz_chain.compile_function()
Path(argv[0]).with_suffix(".hugr").write_bytes(program.to_bytes())
24 changes: 24 additions & 0 deletions test_files/guppy_optimization/1q_squash/rz_chain.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# /// script
# requires-python = ">=3.13"
# dependencies = [
# "guppylang >=0.21.6",
# ]
# ///

from pathlib import Path
from sys import argv

from guppylang import guppy
from guppylang.std.quantum import rz, qubit
from guppylang.std.angles import angle


@guppy
def rz_chain(q: qubit) -> None:
rz(q, angle(1 / 2))
rz(q, angle(1 / 2))
rz(q, angle(1 / 2))


program = rz_chain.compile_function()
Path(argv[0]).with_suffix(".hugr").write_bytes(program.to_bytes())
2 changes: 1 addition & 1 deletion test_files/guppy_optimization/angles/angles.flat.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,5 @@ def f(q: qubit @ owned) -> qubit:
return q


program = main.compile()
program = main.compile_function()
Path(argv[0]).with_suffix(".hugr").write_bytes(program.to_bytes())
2 changes: 1 addition & 1 deletion test_files/guppy_optimization/angles/angles.opt.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@ def main() -> None:
result("b", 0)


program = main.compile()
program = main.compile_function()
Path(argv[0]).with_suffix(".hugr").write_bytes(program.to_bytes())
2 changes: 1 addition & 1 deletion test_files/guppy_optimization/angles/angles.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,5 @@ def f(q: qubit @ owned) -> qubit:
return q


program = main.compile()
program = main.compile_function()
Path(argv[0]).with_suffix(".hugr").write_bytes(program.to_bytes())
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@ def main() -> None:
result("b", 0)


program = main.compile()
program = main.compile_function()
Path(argv[0]).with_suffix(".hugr").write_bytes(program.to_bytes())
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,5 @@ def main() -> None:
result("b", b)


program = main.compile()
program = main.compile_function()
Path(argv[0]).with_suffix(".hugr").write_bytes(program.to_bytes())
2 changes: 1 addition & 1 deletion test_files/guppy_optimization/nested/nested.flat.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,5 @@ def f(qs: array[qubit, 3] @ owned) -> array[qubit, 3]:
return qs


program = main.compile()
program = main.compile_function()
Path(argv[0]).with_suffix(".hugr").write_bytes(program.to_bytes())
2 changes: 1 addition & 1 deletion test_files/guppy_optimization/nested/nested.opt.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,5 @@ def main() -> None:
result("b3", b3)


program = main.compile()
program = main.compile_function()
Path(argv[0]).with_suffix(".hugr").write_bytes(program.to_bytes())
2 changes: 1 addition & 1 deletion test_files/guppy_optimization/nested/nested.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,5 @@ def f(qs: array[qubit, 3] @ owned) -> array[qubit, 3]:
return qs


program = main.compile()
program = main.compile_function()
Path(argv[0]).with_suffix(".hugr").write_bytes(program.to_bytes())
2 changes: 1 addition & 1 deletion test_files/guppy_optimization/ranges/ranges.flat.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,5 @@ def f(qs: array[qubit, 4] @ owned) -> array[qubit, 4]:
return qs


program = main.compile()
program = main.compile_function()
Path(argv[0]).with_suffix(".hugr").write_bytes(program.to_bytes())
2 changes: 1 addition & 1 deletion test_files/guppy_optimization/ranges/ranges.opt.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,5 @@ def main() -> None:
result("b4", b4)


program = main.compile()
program = main.compile_function()
Path(argv[0]).with_suffix(".hugr").write_bytes(program.to_bytes())
2 changes: 1 addition & 1 deletion test_files/guppy_optimization/ranges/ranges.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,5 @@ def f(qs: array[qubit, 4] @ owned) -> array[qubit, 4]:
return qs


program = main.compile()
program = main.compile_function()
Path(argv[0]).with_suffix(".hugr").write_bytes(program.to_bytes())
2 changes: 1 addition & 1 deletion test_files/guppy_optimization/simple_cx/simple_cx.opt.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ def main() -> None:
result("b2", 0)


program = main.compile()
program = main.compile_function()
Path(argv[0]).with_suffix(".hugr").write_bytes(program.to_bytes())
2 changes: 1 addition & 1 deletion test_files/guppy_optimization/simple_cx/simple_cx.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,5 @@ def main() -> None:
result("b2", b2)


program = main.compile()
program = main.compile_function()
Path(argv[0]).with_suffix(".hugr").write_bytes(program.to_bytes())
5 changes: 3 additions & 2 deletions tket-qsystem/tests/guppy_opt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ use tket_qsystem::QSystemPass;
const GUPPY_EXAMPLES_DIR: &str = "../test_files/guppy_optimization";

/// JSON encoding of the clifford simp pytket pass.
const CLIFFORD_SIMP_STR: &str = r#"{"StandardPass": {"allow_swaps": true, "name": "CliffordSimp", "target_2qb_gate": "CX"}, "pass_class": "StandardPass"}"#;
// const CLIFFORD_SIMP_STR: &str = r#"{"StandardPass": {"allow_swaps": true, "name": "CliffordSimp", "target_2qb_gate": "CX"}, "pass_class": "StandardPass"}"#;
const SQUASH_STR: &str = r#"{"StandardPass": {"name": "SquashRzPhasedX"}, "pass_class": "StandardPass"}"#;

enum HugrFileType {
Original,
Expand Down Expand Up @@ -54,7 +55,7 @@ fn run_pytket(h: &mut Hugr) {
.par_iter_mut()
.for_each(|(_region, serial_circuit)| {
let mut circuit_ptr = Tket1Circuit::from_serial_circuit(serial_circuit).unwrap();
Tket1Pass::run_from_json(CLIFFORD_SIMP_STR, &mut circuit_ptr).unwrap();
Tket1Pass::run_from_json(SQUASH_STR, &mut circuit_ptr).unwrap();
*serial_circuit = circuit_ptr.to_serial_circuit().unwrap();
});

Expand Down
Loading