Open quantumjim opened 4 years ago
You should just be able to define a composite instruction for these. Eg
class MeasureX(Instruction):
def __init__(self):
super().__init__("measure_x", 1, 1, [])
def broadcast_arguments(self, qargs, cargs):
# copy from measure instruction
def _define(self):
from qiskit.extensions.standard.h import HGate
from qiskit.circuit.measure import Measure
q = QuantumRegister(1, 'q')
c = ClassicalRegister(1, 'c')
self.definition = [
(HGate(), [q[0]], []),
(Measure(), [q[0]], [c[0]])
(HGate(), [q[0]], []),
]
class MeasureY(Instruction):
def __init__(self):
super().__init__("measure_y", 1, 1, [])
def broadcast_arguments(self, qargs, cargs):
# copy from measure instruction
def _define(self):
from qiskit.extensions.standard.h import HGate
from qiskit.extensions.standard.s import SdgGate
from qiskit.circuit.measure import Measure
q = QuantumRegister(1, 'q')
c = ClassicalRegister(1, 'c')
self.definition = [
(SdgGate(), [q[0]], []),
(HGate(), [q[0]], []),
(Measure(), [q[0]], [c[0]]),
(HGate(), [q[0]], []),
(SdgGate(), [q[0]], [])
]
Edited to include post measurement instruction to rotate to the correct collapsed state.
This issue may be solved by PR #5311 which is pending for review.
Update on this issue, since I've just closed another as a duplicate of it:
We remain interested in generalising the concept of measures that Qiskit can reason about, but it is not at all a trivial task nor a case of just adding a couple of new classes; there are many assumptions baked into the library in many places that measurements are Z-basis, and modifying that will have a lot of knock-on effects throughout the library.
For more context of other discussions that have happened since, see:
What is the expected behavior?
Qiskit natively supports z measurements using
measure
, but x and y basis measurements need to be done with a quick hack (reflecting how the hardware works).However:
I'd suggest
measure_x
andmeasure_y
be added toQuantumCircuit
, withmeasure_x
compiling down toh
followed bymeasure
(except for relevant hardware).