Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CQT-127] Allow Qubit to accept QubitLike #325

Merged
merged 34 commits into from
Oct 8, 2024
Merged
Show file tree
Hide file tree
Changes from 27 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
b67dfe9
[CQT 126] Verify dataclasses using __post_init__ (#319) (#321)
juanboschero Sep 9, 2024
4ab5e1d
[CQT-127] Allow Qubit to accept QubitLike
Sep 11, 2024
820d681
Accept QubitLike throughout opensquirrel
Sep 12, 2024
f167dc5
Merge branch 'develop' into CQT-127-qubit-like-class
juanboschero Sep 12, 2024
0b31beb
Happify ruff
Sep 12, 2024
ef73c33
[CQT 126] Verify dataclasses using __post_init__ (#319) (#321)
juanboschero Sep 9, 2024
af7d62b
[CQT-127] Allow Qubit to accept QubitLike
Sep 11, 2024
f712b23
Accept QubitLike throughout opensquirrel
Sep 12, 2024
fbcd2b0
Happify ruff
Sep 12, 2024
5437165
Implement QubitLike
S-Linde Sep 19, 2024
780755a
Happify ruff
S-Linde Sep 19, 2024
a4709a6
Happify mypy
S-Linde Sep 19, 2024
0bd1a2a
Docstrings
S-Linde Sep 19, 2024
26a5c4e
Happify ruff
S-Linde Sep 19, 2024
226fdd9
Fix for python39
S-Linde Sep 19, 2024
767a9c5
typo
S-Linde Sep 19, 2024
745c738
Remove redundend Qubit from OS
S-Linde Sep 20, 2024
06d8163
Removed redundant Qubit statements from tutorial
S-Linde Sep 20, 2024
8a653ec
Removed redundant Qubit statements from example
S-Linde Sep 20, 2024
8015764
Fix named measurements and reset
S-Linde Sep 20, 2024
3567930
Removed redundant Qubit statements from tests
S-Linde Sep 20, 2024
81b46ae
Resolve initial conflicts
Sep 30, 2024
0d22c93
Resolve initial conflicts
Sep 30, 2024
8288bb0
Merge develop
Sep 30, 2024
6582a12
Fix tests
Sep 30, 2024
2069dec
Happify mypy
Sep 30, 2024
dd38505
Fix py3.9
Sep 30, 2024
778996a
Fix CRk test errors
Oct 2, 2024
424939a
Remove excessive Qubit wrappers
Oct 3, 2024
4377d70
Happify ruff
Oct 3, 2024
351ac68
Restrict QubitLike internally
Oct 4, 2024
33e8bc9
Happify ruff
Oct 4, 2024
970a726
Replace annotation finding with method
Oct 7, 2024
77484b8
Merge branch 'develop' into CQT-127-qubit-like-class
juanboschero Oct 8, 2024
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
48 changes: 17 additions & 31 deletions docs/tutorial.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,10 @@ For creation of a circuit through Python, the `CircuitBuilder` can be used accor

```python
from opensquirrel import CircuitBuilder
from opensquirrel.ir import Qubit, Float
from opensquirrel.ir import Float

builder = CircuitBuilder(qubit_register_size=2)
builder.Ry(Qubit(0), Float(0.23)).CNOT(Qubit(0),Qubit(1))
builder.Ry(0, Float(0.23)).CNOT(0, 1)
qc = builder.to_circuit()

print(qc)
Expand All @@ -87,7 +87,7 @@ You can naturally use the functionalities available in Python to create your cir
```python
builder = CircuitBuilder(qubit_register_size=10)
for i in range(0, 10, 2):
builder.H(Qubit(i))
builder.H(i)
qc = builder.to_circuit()

print(qc)
Expand All @@ -110,9 +110,9 @@ For instance, you can generate a quantum fourier transform (QFT) circuit as foll
qubit_register_size = 5
builder = CircuitBuilder(qubit_register_size)
for i in range(qubit_register_size):
builder.H(Qubit(i))
builder.H(i)
for c in range(i + 1, qubit_register_size):
builder.CRk(Qubit(c), Qubit(i), c-i+1)
builder.CRk(c, i, c-i+1)
qft = builder.to_circuit()

print(qft)
Expand Down Expand Up @@ -161,18 +161,6 @@ _Output_:
Parsing error: failed to resolve overload for cnot with argument pack (qubit, int)

The issue is that the CNOT expects a qubit as second input argument where an integer has been provided.
The same holds for the `CircuitBuilder`, _i.e._,
it also throws an error if arguments are passed of an unexpected type:

```python
try:
CircuitBuilder(qubit_register_size=2).CNOT(Qubit(0), 3)
except Exception as e:
print(e)
```
_Output_:

TypeError: wrong argument type for instruction `CNOT`, got <class 'int'> but expected Qubit

## Modifying a circuit

Expand All @@ -198,7 +186,7 @@ import math

builder = CircuitBuilder(1)
for _ in range(4):
builder.Rx(Qubit(0), Float(math.pi / 4))
builder.Rx(0, Float(math.pi / 4))
qc = builder.to_circuit()

qc.merge_single_qubit_gates()
Expand Down Expand Up @@ -235,7 +223,7 @@ Below is shown how the X-gate is defined in the default gate set of OpenSquirrel

```python
@named_gate
def x(q: Qubit) -> Gate:
def x(q: QubitLike) -> Gate:
return BlochSphereRotation(qubit=q, axis=(1, 0, 0), angle=math.pi, phase=math.pi / 2)
```

Expand All @@ -248,24 +236,22 @@ For instance, the CNOT gate is defined in the default gate set of OpenSquirrel a

```python
@named_gate
def cnot(control: Qubit, target: Qubit) -> Gate:
def cnot(control: QubitLike, target: QubitLike) -> Gate:
return ControlledGate(control, x(target))
```

- The `MatrixGate` class may be used to define a gate in the generic form of a matrix:

```python
@named_gate
def swap(q1: Qubit, q2: Qubit) -> Gate:
def swap(q1: QubitLike, q2: QubitLike) -> Gate:
return MatrixGate(
np.array(
[
[1, 0, 0, 0],
[0, 0, 1, 0],
[0, 1, 0, 0],
[0, 0, 0, 1],
]
),
[
[1, 0, 0, 0],
[0, 0, 1, 0],
[0, 1, 0, 0],
[0, 0, 0, 1],
],
[q1, q2],
)
```
Expand Down Expand Up @@ -377,7 +363,7 @@ an example can be seen below where a Hadamard, Z, Y and Rx gate are all decompos
from opensquirrel.decomposer.aba_decomposer import ZYZDecomposer

builder = CircuitBuilder(qubit_register_size=1)
builder.H(Qubit(0)).Z(Qubit(0)).Y(Qubit(0)).Rx(Qubit(0), Float(math.pi / 3))
builder.H(0).Z(0).Y(0).Rx(0, Float(math.pi / 3))
qc = builder.to_circuit()

qc.decompose(decomposer=ZYZDecomposer())
Expand All @@ -404,7 +390,7 @@ Similarly, the decomposer can be used on individual gates.
from opensquirrel.decomposer.aba_decomposer import XZXDecomposer
from opensquirrel.default_gates import H

print(ZYZDecomposer().decompose(H(Qubit(0))))
print(ZYZDecomposer().decompose(H(0)))
```
_Output_:

Expand Down
Loading