Skip to content

Commit 9df1b0e

Browse files
elenbaascrturrado
andauthored
[CQT-271] Update spec with newly added instructions (#79)
* Add initial pages for init, barrier, and wait instructions. Add SWAP gate to standard gate set. * Fix theta value of CRk. * Add documentation of barrier instruction. * Add documentation on the wait instruction. * Update docs/language_specification/statements/instructions/control_instructions/barrier_instruction.md Co-authored-by: Roberto Turrado Camblor <[email protected]> * Update docs/language_specification/statements/instructions/control_instructions/barrier_instruction.md Co-authored-by: Roberto Turrado Camblor <[email protected]> * Update docs/language_specification/statements/instructions/control_instructions/barrier_instruction.md Co-authored-by: Roberto Turrado Camblor <[email protected]> * Update docs/language_specification/statements/instructions/non_unitary_instructions/init_instruction.md Co-authored-by: Roberto Turrado Camblor <[email protected]> * Update docs/language_specification/statements/instructions/non_unitary_instructions/init_instruction.md Co-authored-by: Roberto Turrado Camblor <[email protected]> * Update docs/language_specification/statements/instructions/non_unitary_instructions/init_instruction.md Co-authored-by: Roberto Turrado Camblor <[email protected]> * Resolve review comments. * Update docs/language_specification/statements/instructions/control_instructions/wait_instruction.md Co-authored-by: Roberto Turrado Camblor <[email protected]> --------- Co-authored-by: Roberto Turrado Camblor <[email protected]>
1 parent 8c135df commit 9df1b0e

File tree

9 files changed

+347
-29
lines changed

9 files changed

+347
-29
lines changed

docs/appendices/spin_2.md renamed to docs/appendices/spin_2plus.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
# Spin-2
1+
# Spin-2+
22

3-
The Spin-2 system developed by QuTech supports the following subset of the cQASM language:
3+
The Spin-2+ system developed by QuTech supports the following subset of the cQASM language:
44

55
* Multiple line comments in `/* … */` are supported.
66
* Single line comments in `// …`, `# …`, `/* …*/` are supported.
@@ -13,7 +13,6 @@ The Spin-2 system developed by QuTech supports the following subset of the cQASM
1313
* The single-gate-multiple-qubit (SGMQ) notation is fully supported for single qubit gates
1414
* The SGMQ notation is not supported for two qubit gates.
1515
* The SGMQ notation results in a bundle resulting in a sequential list of gate operations.
16-
* Subcircuit headers are accepted (and subsequently ignored).
1716
* All other libqasm 1.x language structures are not supported.
1817
* No `prep_X` and `measure_X` instructions are allowed, the lls will init all supported qubits before circuit execution
1918
and measure all in the z-basis at the end of the circuit and only return the subset as defined in the qubit register.

docs/language_specification/general_overview.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,12 @@ The unitary operations, commonly know as gates, can be either
4343
- Instructions:
4444
- [Unitary instructions](statements/instructions/unitary_instructions.md) (_i.e._, gates)
4545
- Non-unitary instructions:
46+
- [Init instruction](statements/instructions/non_unitary_instructions/init_instruction.md)
4647
- [Measure instruction](statements/instructions/non_unitary_instructions/measure_instruction.md)
4748
- [Reset instruction](statements/instructions/non_unitary_instructions/reset_instruction.md)
49+
- Control instructions:
50+
- [Barrier instruction](statements/instructions/control_instructions/barrier_instruction.md)
51+
- [Wait instruction](statements/instructions/control_instructions/wait_instruction.md)
4852
- [Single-gate-multiple-qubit (SGMQ) notation](statements/instructions/single-gate-multiple-qubit-notation.md)
4953

5054
!!! example ""
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
The **`barrier`** instruction is a single-qubit control instruction
2+
that is used to constrain the optimization of a scheduler.
3+
It tells a scheduler that instructions on the specified qubit(s) cannot be scheduled across the barrier.
4+
See the [**`wait`** instruction](wait_instruction.md), to impose a time delay following a barrier.
5+
6+
The general form of the **`barrier`** instruction is as follows:
7+
8+
!!! info ""
9+
10+
&emsp;**`barrier`** _qubit-argument_
11+
12+
??? info "Grammar for **`barrier`** instruction"
13+
14+
_barrier-instruction_:
15+
&emsp; __`barrier`__ _qubit-argument_
16+
17+
_qubit-argument_:
18+
&emsp; _qubit-variable_
19+
&emsp; _qubit-index_
20+
21+
_qubit-variable_:
22+
&emsp; _identifier_
23+
24+
_qubit-index_:
25+
&emsp; _index_
26+
27+
!!! note
28+
29+
The **`barrier`** instruction accepts
30+
[SGMQ notation](../single-gate-multiple-qubit-notation.md).
31+
SGMQ notation allows you to express the application of an instruction to multiple qubits.
32+
However, SGMQ notation does not guarantee simultaneity.
33+
In general, a compiler will unpack this notation to separate consecutive
34+
single-qubit instructions on each respective qubit.
35+
This will depend on the scheduling optimization that is applied during the compilation process.
36+
37+
For certain backends,
38+
groups of consecutive **`barrier`** instructions are linked together to form a _uniform_ barrier,
39+
across which no instructions on the specified qubits can be scheduled.
40+
Note that one can create a group of consecutive **`barrier`** instructions, _i.e._ a _uniform_ barrier,
41+
using SGMQ notation.
42+
43+
!!! example
44+
45+
=== "Single qubit"
46+
47+
```linenums="1", hl_lines="3"
48+
qubit q
49+
X q
50+
barrier q
51+
X q
52+
```
53+
54+
=== "Multiple qubits"
55+
56+
```linenums="1", hl_lines="3"
57+
qubit[3] q
58+
X q[0]
59+
barrier q[0, 1]
60+
H q[0]
61+
X q[2]
62+
H q[1]
63+
```
64+
65+
In the examples above it is shown how the **`barrier`** instruction can be used with a single qubit and multiple qubits.
66+
In the case of the single qubit,
67+
an optimizer would generally fuse the two **`X`** gates into a single identity gate, **`I`**.
68+
However, because of the presence of the **`barrier`** instruction, the user explicitly states that the instructions on
69+
**`q`** are not permitted to be optimized across the barrier.
70+
The second example shows that a barrier can be placed for multiple qubits.
71+
Note that the **`barrier`** instruction is applied to qubits **`q[0]`** and **`q[1]`**.
72+
Qubit **`q[2]`** can be optimized freely across this circuit, _i.e._, be scheduled before or after the barrier.
73+
74+
The following code snippet illustrates how the **`barrier`** instruction might be used in context.
75+
76+
```linenums="1", hl_lines="9 12 19"
77+
version 3.0
78+
79+
qubit[2] q
80+
init q
81+
82+
// Phi+ state
83+
H q[0]
84+
CNOT q[0], q[1]
85+
barrier q
86+
b[0,1] = measure q
87+
88+
barrier q
89+
reset q
90+
91+
// Psi+ state
92+
H q[0]
93+
X q[1]
94+
CNOT q[0], q[1]
95+
barrier q
96+
b[2, 3] = measure q
97+
```
98+
99+
In the above code snippet, the $\Phi_{+}$ and $\Psi_{+}$ Bell states are generated and measured, successively.
100+
The **`barrier`** instruction is used to guarantee that the
101+
[**`measure`** instruction](../non_unitary_instructions/measure_instruction.md) is scheduled _after_ the respective
102+
states have been generated.
103+
Moreover, an extra **`barrier`** instruction is used to separate the generation and measurement of the two Bell states.
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
The **`wait`** instruction is a single-qubit control instruction that is used to constrain the optimization of a
2+
scheduler.
3+
It tells the scheduler to delay the subsequent instructions on the specified qubit(s) by a given time.
4+
The delay time is passed along with the instruction as a dimensionless parameter,
5+
the unit of which represents the duration of a single-qubit gate on the backend,
6+
_i.e._, an execution cycle.
7+
Moreover, the **`wait`** instruction will also function as a [_barrier_](barrier_instruction.md),
8+
telling the scheduler that instructions on the specified qubit(s) cannot be scheduled across the position of the
9+
**`wait`** instruction.
10+
11+
!!! warning
12+
13+
The [**`barrier`** instruction](barrier_instruction.md) may be considered equal to the **`wait`** instruction with a
14+
time delay set to 0.
15+
Note however that for certain backends, groups of consecutive **`barrier`** instructions are linked together to
16+
form a _uniform_ barrier, across which no instructions on the specified qubits can be scheduled.
17+
This is **not** the case for the **`wait`** instruction; consecutive **`wait`** instructions on different qubits
18+
are considered to be independent instructions.
19+
20+
Multiple successive **`wait`** instructions on the _same_ qubit,
21+
however, may be fused into a single **`wait`** instruction,
22+
where the delay time is set to the sum of the delay times of the separate instructions.
23+
For example,
24+
25+
```hl_lines="1 3"
26+
wait(3) q[0]
27+
wait(4) q[1]
28+
wait(2) q[0]
29+
```
30+
31+
could be optimized to:
32+
33+
```hl_lines="1"
34+
wait(5) q[0]
35+
wait(4) q[1]
36+
```
37+
38+
The general form of the **`wait`** instruction is as follows:
39+
40+
!!! info ""
41+
42+
&emsp;__`wait(`__ _parameter_ __`)`__ _qubit-argument_
43+
44+
??? info "Grammar for **`wait`** instruction"
45+
46+
_wait-instruction_:
47+
&emsp;__`wait(`__ _parameter_ __`)`__ _qubit-argument_
48+
49+
_parameter_:
50+
&emsp; _integer-literal_
51+
52+
_qubit-argument_:
53+
&emsp; _qubit-variable_
54+
&emsp; _qubit-index_
55+
56+
_qubit-variable_:
57+
&emsp; _identifier_
58+
59+
_qubit-index_:
60+
&emsp; _index_
61+
62+
!!! note
63+
64+
The **`wait`** instruction accepts
65+
[SGMQ notation](../single-gate-multiple-qubit-notation.md), similar to gates.
66+
67+
!!! example
68+
69+
=== "Single qubit"
70+
71+
```linenums="1", hl_lines="3"
72+
qubit q
73+
X q
74+
wait(5) q // time delay of 5 execution cycles
75+
X q
76+
```
77+
78+
=== "Multiple qubits"
79+
80+
```linenums="1", hl_lines="3"
81+
qubit[3] q
82+
X q[0]
83+
wait(5) q[0, 1] // time delay of 5 execution cycles
84+
H q[0]
85+
X q[2]
86+
H q[1]
87+
```
88+
89+
In the examples above it is shown how the **`wait`** instruction can be used with a single qubit and multiple qubits.
90+
In the case of the single qubit, the **`wait`** instruction tells the scheduler to schedule a delay of 5 execution
91+
cycles between the successive **`X`** gates.
92+
Note that it also implicitly places a [barrier](barrier_instruction.md) between the two **`X`** gates,
93+
such that they cannot be fused into a single identity gate, **`I`**.
94+
In the second example, using SGMQ notation, the **`wait`** instruction is applied to qubits **`q[0]`** and **`q[1]`**.
95+
Enforcing a delay of 5 execution cycles on any following instructions involving those qubits,
96+
_e.g._, here **`H q[0]`** and **`H q[1]`**.
97+
Qubit **`q[2]`** can be optimized freely across this circuit,
98+
_i.e._, be scheduled before or after **`wait`** instruction, regardless of any specified time delay.
99+
100+
The following code snippet illustrates how the **`wait`** instruction might be used in context.
101+
102+
```linenums="1", hl_lines="7"
103+
version 3.0
104+
105+
qubit[2] q
106+
bit[2] b
107+
init q
108+
109+
wait(100) q[0]
110+
b[0] = measure q[0]
111+
```
112+
113+
Here, the [measurement](../non_unitary_instructions/measure_instruction.md) of **`q[0]`** is forced to be scheduled at
114+
least 100 execution cycles after the [initialization](../non_unitary_instructions/init_instruction.md)
115+
of the qubit is complete.
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
In general, qubits are initialized in the $|0\rangle$ state.
2+
Nonetheless, to explicitly initialize (particular) qubits in the $|0\rangle$ state
3+
one can use the **`init`** instruction.
4+
The general form of an **`init`** instruction is as follows:
5+
6+
!!! info ""
7+
8+
&emsp;**`init`** _qubit-argument_
9+
10+
??? info "Grammar for **`init`** instruction"
11+
12+
_init-instruction_:
13+
&emsp; __`init`__ _qubit-argument_
14+
15+
_qubit-argument_:
16+
&emsp; _qubit-variable_
17+
&emsp; _qubit-index_
18+
19+
_qubit-variable_:
20+
&emsp; _identifier_
21+
22+
_qubit-index_:
23+
&emsp; _index_
24+
25+
!!! example
26+
27+
=== "Initialize a single qubit"
28+
29+
```linenums="1", hl_lines="2"
30+
qubit q
31+
init q
32+
```
33+
34+
=== "Initialize multiple qubits through their register index"
35+
36+
```linenums="1", hl_lines="2"
37+
qubit[5] q
38+
init q[2, 4]
39+
```
40+
41+
!!! note
42+
43+
The **`init`** instruction accepts
44+
[SGMQ notation](../single-gate-multiple-qubit-notation.md), similar to gates.
45+
46+
The following code snippet shows how the **`init`** instruction might be used in context.
47+
48+
```linenums="1" hl_lines="6"
49+
version 3.0
50+
51+
qubit[2] q
52+
bit[2] b
53+
54+
init q // Initializes the qubits to |0>
55+
56+
H q[0]
57+
CNOT q[0], q[1]
58+
59+
b = measure q
60+
```
61+
62+
In the code example above, the qubits are first declared and subsequently initialized.
63+
Note that the initialization of qubits needs to be done before any instruction
64+
(excluding a control instruction)
65+
is applied to them (see warning below).
66+
If one wishes to _reset_ the state of the qubit to $|0\rangle$ mid-circuit,
67+
one should use the [**`reset`**](../non_unitary_instructions/reset_instruction.md) instruction.
68+
69+
70+
!!! warning
71+
72+
Initialization of a qubit can only be done immediately after declaration of the qubit, _i.e._,
73+
it is not possible to initialize a qubit, if prior to that an instruction was applied to the qubit
74+
(excluding a control instruction).
75+
76+
=== "Invalid initialization"
77+
78+
```linenums="1" hl_lines="8"
79+
version 3.0
80+
81+
qubit[2] q
82+
83+
barrier q // Control instructions may be applied to qubits before initialization
84+
H q[1]
85+
86+
init q[1] // Invalid use, since the H gate was applied to q[1] before initialization
87+
```
88+
89+
=== "Valid initialization"
90+
91+
```linenums="1" hl_lines="8"
92+
version 3.0
93+
94+
qubit[2] q
95+
96+
barrier q // Control instructions may be applied to qubits before initialization
97+
H q[1]
98+
99+
init q[0] // Valid use, because no instruction is applied to q[0] before initalization
100+
```
101+

docs/language_specification/statements/instructions/non_unitary_instructions/measure_instruction.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
A **`measure`** instruction performs a measurement to its qubit argument and
22
assigns the outcome to a bit variable.
3-
The general form of a measure instruction is as follows:
3+
The general form of a **`measure`** instruction is as follows:
44

55
!!! info ""
66

77
&emsp;_bit-argument_ **`=`** **`measure`** _qubit-argument_
88

9-
??? info "Grammar for measure instruction"
9+
??? info "Grammar for **`measure`** instruction"
1010

1111
_measure-instruction_:
1212
&emsp; _bit-argument_ __`=`__ __`measure`__ _qubit-argument_
@@ -51,10 +51,10 @@ The general form of a measure instruction is as follows:
5151

5252
!!! note
5353

54-
The measure instruction accepts
54+
The **`measure`** instruction accepts
5555
[SGMQ notation](../single-gate-multiple-qubit-notation.md), similar to gates.
5656

57-
The following code snippet shows how the measure instruction might be used in context.
57+
The following code snippet shows how the **`measure`** instruction might be used in context.
5858

5959
```linenums="1" hl_lines="9"
6060
version 3.0

0 commit comments

Comments
 (0)