Skip to content

How to determine if an operation has a gate? #3556

Closed
@dabacon

Description

@dabacon

It used to be that you could check whether an operation had a gate using a type check
isinstance(gate_op, cirq.GateOperation)
But if you tag an op it loses that signature.
isinstance(gate_op.with_tags('you are it'), cirq.GateOperation) == False

Note that there are a lot of these checks throughout Cirq that will presumably break when you tag an operation. For example look at cirq.EjectPhasedPaulis().

eject = cirq.EjectPhasedPaulis()
q = cirq.NamedQubit('a')
circuit = cirq.Circuit(cirq.PhasedXPowGate(phase_exponent=0.125)(q), cirq.Z(q))
eject.optimize_circuit(circuit)
print(circuit)

does the correct optimization

a: ───PhX(0.625)───────

Put if you tag the Z, it doesn't do the optimization

circuit = cirq.Circuit(cirq.PhasedXPowGate(phase_exponent=0.125)(q), cirq.Z(q).with_tags('you are it')
eject.optimize_circuit(circuit)
print(circuit)

prints

a: ───PhX(0.125)───Z['you are it']───

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/tagsarea/transformerskind/bug-reportSomething doesn't seem to work.triage/acceptedA consensus emerged that this bug report, feature request, or other action should be worked ontriage/discussNeeds decision / discussion, bring these up during Cirq Cynque

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions