microsoft/qdk
Publicmirrored from https://github.com/microsoft/qdkAvailable
source/npm/qsharp/test/circuits-cases/intersecting-wires.qs
52lines · modecode
| 1 | operation Main() : Unit { |
| 2 | use qs = Qubit[5]; |
| 3 | M(qs[0]); |
| 4 | // Crossing a qubit wire |
| 5 | Foo([qs[2], qs[4]]); |
| 6 | // Crossing a classical wire |
| 7 | Foo(qs[0..1]); |
| 8 | // Crossing both qubit and classical wires |
| 9 | Foo([qs[2], qs[0]]); |
| 10 | // Spanning adjacent qubits |
| 11 | Foo(qs[3..4]); |
| 12 | // Crossing classical wire and adjacent qubits |
| 13 | Foo(qs[0..2]); |
| 14 | |
| 15 | // Some more classical wires to intersect |
| 16 | M(qs[2]); |
| 17 | M(qs[2]); |
| 18 | |
| 19 | // Spanning all qubit wires, one classical wire extending |
| 20 | // from the box, and crossing the other classical wires |
| 21 | BoxWithMeasurements(qs); |
| 22 | |
| 23 | use q1 = Qubit(); |
| 24 | use q2 = Qubit(); |
| 25 | Bar(q1); |
| 26 | Bar(q2); |
| 27 | Foo2(q1); |
| 28 | Bar(q1); |
| 29 | Foo2(q1); |
| 30 | Foo2(q2); |
| 31 | Bar(q2); |
| 32 | Foo2(q2); |
| 33 | } |
| 34 | |
| 35 | operation Foo2(q : Qubit) : Unit { |
| 36 | Bar(q); |
| 37 | MResetZ(q); |
| 38 | } |
| 39 | |
| 40 | operation Bar(q : Qubit) : Unit { |
| 41 | X(q); |
| 42 | Y(q); |
| 43 | } |
| 44 | |
| 45 | operation BoxWithMeasurements(qs: Qubit[]) : Unit { |
| 46 | M(qs[2]); |
| 47 | Foo(qs); |
| 48 | } |
| 49 | |
| 50 | operation Foo(qs : Qubit[]) : Unit { |
| 51 | body intrinsic; |
| 52 | } |
| 53 | |