diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6745667c..090aaad9 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -278,11 +278,34 @@ jobs: flags: python token: ${{ secrets.CODECOV_TOKEN }} + # Ensure that serialized extensions match rust implementation + tket2-extensions: + needs: [changes, tests-rs-stable-all-features] + if: ${{ needs.changes.outputs.rust == 'true' && github.event_name != 'merge_group' }} + name: Check standard extensions + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: mozilla-actions/sccache-action@v0.0.5 + - name: Install stable toolchain + uses: dtolnay/rust-toolchain@stable + - uses: extractions/setup-just@v2 + - name: Generate the updated definitions + run: just gen-extensions + - name: Check if the declarations are up to date + run: | + git diff --exit-code --name-only tket2-py/tket2/extensions/_json_defs + if [ $? -ne 0 ]; then + echo "The serialized standard extensions are not up to date" + echo "Please run 'just gen-extensions' and commit the changes" + exit 1 + fi + # This is a meta job to mark successful completion of the required checks, # even if they are skipped due to no changes in the relevant files. required-checks: name: Required checks 🦀+🐍 - needs: [changes, check-rs, check-py, tests-rs-stable-no-features, tests-rs-stable-all-features, tests-py] + needs: [changes, check-rs, check-py, tests-rs-stable-no-features, tests-rs-stable-all-features, tests-py, tket2-extensions] if: ${{ !cancelled() }} runs-on: ubuntu-latest steps: diff --git a/Cargo.lock b/Cargo.lock index 79cc6812..79fcca75 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -261,6 +261,16 @@ dependencies = [ "clap_derive", ] +[[package]] +name = "clap-verbosity-flag" +version = "2.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "63d19864d6b68464c59f7162c9914a0b569ddc2926b4a2d71afe62a9738eff53" +dependencies = [ + "clap", + "log", +] + [[package]] name = "clap_builder" version = "4.5.17" @@ -291,6 +301,21 @@ version = "0.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4b82cf0babdbd58558212896d1a4272303a57bdb245c2bf1147185fb45640e70" +[[package]] +name = "clio" +version = "0.3.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b7fc6734af48458f72f5a3fa7b840903606427d98a710256e808f76a965047d9" +dependencies = [ + "cfg-if", + "clap", + "is-terminal", + "libc", + "tempfile", + "walkdir", + "windows-sys 0.42.0", +] + [[package]] name = "colorchoice" version = "1.0.1" @@ -567,6 +592,22 @@ dependencies = [ "typeid", ] +[[package]] +name = "errno" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "534c5cf6194dfab3db3242765c03bbe257cf92f22b38f6bc0c58d59108a820ba" +dependencies = [ + "libc", + "windows-sys 0.52.0", +] + +[[package]] +name = "fastrand" +version = "2.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e8c02a5121d4ea3eb16a80748c74f5549a5665e4c21333c6098f283870fbdea6" + [[package]] name = "fixedbitset" version = "0.4.2" @@ -760,6 +801,21 @@ dependencies = [ "hugr-passes", ] +[[package]] +name = "hugr-cli" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6df2f78a68df30280cc351522dee4d537707478d216758aa7404cbeb13aa770" +dependencies = [ + "clap", + "clap-verbosity-flag", + "clio", + "hugr-core", + "serde", + "serde_json", + "thiserror", +] + [[package]] name = "hugr-core" version = "0.9.1" @@ -955,9 +1011,15 @@ checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" [[package]] name = "libc" -version = "0.2.155" +version = "0.2.158" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c" +checksum = "d8adc4bb1803a324070e64a98ae98f38934d91957a99cfb3a43dcbc01bc56439" + +[[package]] +name = "linux-raw-sys" +version = "0.4.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78b3ae25bc7c8c38cec158d1f2757ee79e9b3740fbc7ccf0e59e4b08d793fa89" [[package]] name = "lock_api" @@ -1516,6 +1578,19 @@ dependencies = [ "semver", ] +[[package]] +name = "rustix" +version = "0.38.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f55e80d50763938498dd5ebb18647174e0c76dc38c5505294bb224624f30f36" +dependencies = [ + "bitflags", + "errno", + "libc", + "linux-raw-sys", + "windows-sys 0.52.0", +] + [[package]] name = "rustversion" version = "1.0.17" @@ -1682,6 +1757,19 @@ version = "0.12.15" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4873307b7c257eddcb50c9bedf158eb669578359fb28428bef438fec8e6ba7c2" +[[package]] +name = "tempfile" +version = "3.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "04cbcdd0c794ebb0d4cf35e88edd2f7d2c4c3e9a5a6dab322839b321c6a87a64" +dependencies = [ + "cfg-if", + "fastrand", + "once_cell", + "rustix", + "windows-sys 0.59.0", +] + [[package]] name = "thiserror" version = "1.0.63" @@ -1848,8 +1936,10 @@ dependencies = [ name = "tket2-hseries" version = "0.2.0" dependencies = [ + "clap", "cool_asserts", "hugr", + "hugr-cli", "itertools 0.13.0", "lazy_static", "petgraph", @@ -2191,6 +2281,21 @@ dependencies = [ "windows-targets 0.52.6", ] +[[package]] +name = "windows-sys" +version = "0.42.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a3e1820f08b8513f676f7ab6c1f99ff312fb97b553d30ff4dd86f9f15728aa7" +dependencies = [ + "windows_aarch64_gnullvm 0.42.2", + "windows_aarch64_msvc 0.42.2", + "windows_i686_gnu 0.42.2", + "windows_i686_msvc 0.42.2", + "windows_x86_64_gnu 0.42.2", + "windows_x86_64_gnullvm 0.42.2", + "windows_x86_64_msvc 0.42.2", +] + [[package]] name = "windows-sys" version = "0.45.0" @@ -2209,6 +2314,15 @@ dependencies = [ "windows-targets 0.52.6", ] +[[package]] +name = "windows-sys" +version = "0.59.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" +dependencies = [ + "windows-targets 0.52.6", +] + [[package]] name = "windows-targets" version = "0.42.2" diff --git a/Cargo.toml b/Cargo.toml index 7d503b6a..7da38922 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -28,6 +28,7 @@ missing_docs = "warn" # Make sure to run `just recompile-eccs` if the hugr serialisation format changes. hugr = "0.12.1" hugr-core = "0.9.1" +hugr-cli = "0.6.0" portgraph = "0.12" pyo3 = "0.21.2" itertools = "0.13.0" diff --git a/justfile b/justfile index 0ab0d9c3..7e33e32f 100644 --- a/justfile +++ b/justfile @@ -44,6 +44,9 @@ coverage language="[rust|python]": (_run_lang language \ recompile-eccs: scripts/compile-test-eccs.sh +# Generate serialized declarations for the tket2 extensions +gen-extensions: + cargo run -p tket2-hseries gen-extensions -o tket2-py/tket2/extensions/_json_defs # Runs a rust and a python command, depending on the `language` variable. # diff --git a/tket2-hseries/Cargo.toml b/tket2-hseries/Cargo.toml index 5534a985..04568cf2 100644 --- a/tket2-hseries/Cargo.toml +++ b/tket2-hseries/Cargo.toml @@ -13,6 +13,14 @@ description = "TKET2 tool for preparing and validating `Hugr`s for compilation t keywords = ["Quantum", "Quantinuum"] categories = ["compilers"] +[features] +default = ["cli"] +cli = ["dep:clap", "dep:hugr-cli"] + +[[bin]] +name = "tket2-hseries" +required-features = ["cli"] + [dependencies] hugr.workspace = true tket2 = { path = "../tket2", version = "0.2.0" } @@ -24,6 +32,8 @@ strum.workspace = true strum_macros.workspace = true thiserror.workspace = true itertools.workspace = true +clap = { workspace = true, optional = true} +hugr-cli = { workspace = true, optional = true } [dev-dependencies] cool_asserts.workspace = true diff --git a/tket2-hseries/src/bin/tket2-hseries.rs b/tket2-hseries/src/bin/tket2-hseries.rs new file mode 100644 index 00000000..a610603c --- /dev/null +++ b/tket2-hseries/src/bin/tket2-hseries.rs @@ -0,0 +1,26 @@ +//! CLI for tket2-hseries + +use clap::Parser as _; +use hugr::extension::ExtensionRegistry; +use tket2_hseries::cli::CliArgs; + +fn main() { + match CliArgs::parse() { + CliArgs::GenExtensions(args) => { + let reg = ExtensionRegistry::try_new([ + tket2::extension::TKET2_EXTENSION.to_owned(), + tket2::extension::angle::ANGLE_EXTENSION.to_owned(), + tket2_hseries::extension::hseries::EXTENSION.to_owned(), + tket2_hseries::extension::futures::EXTENSION.to_owned(), + tket2_hseries::extension::result::EXTENSION.to_owned(), + ]) + .unwrap(); + + args.run_dump(®); + } + _ => { + eprintln!("Unknown command"); + std::process::exit(1); + } + }; +} diff --git a/tket2-hseries/src/cli.rs b/tket2-hseries/src/cli.rs new file mode 100644 index 00000000..2bbb41af --- /dev/null +++ b/tket2-hseries/src/cli.rs @@ -0,0 +1,14 @@ +//! CLI tools for tket2-hseries. + +use clap::Parser; + +/// CLI arguments. +#[derive(Parser, Debug)] +#[clap(version = "1.0", long_about = None)] +#[clap(about = "tket2-hseries CLI tools.")] +#[group(id = "tket2-hseries")] +#[non_exhaustive] +pub enum CliArgs { + /// Generate serialized extensions. + GenExtensions(hugr_cli::extensions::ExtArgs), +} diff --git a/tket2-hseries/src/lib.rs b/tket2-hseries/src/lib.rs index f53fb643..777b7c28 100644 --- a/tket2-hseries/src/lib.rs +++ b/tket2-hseries/src/lib.rs @@ -15,6 +15,8 @@ use thiserror::Error; use extension::{futures::FutureOpDef, hseries::HSeriesOp}; use lazify_measure::{LazifyMeasurePass, LazifyMeasurePassError}; +#[cfg(feature = "cli")] +pub mod cli; pub mod extension; pub mod lazify_measure; diff --git a/tket2-py/tket2/extensions/_json_defs/tket2/angle.json b/tket2-py/tket2/extensions/_json_defs/tket2/angle.json new file mode 100644 index 00000000..fba13689 --- /dev/null +++ b/tket2-py/tket2/extensions/_json_defs/tket2/angle.json @@ -0,0 +1,396 @@ +{ + "version": "0.1.0", + "name": "tket2.angle", + "extension_reqs": [], + "types": { + "angle": { + "extension": "tket2.angle", + "name": "angle", + "params": [], + "description": "angle type expressed as dyadic rational multiples of 2π", + "bound": { + "b": "Explicit", + "bound": "C" + } + } + }, + "values": {}, + "operations": { + "aadd": { + "extension": "tket2.angle", + "name": "aadd", + "description": "addition of angles", + "signature": { + "params": [], + "body": { + "input": [ + { + "t": "Opaque", + "extension": "tket2.angle", + "id": "angle", + "args": [], + "bound": "C" + }, + { + "t": "Opaque", + "extension": "tket2.angle", + "id": "angle", + "args": [], + "bound": "C" + } + ], + "output": [ + { + "t": "Opaque", + "extension": "tket2.angle", + "id": "angle", + "args": [], + "bound": "C" + } + ], + "extension_reqs": [] + } + }, + "binary": false + }, + "adiv": { + "extension": "tket2.angle", + "name": "adiv", + "description": "Divide angle by an integer. If the integer is not a power of 2, or if the resulting denominator would exceed 2^64, the result is rounded to the nearest multiple of 2 pi / 2^ 64", + "signature": { + "params": [], + "body": { + "input": [ + { + "t": "Opaque", + "extension": "tket2.angle", + "id": "angle", + "args": [], + "bound": "C" + }, + { + "t": "I" + } + ], + "output": [ + { + "t": "Opaque", + "extension": "tket2.angle", + "id": "angle", + "args": [], + "bound": "C" + } + ], + "extension_reqs": [] + } + }, + "binary": false + }, + "aeq": { + "extension": "tket2.angle", + "name": "aeq", + "description": "check angle equality", + "signature": { + "params": [], + "body": { + "input": [ + { + "t": "Opaque", + "extension": "tket2.angle", + "id": "angle", + "args": [], + "bound": "C" + }, + { + "t": "Opaque", + "extension": "tket2.angle", + "id": "angle", + "args": [], + "bound": "C" + } + ], + "output": [ + { + "t": "Sum", + "s": "Unit", + "size": 2 + } + ], + "extension_reqs": [] + } + }, + "binary": false + }, + "afromrad": { + "extension": "tket2.angle", + "name": "afromrad", + "description": "construct angle from radians, rounding given a log-denominator", + "signature": { + "params": [], + "body": { + "input": [ + { + "t": "I" + }, + { + "t": "Opaque", + "extension": "arithmetic.float.types", + "id": "float64", + "args": [], + "bound": "C" + } + ], + "output": [ + { + "t": "Opaque", + "extension": "tket2.angle", + "id": "angle", + "args": [], + "bound": "C" + } + ], + "extension_reqs": [] + } + }, + "binary": false + }, + "amul": { + "extension": "tket2.angle", + "name": "amul", + "description": "multiply angle by a scalar", + "signature": { + "params": [], + "body": { + "input": [ + { + "t": "Opaque", + "extension": "tket2.angle", + "id": "angle", + "args": [], + "bound": "C" + }, + { + "t": "I" + } + ], + "output": [ + { + "t": "Opaque", + "extension": "tket2.angle", + "id": "angle", + "args": [], + "bound": "C" + } + ], + "extension_reqs": [] + } + }, + "binary": false + }, + "aneg": { + "extension": "tket2.angle", + "name": "aneg", + "description": "negation of an angle", + "signature": { + "params": [], + "body": { + "input": [ + { + "t": "Opaque", + "extension": "tket2.angle", + "id": "angle", + "args": [], + "bound": "C" + } + ], + "output": [ + { + "t": "Opaque", + "extension": "tket2.angle", + "id": "angle", + "args": [], + "bound": "C" + } + ], + "extension_reqs": [] + } + }, + "binary": false + }, + "anew": { + "extension": "tket2.angle", + "name": "anew", + "description": "construct angle from numerator and log-denominator, returning an error if invalid", + "signature": { + "params": [], + "body": { + "input": [ + { + "t": "I" + }, + { + "t": "I" + } + ], + "output": [ + { + "t": "Sum", + "s": "General", + "rows": [ + [ + { + "t": "Opaque", + "extension": "prelude", + "id": "error", + "args": [], + "bound": "C" + } + ], + [ + { + "t": "Opaque", + "extension": "tket2.angle", + "id": "angle", + "args": [], + "bound": "C" + } + ] + ] + } + ], + "extension_reqs": [] + } + }, + "binary": false + }, + "aparts": { + "extension": "tket2.angle", + "name": "aparts", + "description": "decompose angle into numerator and log-denominator", + "signature": { + "params": [], + "body": { + "input": [ + { + "t": "Opaque", + "extension": "tket2.angle", + "id": "angle", + "args": [], + "bound": "C" + } + ], + "output": [ + { + "t": "I" + }, + { + "t": "I" + } + ], + "extension_reqs": [] + } + }, + "binary": false + }, + "asub": { + "extension": "tket2.angle", + "name": "asub", + "description": "subtraction of the second angle from the first", + "signature": { + "params": [], + "body": { + "input": [ + { + "t": "Opaque", + "extension": "tket2.angle", + "id": "angle", + "args": [], + "bound": "C" + }, + { + "t": "Opaque", + "extension": "tket2.angle", + "id": "angle", + "args": [], + "bound": "C" + } + ], + "output": [ + { + "t": "Opaque", + "extension": "tket2.angle", + "id": "angle", + "args": [], + "bound": "C" + } + ], + "extension_reqs": [] + } + }, + "binary": false + }, + "atorad": { + "extension": "tket2.angle", + "name": "atorad", + "description": "convert angle to radians", + "signature": { + "params": [], + "body": { + "input": [ + { + "t": "Opaque", + "extension": "tket2.angle", + "id": "angle", + "args": [], + "bound": "C" + } + ], + "output": [ + { + "t": "Opaque", + "extension": "arithmetic.float.types", + "id": "float64", + "args": [], + "bound": "C" + } + ], + "extension_reqs": [] + } + }, + "binary": false + }, + "atrunc": { + "extension": "tket2.angle", + "name": "atrunc", + "description": "truncate an angle to one with a lower log-denominator with the nearest value, rounding down in [0, 2π) if necessary", + "signature": { + "params": [], + "body": { + "input": [ + { + "t": "Opaque", + "extension": "tket2.angle", + "id": "angle", + "args": [], + "bound": "C" + }, + { + "t": "I" + } + ], + "output": [ + { + "t": "Opaque", + "extension": "tket2.angle", + "id": "angle", + "args": [], + "bound": "C" + } + ], + "extension_reqs": [] + } + }, + "binary": false + } + } +} diff --git a/tket2-py/tket2/extensions/_json_defs/tket2/futures.json b/tket2-py/tket2/extensions/_json_defs/tket2/futures.json new file mode 100644 index 00000000..7263042b --- /dev/null +++ b/tket2-py/tket2/extensions/_json_defs/tket2/futures.json @@ -0,0 +1,172 @@ +{ + "version": "0.1.0", + "name": "tket2.futures", + "extension_reqs": [], + "types": { + "Future": { + "extension": "tket2.futures", + "name": "Future", + "params": [ + { + "tp": "Type", + "b": "A" + } + ], + "description": "A value that is computed asynchronously", + "bound": { + "b": "Explicit", + "bound": "A" + } + } + }, + "values": {}, + "operations": { + "Dup": { + "extension": "tket2.futures", + "name": "Dup", + "description": "Duplicate a Future. The original Future is consumed and two Futures are returned", + "signature": { + "params": [ + { + "tp": "Type", + "b": "A" + } + ], + "body": { + "input": [ + { + "t": "Opaque", + "extension": "tket2.futures", + "id": "Future", + "args": [ + { + "tya": "Type", + "ty": { + "t": "V", + "i": 0, + "b": "A" + } + } + ], + "bound": "A" + } + ], + "output": [ + { + "t": "Opaque", + "extension": "tket2.futures", + "id": "Future", + "args": [ + { + "tya": "Type", + "ty": { + "t": "V", + "i": 0, + "b": "A" + } + } + ], + "bound": "A" + }, + { + "t": "Opaque", + "extension": "tket2.futures", + "id": "Future", + "args": [ + { + "tya": "Type", + "ty": { + "t": "V", + "i": 0, + "b": "A" + } + } + ], + "bound": "A" + } + ], + "extension_reqs": [] + } + }, + "binary": false + }, + "Free": { + "extension": "tket2.futures", + "name": "Free", + "description": "Consume a future without reading it.", + "signature": { + "params": [ + { + "tp": "Type", + "b": "A" + } + ], + "body": { + "input": [ + { + "t": "Opaque", + "extension": "tket2.futures", + "id": "Future", + "args": [ + { + "tya": "Type", + "ty": { + "t": "V", + "i": 0, + "b": "A" + } + } + ], + "bound": "A" + } + ], + "output": [], + "extension_reqs": [] + } + }, + "binary": false + }, + "Read": { + "extension": "tket2.futures", + "name": "Read", + "description": "Read a value from a Future, consuming it", + "signature": { + "params": [ + { + "tp": "Type", + "b": "A" + } + ], + "body": { + "input": [ + { + "t": "Opaque", + "extension": "tket2.futures", + "id": "Future", + "args": [ + { + "tya": "Type", + "ty": { + "t": "V", + "i": 0, + "b": "A" + } + } + ], + "bound": "A" + } + ], + "output": [ + { + "t": "V", + "i": 0, + "b": "A" + } + ], + "extension_reqs": [] + } + }, + "binary": false + } + } +} diff --git a/tket2-py/tket2/extensions/_json_defs/tket2/hseries.json b/tket2-py/tket2/extensions/_json_defs/tket2/hseries.json new file mode 100644 index 00000000..700ddefa --- /dev/null +++ b/tket2-py/tket2/extensions/_json_defs/tket2/hseries.json @@ -0,0 +1,265 @@ +{ + "version": "0.1.0", + "name": "tket2.hseries", + "extension_reqs": [ + "arithmetic.float.types", + "prelude", + "tket2.angle", + "tket2.futures" + ], + "types": {}, + "values": {}, + "operations": { + "LazyMeasure": { + "extension": "tket2.hseries", + "name": "LazyMeasure", + "description": "LazyMeasure", + "signature": { + "params": [], + "body": { + "input": [ + { + "t": "Q" + } + ], + "output": [ + { + "t": "Q" + }, + { + "t": "Opaque", + "extension": "tket2.futures", + "id": "Future", + "args": [ + { + "tya": "Type", + "ty": { + "t": "Sum", + "s": "Unit", + "size": 2 + } + } + ], + "bound": "A" + } + ], + "extension_reqs": [] + } + }, + "binary": false + }, + "Measure": { + "extension": "tket2.hseries", + "name": "Measure", + "description": "Measure", + "signature": { + "params": [], + "body": { + "input": [ + { + "t": "Q" + } + ], + "output": [ + { + "t": "Q" + }, + { + "t": "Sum", + "s": "Unit", + "size": 2 + } + ], + "extension_reqs": [] + } + }, + "binary": false + }, + "PhasedX": { + "extension": "tket2.hseries", + "name": "PhasedX", + "description": "PhasedX", + "signature": { + "params": [], + "body": { + "input": [ + { + "t": "Q" + }, + { + "t": "Opaque", + "extension": "arithmetic.float.types", + "id": "float64", + "args": [], + "bound": "C" + }, + { + "t": "Opaque", + "extension": "arithmetic.float.types", + "id": "float64", + "args": [], + "bound": "C" + } + ], + "output": [ + { + "t": "Q" + } + ], + "extension_reqs": [] + } + }, + "binary": false + }, + "QAlloc": { + "extension": "tket2.hseries", + "name": "QAlloc", + "description": "QAlloc", + "signature": { + "params": [], + "body": { + "input": [], + "output": [ + { + "t": "Q" + } + ], + "extension_reqs": [] + } + }, + "binary": false + }, + "QFree": { + "extension": "tket2.hseries", + "name": "QFree", + "description": "QFree", + "signature": { + "params": [], + "body": { + "input": [ + { + "t": "Q" + } + ], + "output": [], + "extension_reqs": [] + } + }, + "binary": false + }, + "Reset": { + "extension": "tket2.hseries", + "name": "Reset", + "description": "Reset", + "signature": { + "params": [], + "body": { + "input": [ + { + "t": "Q" + } + ], + "output": [ + { + "t": "Q" + } + ], + "extension_reqs": [] + } + }, + "binary": false + }, + "Rz": { + "extension": "tket2.hseries", + "name": "Rz", + "description": "Rz", + "signature": { + "params": [], + "body": { + "input": [ + { + "t": "Q" + }, + { + "t": "Opaque", + "extension": "arithmetic.float.types", + "id": "float64", + "args": [], + "bound": "C" + } + ], + "output": [ + { + "t": "Q" + } + ], + "extension_reqs": [] + } + }, + "binary": false + }, + "ZZMax": { + "extension": "tket2.hseries", + "name": "ZZMax", + "description": "ZZMax", + "signature": { + "params": [], + "body": { + "input": [ + { + "t": "Q" + }, + { + "t": "Q" + } + ], + "output": [ + { + "t": "Q" + }, + { + "t": "Q" + } + ], + "extension_reqs": [] + } + }, + "binary": false + }, + "ZZPhase": { + "extension": "tket2.hseries", + "name": "ZZPhase", + "description": "ZZPhase", + "signature": { + "params": [], + "body": { + "input": [ + { + "t": "Q" + }, + { + "t": "Q" + }, + { + "t": "Opaque", + "extension": "arithmetic.float.types", + "id": "float64", + "args": [], + "bound": "C" + } + ], + "output": [ + { + "t": "Q" + }, + { + "t": "Q" + } + ], + "extension_reqs": [] + } + }, + "binary": false + } + } +} diff --git a/tket2-py/tket2/extensions/_json_defs/tket2/quantum.json b/tket2-py/tket2/extensions/_json_defs/tket2/quantum.json new file mode 100644 index 00000000..bf48f5f2 --- /dev/null +++ b/tket2-py/tket2/extensions/_json_defs/tket2/quantum.json @@ -0,0 +1,664 @@ +{ + "version": "0.1.0", + "name": "tket2.quantum", + "extension_reqs": [], + "types": {}, + "values": {}, + "operations": { + "CRz": { + "extension": "tket2.quantum", + "name": "CRz", + "description": "CRz", + "misc": { + "commutation": [] + }, + "signature": { + "params": [], + "body": { + "input": [ + { + "t": "Q" + }, + { + "t": "Q" + }, + { + "t": "Opaque", + "extension": "tket2.angle", + "id": "angle", + "args": [], + "bound": "C" + } + ], + "output": [ + { + "t": "Q" + }, + { + "t": "Q" + } + ], + "extension_reqs": [] + } + }, + "binary": false + }, + "CX": { + "extension": "tket2.quantum", + "name": "CX", + "description": "CX", + "misc": { + "commutation": [ + [ + 0, + "Z" + ], + [ + 1, + "X" + ] + ] + }, + "signature": { + "params": [], + "body": { + "input": [ + { + "t": "Q" + }, + { + "t": "Q" + } + ], + "output": [ + { + "t": "Q" + }, + { + "t": "Q" + } + ], + "extension_reqs": [] + } + }, + "binary": false + }, + "CY": { + "extension": "tket2.quantum", + "name": "CY", + "description": "CY", + "misc": { + "commutation": [] + }, + "signature": { + "params": [], + "body": { + "input": [ + { + "t": "Q" + }, + { + "t": "Q" + } + ], + "output": [ + { + "t": "Q" + }, + { + "t": "Q" + } + ], + "extension_reqs": [] + } + }, + "binary": false + }, + "CZ": { + "extension": "tket2.quantum", + "name": "CZ", + "description": "CZ", + "misc": { + "commutation": [ + [ + 0, + "Z" + ], + [ + 1, + "Z" + ] + ] + }, + "signature": { + "params": [], + "body": { + "input": [ + { + "t": "Q" + }, + { + "t": "Q" + } + ], + "output": [ + { + "t": "Q" + }, + { + "t": "Q" + } + ], + "extension_reqs": [] + } + }, + "binary": false + }, + "H": { + "extension": "tket2.quantum", + "name": "H", + "description": "H", + "misc": { + "commutation": [] + }, + "signature": { + "params": [], + "body": { + "input": [ + { + "t": "Q" + } + ], + "output": [ + { + "t": "Q" + } + ], + "extension_reqs": [] + } + }, + "binary": false + }, + "Measure": { + "extension": "tket2.quantum", + "name": "Measure", + "description": "Measure", + "misc": { + "commutation": [ + [ + 0, + "Z" + ] + ] + }, + "signature": { + "params": [], + "body": { + "input": [ + { + "t": "Q" + } + ], + "output": [ + { + "t": "Q" + }, + { + "t": "Sum", + "s": "Unit", + "size": 2 + } + ], + "extension_reqs": [] + } + }, + "binary": false + }, + "QAlloc": { + "extension": "tket2.quantum", + "name": "QAlloc", + "description": "QAlloc", + "misc": { + "commutation": [] + }, + "signature": { + "params": [], + "body": { + "input": [], + "output": [ + { + "t": "Q" + } + ], + "extension_reqs": [] + } + }, + "binary": false + }, + "QFree": { + "extension": "tket2.quantum", + "name": "QFree", + "description": "QFree", + "misc": { + "commutation": [] + }, + "signature": { + "params": [], + "body": { + "input": [ + { + "t": "Q" + } + ], + "output": [], + "extension_reqs": [] + } + }, + "binary": false + }, + "Reset": { + "extension": "tket2.quantum", + "name": "Reset", + "description": "Reset", + "misc": { + "commutation": [] + }, + "signature": { + "params": [], + "body": { + "input": [ + { + "t": "Q" + } + ], + "output": [ + { + "t": "Q" + } + ], + "extension_reqs": [] + } + }, + "binary": false + }, + "Rx": { + "extension": "tket2.quantum", + "name": "Rx", + "description": "Rx", + "misc": { + "commutation": [ + [ + 0, + "X" + ] + ] + }, + "signature": { + "params": [], + "body": { + "input": [ + { + "t": "Q" + }, + { + "t": "Opaque", + "extension": "tket2.angle", + "id": "angle", + "args": [], + "bound": "C" + } + ], + "output": [ + { + "t": "Q" + } + ], + "extension_reqs": [] + } + }, + "binary": false + }, + "Ry": { + "extension": "tket2.quantum", + "name": "Ry", + "description": "Ry", + "misc": { + "commutation": [] + }, + "signature": { + "params": [], + "body": { + "input": [ + { + "t": "Q" + }, + { + "t": "Opaque", + "extension": "tket2.angle", + "id": "angle", + "args": [], + "bound": "C" + } + ], + "output": [ + { + "t": "Q" + } + ], + "extension_reqs": [] + } + }, + "binary": false + }, + "Rz": { + "extension": "tket2.quantum", + "name": "Rz", + "description": "Rz", + "misc": { + "commutation": [ + [ + 0, + "Z" + ] + ] + }, + "signature": { + "params": [], + "body": { + "input": [ + { + "t": "Q" + }, + { + "t": "Opaque", + "extension": "tket2.angle", + "id": "angle", + "args": [], + "bound": "C" + } + ], + "output": [ + { + "t": "Q" + } + ], + "extension_reqs": [] + } + }, + "binary": false + }, + "S": { + "extension": "tket2.quantum", + "name": "S", + "description": "S", + "misc": { + "commutation": [ + [ + 0, + "Z" + ] + ] + }, + "signature": { + "params": [], + "body": { + "input": [ + { + "t": "Q" + } + ], + "output": [ + { + "t": "Q" + } + ], + "extension_reqs": [] + } + }, + "binary": false + }, + "Sdg": { + "extension": "tket2.quantum", + "name": "Sdg", + "description": "Sdg", + "misc": { + "commutation": [ + [ + 0, + "Z" + ] + ] + }, + "signature": { + "params": [], + "body": { + "input": [ + { + "t": "Q" + } + ], + "output": [ + { + "t": "Q" + } + ], + "extension_reqs": [] + } + }, + "binary": false + }, + "T": { + "extension": "tket2.quantum", + "name": "T", + "description": "T", + "misc": { + "commutation": [ + [ + 0, + "Z" + ] + ] + }, + "signature": { + "params": [], + "body": { + "input": [ + { + "t": "Q" + } + ], + "output": [ + { + "t": "Q" + } + ], + "extension_reqs": [] + } + }, + "binary": false + }, + "Tdg": { + "extension": "tket2.quantum", + "name": "Tdg", + "description": "Tdg", + "misc": { + "commutation": [ + [ + 0, + "Z" + ] + ] + }, + "signature": { + "params": [], + "body": { + "input": [ + { + "t": "Q" + } + ], + "output": [ + { + "t": "Q" + } + ], + "extension_reqs": [] + } + }, + "binary": false + }, + "Toffoli": { + "extension": "tket2.quantum", + "name": "Toffoli", + "description": "Toffoli", + "misc": { + "commutation": [] + }, + "signature": { + "params": [], + "body": { + "input": [ + { + "t": "Q" + }, + { + "t": "Q" + }, + { + "t": "Q" + } + ], + "output": [ + { + "t": "Q" + }, + { + "t": "Q" + }, + { + "t": "Q" + } + ], + "extension_reqs": [] + } + }, + "binary": false + }, + "X": { + "extension": "tket2.quantum", + "name": "X", + "description": "X", + "misc": { + "commutation": [ + [ + 0, + "X" + ] + ] + }, + "signature": { + "params": [], + "body": { + "input": [ + { + "t": "Q" + } + ], + "output": [ + { + "t": "Q" + } + ], + "extension_reqs": [] + } + }, + "binary": false + }, + "Y": { + "extension": "tket2.quantum", + "name": "Y", + "description": "Y", + "misc": { + "commutation": [ + [ + 0, + "Y" + ] + ] + }, + "signature": { + "params": [], + "body": { + "input": [ + { + "t": "Q" + } + ], + "output": [ + { + "t": "Q" + } + ], + "extension_reqs": [] + } + }, + "binary": false + }, + "Z": { + "extension": "tket2.quantum", + "name": "Z", + "description": "Z", + "misc": { + "commutation": [ + [ + 0, + "Z" + ] + ] + }, + "signature": { + "params": [], + "body": { + "input": [ + { + "t": "Q" + } + ], + "output": [ + { + "t": "Q" + } + ], + "extension_reqs": [] + } + }, + "binary": false + }, + "symbolic_angle": { + "extension": "tket2.quantum", + "name": "symbolic_angle", + "description": "Store a sympy expression that can be evaluated to an angle.", + "signature": { + "params": [ + { + "tp": "String" + } + ], + "body": { + "input": [], + "output": [ + { + "t": "Opaque", + "extension": "tket2.angle", + "id": "angle", + "args": [], + "bound": "C" + } + ], + "extension_reqs": [] + } + }, + "binary": false + } + } +} diff --git a/tket2-py/tket2/extensions/_json_defs/tket2/result.json b/tket2-py/tket2/extensions/_json_defs/tket2/result.json new file mode 100644 index 00000000..85ed4bc4 --- /dev/null +++ b/tket2-py/tket2/extensions/_json_defs/tket2/result.json @@ -0,0 +1,360 @@ +{ + "version": "0.1.0", + "name": "tket2.result", + "extension_reqs": [ + "arithmetic.float.types", + "arithmetic.int.types" + ], + "types": {}, + "values": {}, + "operations": { + "result_array_bool": { + "extension": "tket2.result", + "name": "result_array_bool", + "description": "Report an array of boolean results.", + "signature": { + "params": [ + { + "tp": "String" + }, + { + "tp": "BoundedNat", + "bound": null + } + ], + "body": { + "input": [ + { + "t": "Opaque", + "extension": "prelude", + "id": "array", + "args": [ + { + "tya": "Variable", + "idx": 1, + "cached_decl": { + "tp": "BoundedNat", + "bound": null + } + }, + { + "tya": "Type", + "ty": { + "t": "Sum", + "s": "Unit", + "size": 2 + } + } + ], + "bound": "C" + } + ], + "output": [], + "extension_reqs": [] + } + }, + "binary": false + }, + "result_array_f64": { + "extension": "tket2.result", + "name": "result_array_f64", + "description": "Report an array of floating-point results.", + "signature": { + "params": [ + { + "tp": "String" + }, + { + "tp": "BoundedNat", + "bound": null + } + ], + "body": { + "input": [ + { + "t": "Opaque", + "extension": "prelude", + "id": "array", + "args": [ + { + "tya": "Variable", + "idx": 1, + "cached_decl": { + "tp": "BoundedNat", + "bound": null + } + }, + { + "tya": "Type", + "ty": { + "t": "Opaque", + "extension": "arithmetic.float.types", + "id": "float64", + "args": [], + "bound": "C" + } + } + ], + "bound": "C" + } + ], + "output": [], + "extension_reqs": [] + } + }, + "binary": false + }, + "result_array_int": { + "extension": "tket2.result", + "name": "result_array_int", + "description": "Report an array of signed integer results.", + "signature": { + "params": [ + { + "tp": "String" + }, + { + "tp": "BoundedNat", + "bound": null + }, + { + "tp": "BoundedNat", + "bound": 7 + } + ], + "body": { + "input": [ + { + "t": "Opaque", + "extension": "prelude", + "id": "array", + "args": [ + { + "tya": "Variable", + "idx": 1, + "cached_decl": { + "tp": "BoundedNat", + "bound": null + } + }, + { + "tya": "Type", + "ty": { + "t": "Opaque", + "extension": "arithmetic.int.types", + "id": "int", + "args": [ + { + "tya": "Variable", + "idx": 2, + "cached_decl": { + "tp": "BoundedNat", + "bound": 7 + } + } + ], + "bound": "C" + } + } + ], + "bound": "C" + } + ], + "output": [], + "extension_reqs": [] + } + }, + "binary": false + }, + "result_array_uint": { + "extension": "tket2.result", + "name": "result_array_uint", + "description": "Report an array of unsigned integer results.", + "signature": { + "params": [ + { + "tp": "String" + }, + { + "tp": "BoundedNat", + "bound": null + }, + { + "tp": "BoundedNat", + "bound": 7 + } + ], + "body": { + "input": [ + { + "t": "Opaque", + "extension": "prelude", + "id": "array", + "args": [ + { + "tya": "Variable", + "idx": 1, + "cached_decl": { + "tp": "BoundedNat", + "bound": null + } + }, + { + "tya": "Type", + "ty": { + "t": "Opaque", + "extension": "arithmetic.int.types", + "id": "int", + "args": [ + { + "tya": "Variable", + "idx": 2, + "cached_decl": { + "tp": "BoundedNat", + "bound": 7 + } + } + ], + "bound": "C" + } + } + ], + "bound": "C" + } + ], + "output": [], + "extension_reqs": [] + } + }, + "binary": false + }, + "result_bool": { + "extension": "tket2.result", + "name": "result_bool", + "description": "Report a boolean result.", + "signature": { + "params": [ + { + "tp": "String" + } + ], + "body": { + "input": [ + { + "t": "Sum", + "s": "Unit", + "size": 2 + } + ], + "output": [], + "extension_reqs": [] + } + }, + "binary": false + }, + "result_f64": { + "extension": "tket2.result", + "name": "result_f64", + "description": "Report a floating-point result.", + "signature": { + "params": [ + { + "tp": "String" + } + ], + "body": { + "input": [ + { + "t": "Opaque", + "extension": "arithmetic.float.types", + "id": "float64", + "args": [], + "bound": "C" + } + ], + "output": [], + "extension_reqs": [] + } + }, + "binary": false + }, + "result_int": { + "extension": "tket2.result", + "name": "result_int", + "description": "Report a signed integer result.", + "signature": { + "params": [ + { + "tp": "String" + }, + { + "tp": "BoundedNat", + "bound": 7 + } + ], + "body": { + "input": [ + { + "t": "Opaque", + "extension": "arithmetic.int.types", + "id": "int", + "args": [ + { + "tya": "Variable", + "idx": 1, + "cached_decl": { + "tp": "BoundedNat", + "bound": 7 + } + } + ], + "bound": "C" + } + ], + "output": [], + "extension_reqs": [] + } + }, + "binary": false + }, + "result_uint": { + "extension": "tket2.result", + "name": "result_uint", + "description": "Report an unsigned integer result.", + "signature": { + "params": [ + { + "tp": "String" + }, + { + "tp": "BoundedNat", + "bound": 7 + } + ], + "body": { + "input": [ + { + "t": "Opaque", + "extension": "arithmetic.int.types", + "id": "int", + "args": [ + { + "tya": "Variable", + "idx": 1, + "cached_decl": { + "tp": "BoundedNat", + "bound": 7 + } + } + ], + "bound": "C" + } + ], + "output": [], + "extension_reqs": [] + } + }, + "binary": false + } + } +}