Skip to content

Commit

Permalink
Fix bug in writer for SWAP instruction. (#444)
Browse files Browse the repository at this point in the history
* Fix bug in writer for SWAP instruction.

* Add CHANGELOG entry.
Update OpenSquirrel version number.

* Update CHANGELOG.md

Co-authored-by: Roberto Turrado Camblor <[email protected]>

* Undo version number update (not part of this bugfix).

* Update CHANGELOG.md

Co-authored-by: Roberto Turrado Camblor <[email protected]>

---------

Co-authored-by: Roberto Turrado Camblor <[email protected]>
  • Loading branch information
elenbaasc and rturrado authored Jan 31, 2025
1 parent 42691cb commit 07e1ee2
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@ This project adheres to [Semantic Versioning](http://semver.org/).
* **Removed** for now removed features.


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

### Fixed

- Bug in the writing of SWAP instructions


## [ 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

0 comments on commit 07e1ee2

Please sign in to comment.