Skip to content

Commit

Permalink
convert SingleQubitCliffordGate to phasedXZ during serialization (#6419)
Browse files Browse the repository at this point in the history
  • Loading branch information
NoureldinYosri authored Jan 18, 2024
1 parent 7da7f64 commit a3eed6b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
4 changes: 3 additions & 1 deletion cirq-google/cirq_google/serialization/circuit_serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,9 @@ def _serialize_gate_op(
out=msg.phasedxpowgate.exponent,
arg_function_language=arg_function_language,
)
elif isinstance(gate, cirq.PhasedXZGate):
elif isinstance(gate, (cirq.PhasedXZGate, cirq.ops.SingleQubitCliffordGate)):
if isinstance(gate, cirq.ops.SingleQubitCliffordGate):
gate = gate.to_phased_xz_gate()
arg_func_langs.float_arg_to_proto(
gate.x_exponent,
out=msg.phasedxzgate.x_exponent,
Expand Down
13 changes: 13 additions & 0 deletions cirq-google/cirq_google/serialization/circuit_serializer_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -668,3 +668,16 @@ def test_measurement_gate_deserialize() -> None:
msg = cg.CIRCUIT_SERIALIZER.serialize(circuit)

assert cg.CIRCUIT_SERIALIZER.deserialize(msg) == circuit


def test_circuit_with_cliffords():
q = cirq.NamedQubit('q')
circuit = cirq.Circuit(
g(q) for g in cirq.ops.SingleQubitCliffordGate.all_single_qubit_cliffords
)
want = cirq.Circuit(
g.to_phased_xz_gate()(q)
for g in cirq.ops.SingleQubitCliffordGate.all_single_qubit_cliffords
)
msg = cg.CIRCUIT_SERIALIZER.serialize(circuit)
assert cg.CIRCUIT_SERIALIZER.deserialize(msg) == want

0 comments on commit a3eed6b

Please sign in to comment.