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

Fix bug in writer for SWAP instruction. #444

Merged
merged 6 commits into from
Jan 31, 2025
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
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
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,13 @@ This project adheres to [Semantic Versioning](http://semver.org/).
* **Removed** for now removed features.


## [ 0.3.0 ] - [ xxxx-yy-zz ]
## [0.4.0] - [ xxxx-yy-zz ]

### Fixed

- Bug in the writing of SWAP instructions.
elenbaasc marked this conversation as resolved.
Show resolved Hide resolved

## [ 0.3.0 ] - [ 2025-01-30 ]

### Added

Expand Down
2 changes: 1 addition & 1 deletion opensquirrel/writer/writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def visit_gate(self, gate: Gate) -> None:
gate_generator = []
if gate.generator is not None:
gate_generator = list(inspect.signature(gate.generator).parameters.keys())
qubit_function_keys = ["target", "control", "qubit"]
qubit_function_keys = ["target", "control", "qubit", "qubit0", "qubit1"]
if gate.is_anonymous:
if "MatrixGate" in gate_name:
# In the case of a MatrixGate the newlines should be removed from the array
Expand Down
16 changes: 16 additions & 0 deletions test/writer/test_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,22 @@ def test_measure() -> None:
)


def test_swap() -> None:
builder = CircuitBuilder(2, 2)
builder.SWAP(0, 1)
circuit = builder.to_circuit()
assert (
writer.circuit_to_string(circuit)
== """version 3.0

qubit[2] q
bit[2] b

SWAP q[0], q[1]
"""
)


def test_anonymous_gate() -> None:
builder = CircuitBuilder(2, 2)
builder.H(0)
Expand Down