From 18845fd569a01a25d59da5e355c9e2381bd25f3d Mon Sep 17 00:00:00 2001 From: Seyon Sivarajah Date: Tue, 19 Sep 2023 15:06:18 +0100 Subject: [PATCH 1/2] docs: add operation constraint to quantum extension Closes #170 --- specification/hugr.md | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/specification/hugr.md b/specification/hugr.md index 4e7fcf215..c12926955 100644 --- a/specification/hugr.md +++ b/specification/hugr.md @@ -1727,10 +1727,19 @@ allocation, and the compiler can add/remove/move these operations to use more or fewer qubits. In some use cases, that may not be desirable, and we may instead want to guarantee only a certain number of qubits are used by the program. For this purpose TKET2 places additional -constraints on the `main` function that are in line with TKET1 backwards -compatibility. Namely the main function takes one `Array` +constraints on the HUGR that are in line with TKET1 backwards +compatibility: + +1. The `main` function takes one `Array` input and has one output of the same type (the same statically known -size). If further the program does not contain any `qalloc` or `qfree` +size). +2. All Operations that have a `FunctionType` involving `Qubit`: + 1. Have as many `Qubit` input wires as output. + 2. Guarantee semantics that when filtered to `Qubit` only, there is a + bijection such that the _nth_ input maps to the _nth_ output. + +This means we can treat all `Qubit` operations as returning all qubits they take +in. If further the program does not contain any `qalloc` or `qfree` operations we can state the program only uses `N` qubits. ### Higher-order (Tierkreis) Extension From 7065c20837692c6b149d51e69300918caf9101ce Mon Sep 17 00:00:00 2001 From: Seyon Sivarajah Date: Tue, 19 Sep 2023 17:04:43 +0100 Subject: [PATCH 2/2] remove semantic mapping constraint --- specification/hugr.md | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/specification/hugr.md b/specification/hugr.md index c12926955..97cccf829 100644 --- a/specification/hugr.md +++ b/specification/hugr.md @@ -1733,13 +1733,14 @@ compatibility: 1. The `main` function takes one `Array` input and has one output of the same type (the same statically known size). -2. All Operations that have a `FunctionType` involving `Qubit`: - 1. Have as many `Qubit` input wires as output. - 2. Guarantee semantics that when filtered to `Qubit` only, there is a - bijection such that the _nth_ input maps to the _nth_ output. +2. All Operations that have a `FunctionType` involving `Qubit` have as + many `Qubit` input wires as output. -This means we can treat all `Qubit` operations as returning all qubits they take -in. If further the program does not contain any `qalloc` or `qfree` + +With these constraints, we can treat all `Qubit` operations as returning all qubits they take +in. The implicit bijection from input `Qubit` to output allows register +allocation for all `Qubit` wires. +If further the program does not contain any `qalloc` or `qfree` operations we can state the program only uses `N` qubits. ### Higher-order (Tierkreis) Extension