How to determine if an operation has a gate?
See original GitHub issueIt 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']───
Issue Analytics
- State:
- Created 3 years ago
- Comments:11 (3 by maintainers)
Top Results From Across the Web
Designing a circuit to verify operation of an OR gate.
This can be found and verified using demorgan's theorem. So, if both functions listed produce the same output, then the gate is working....
Read more >Gate Operation - an overview | ScienceDirect Topics
The operation of a dynamic gate is typically divided into two major phases: precharge and evaluation. The mode of operation is determined by...
Read more >Logic OR Gate Tutorial
Logic OR Gates are available using digital circuits to produce the desired logical function and is given a symbol whose shape represents the...
Read more >logic gate (AND, OR, XOR, NOT, NAND, NOR and XNOR)
The NAND gate operates as an AND gate followed by a NOT gate. It acts in the manner of the logical operation "and"...
Read more >Logic Gates - Building an ALU
At the end of this tutorial you will find some activities that you will need to complete ... was there a carry, and...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
A similar issue exists for
CircuitOperation
s (#3580), which do not populate thegate
field but instead have acircuit
field not present in the baseOperation
class.cirq.Operation
has agate
property of typeOptional[Gate]
so you can check it againstNone
on any operation:Note that
TaggedOperation
delegatesgate
to the underlying operation (https://github.com/quantumlib/Cirq/blob/master/cirq/ops/raw_types.py#L534) so it also works fine to access the gate of a tagged operation directly without going through the sub operation.