Skip to content

2 Qubit ControlledOperations should be supported in convert_to_sycamore_gates  #4152

Closed
@tanujkhattar

Description

@tanujkhattar

Description of the Issue

We check isinstance(op, GateOperation) while verifying that the given operation can be decomposed using analytical / tabulation methods. This leads to the problem that we don't recognize two qubit controlled operations as known gates and hence don't support them.

elif len(op.qubits) == 2 and isinstance(op, ops.GateOperation):

For example:

num_qubits = 3
qubits = cirq.GridQubit.rect(1, num_qubits, 4, 4)
circuit = cirq.Circuit(cirq.QuantumFourierTransformGate(num_qubits)(*qubits))
cirq.Circuit(cirq.google.ConvertToSycamoreGates().convert(circuit), device = cirq.google.Sycamore)

The above code fails with the following error:

TypeError: Don't know how to work with cirq.S(cirq.GridQubit(4, 4)).controlled_by(cirq.GridQubit(4, 5)). It isn't a native xmon operation, a 1 or 2 qubit gate with a known unitary, or composite.

The reason it fails is because ControlledOperations don't satisfy the isinstance(gate, GateOperation) constraint.

op = cirq.S(cirq.GridQubit(4, 4)).controlled_by(cirq.GridQubit(4, 5))
print(type(op), isinstance(op, cirq.GateOperation))

gives

<class 'cirq.ops.controlled_operation.ControlledOperation'> False

However, the gate is actually just a two qubit controlled gate and should be decomposable into the native gateset via known_two_q_operations_to_sycamore_operations.

op = cirq.S(cirq.GridQubit(4, 4)).controlled_by(cirq.GridQubit(4, 5))
print([*known_two_q_operations_to_sycamore_operations(op.qubits[0], op.qubits[1], op, None)])

gives the following decomposition

[cirq.PhasedXZGate(axis_phase_exponent=-1.1102230246251565e-16, x_exponent=0.7239292897100449, z_exponent=0.08333333333333348).on(cirq.GridQubit(4, 5)), cirq.PhasedXZGate(axis_phase_exponent=0.5416666666666665, x_exponent=0.0, z_exponent=0.916666666666667).on(cirq.GridQubit(4, 4)), cirq_google.SYC.on(cirq.GridQubit(4, 5), cirq.GridQubit(4, 4)), cirq.Rx(rads=0.5922772837339743).on(cirq.GridQubit(4, 4)), cirq_google.SYC.on(cirq.GridQubit(4, 5), cirq.GridQubit(4, 4)), cirq.PhasedXZGate(axis_phase_exponent=-0.08333333333333315, x_exponent=0.7239292897100451, z_exponent=-0.916666666666667).on(cirq.GridQubit(4, 5)), cirq.PhasedXZGate(axis_phase_exponent=0.22741638234956674, x_exponent=2.220446049250313e-16, z_exponent=0.25).on(cirq.GridQubit(4, 4)), cirq.Rz(rads=0.7853981633974483).on(cirq.GridQubit(4, 5)), cirq.Rz(rads=0.7853981633974483).on(cirq.GridQubit(4, 4))]

Proposed Solution

elif len(op.qubits) == 2 and isinstance(op, ops.GateOperation):

should be modified to also recognize two qubit ControlledOperations.

Cirq version
0.11.0.dev

Part of #3242

Metadata

Metadata

Assignees

Labels

area/gate-compilationkind/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