-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Closed
Labels
kind/bug-reportSomething doesn't seem to work.Something doesn't seem to work.triage/acceptedA consensus emerged that this bug report, feature request, or other action should be worked onA consensus emerged that this bug report, feature request, or other action should be worked on
Description
Using cirq.optimize_for_target_gateset(circuit, gateset=cirq.CZTargetGateset()) returns a circuit with more moments. First, it doesn't combine the multiple single qubit rotations into a single PhasedXZGate. Second, it distributes the operations of an optimal moment to make it non-optimal
How to reproduce the issue
circ = cirq.Circuit([cirq.Moment(
cirq.X(cirq.LineQubit(1)),
cirq.X(cirq.LineQubit(2)),
cirq.X(cirq.LineQubit(3)),
cirq.X(cirq.LineQubit(6)),
),
cirq.Moment(
cirq.H(cirq.LineQubit(0)),
cirq.H(cirq.LineQubit(1)),
cirq.H(cirq.LineQubit(2)),
cirq.H(cirq.LineQubit(3)),
cirq.H(cirq.LineQubit(4)),
cirq.H(cirq.LineQubit(5)),
cirq.H(cirq.LineQubit(6)),
),
cirq.Moment(
cirq.H(cirq.LineQubit(1)),
cirq.H(cirq.LineQubit(3)),
cirq.H(cirq.LineQubit(5)),
),
cirq.Moment(
cirq.CZ(cirq.LineQubit(0), cirq.LineQubit(1)),
cirq.CZ(cirq.LineQubit(2), cirq.LineQubit(3)),
cirq.CZ(cirq.LineQubit(4), cirq.LineQubit(5)),
),
cirq.Moment(
cirq.CZ(cirq.LineQubit(2), cirq.LineQubit(1)),
cirq.CZ(cirq.LineQubit(4), cirq.LineQubit(3)),
cirq.CZ(cirq.LineQubit(6), cirq.LineQubit(5)))])
circ
print(circ)
print("number of moments = ", len(circ),"\n")
circ_opt = cirq.optimize_for_target_gateset(circuit=circ,gateset=gateset)
print(circ_opt)
print("number of moments = ", len(circ_opt))
0: ───────H───────@───────
│
1: ───X───H───H───@───@───
│
2: ───X───H───────@───@───
│
3: ───X───H───H───@───@───
│
4: ───────H───────@───@───
│
5: ───────H───H───@───@───
│
6: ───X───H───────────@───
number of moments = 5
0: ───PhXZ(a=-0.5,x=0.5,z=-1)────────────────────────────@────────────────────────────────────────────────────
│
1: ───PhXZ(a=-0.5,x=0.5,z=0)────PhXZ(a=0.5,x=-0.5,z=1)───@───@────────────────────────────────────────────────
│
2: ───PhXZ(a=-0.5,x=0.5,z=0)─────────────────────────────@───@────────────────────────────────────────────────
│
3: ───PhXZ(a=-0.5,x=0.5,z=0)────PhXZ(a=0.5,x=-0.5,z=1)───@───@────────────────────────────────────────────────
│
4: ───PhXZ(a=-0.5,x=0.5,z=-1)───@────────────────────────────@────────────────────────────────────────────────
│
5: ─────────────────────────────@─────────────────────────────────────────────────────────────────────────@───
│
6: ──────────────────────────────────────────────────────────PhXZ(a=0,x=1,z=0)───PhXZ(a=0.5,x=-0.5,z=1)───@───
number of moments = 6
I find that using cirq.merge_single_qubit_moments_to_phxz(circ) first fixes the issue.
Cirq version
1.2.0.dev20230628175157
Metadata
Metadata
Assignees
Labels
kind/bug-reportSomething doesn't seem to work.Something doesn't seem to work.triage/acceptedA consensus emerged that this bug report, feature request, or other action should be worked onA consensus emerged that this bug report, feature request, or other action should be worked on