Skip to content

Major goal: gate pattern matching #2536

@Strilanc

Description

@Strilanc
  • We have many different ways of specifying the same gate. An X gate could an instance of PauliString, of XPowGate, of PhasedXPowGate, of (in the future) PhasedXZPowGate, of MatrixGate, you get the idea. It would be nice if I could just say cirq.match(might_be_x, cirq.X) in order to recognize X gates, and cirq.match(might_be_x, cirq.XPowGate) to identify X rotations.

  • I always accidentally write if isinstance(op, GateType) instead of if isinstance(op.gate, GateType) and then lose ten minutes figuring out what's wrong. It would be nice if this was not a possible mistake to make, e.g. if cirq.match(op, cirq.IdentityGate) worked and also if cirq.match(gate, cirq.IdentityGate) worked.

  • Currently, in order to identify an identity operation from an Any you have to say if isinstance(obj, cirq.Operation) and isinstance(obj.gate, cirq.IdentityGate). It would be nice if this had no and in it, e.g. if cirq.match(obj, cirq.IdentityGate):.

  • I often want matching to be approximate. For example, PhasedXPowGate(exponent=0.2, phase_exponent=1e-10) should match into XPowGate when tolerance is larger than 1e-10.

Metadata

Metadata

Labels

area/gatescomplexity/highintroduces/modifies 6+ concepts or touches Cirq core concepts or > 1 month for an expertkind/feature-requestDescribes new functionalityroadmapfor higher level roadmap items to capture conversations and feedback (not for project tracking)status/needs-agreed-designWe want to do this, but it needs an agreed upon design before implementationtriage/acceptedA consensus emerged that this bug report, feature request, or other action should be worked on

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions