Skip to content

optimize_for_target_gateset returns a non-optimal circuit #6422

@gauravgyawali

Description

@gauravgyawali

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

Labels

kind/bug-reportSomething doesn't seem to work.triage/acceptedA consensus emerged that this bug report, feature request, or other action should be worked on

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions