Skip to content

Commit

Permalink
[feature] add rzz qasm output support
Browse files Browse the repository at this point in the history
  • Loading branch information
ss2165 committed Feb 17, 2022
1 parent 0586960 commit 8fd47c3
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
10 changes: 7 additions & 3 deletions pytket/pytket/qasm/qasm.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,9 @@
),
}
included_gates["hqslib1"] = included_gates["qelib1"].copy()
included_gates["hqslib1"].update(("U1q", "rz", "ZZ"))
included_gates["hqslib1"].update(("U1q", "rz", "ZZ", "RZZ"))
included_gates["hqslib1"].difference_update(
("crx", "cry", "sx", "sxdg", "csx", "swap", "cswap")
("crx", "cry", "sx", "sxdg", "csx", "swap", "cswap", "rzz")
)
_tk_to_qasm_noparams = dict(((item[1], item[0]) for item in NOPARAM_COMMANDS.items()))
_tk_to_qasm_noparams[OpType.CX] = "cx" # prefer "cx" to "CX"
Expand Down Expand Up @@ -580,7 +580,11 @@ def circuit_to_qasm_io(
f"{args[-1]} = {args[0]} {_classical_gatestr_map[opstr]} {args[1]};\n"
)
continue
if optype in _tk_to_qasm_noparams:
if header == "hqslib1" and optype == OpType.ZZPhase:
# special handling for zzphase
opstr = "RZZ"
params = op.params
elif optype in _tk_to_qasm_noparams:
opstr = _tk_to_qasm_noparams[optype]
elif optype in _tk_to_qasm_params:
opstr = _tk_to_qasm_params[optype]
Expand Down
7 changes: 7 additions & 0 deletions pytket/tests/qasm_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,13 @@ def test_new_qelib1_aliases() -> None:
assert "U3(0, 0, 0) q[0]" in commands_str


def test_h1_rzz() -> None:
c = Circuit(2)
c.add_gate(OpType.ZZPhase, [0.1], [0, 1])
assert "rzz" in circuit_to_qasm_str(c, header="qelib1")
assert "RZZ" in circuit_to_qasm_str(c, header="hqslib1")


if __name__ == "__main__":
test_qasm_correct()
test_qasm_qubit()
Expand Down

0 comments on commit 8fd47c3

Please sign in to comment.