0

Is there a way to represent measurements in other bases in Qiskit? The default measurement is in the Z (computational) basis. Can I also depict measurement in X, Y and general Pauli Measurements?

I know that I can apply a suitable unitary and then measure in the Z basis, but I am looking for a way to add the measurements to the circuit almost like "gates". I will be putting many such measurements in sequence in my circuits. I will be happy to use any external/in-development tool that allows this and interfaces well with Qiskit.

glS
  • 24,708
  • 5
  • 34
  • 108
shashvat
  • 805
  • 4
  • 13
  • 3
    In progress: https://github.com/Qiskit/qiskit-terra/pull/5311 – Yael Ben-Haim Mar 07 '21 at 07:01
  • Hi, Thanks for your quick answer. Do you think that is ready to use for what I have said I want to do? – shashvat Mar 07 '21 at 08:32
  • Probably, but I don't think it will be easy for you to apply it without a proper release of Qiskit that includes it. – Yael Ben-Haim Mar 07 '21 at 12:06
  • Have you looked into using Pennylane? They allow you to measure in arbitrary basis as you mentioned.... look here: https://pennylane.readthedocs.io/en/stable/introduction/measurements.html and there is a plugin between Pennylane and Qiskit https://pennylane-qiskit.readthedocs.io/en/latest/ which allows you to execute your work on IBM hardware. – KAJ226 Mar 07 '21 at 17:30
  • @KAJ226 Thanks for sharing! Unfortunately it looks like while Pennylane does allow the general Pauli measurements I want, it still does not allow multiple measurements per circuit. – shashvat Mar 08 '21 at 03:18
  • @YaelBen-Haim Is there any chance that the meas_pauli branch could be used something like this: https://quantumcomputing.stackexchange.com/a/16007/13497 ? – shashvat Mar 08 '21 at 03:21
  • Hello @user3717194, how about something like this: https://quantumcomputing.stackexchange.com/questions/13605/how-to-measure-in-another-basis ? You create functions for measurements you want and apply them at the end of the circuit, would that be a good enough temporary solution for you? You can also use the idea to create custom gates like composite gates here by creating a circuit and transform it into instruction you apply as gates on any circuit. Is it helpful? – Lena Mar 08 '21 at 08:38
  • By the way, there is a lab available on the Qiskit textbook about Quantum Measurement, maybe it'll help you, here https://qiskit.org/textbook/ch-labs/Lab02_QuantumMeasurement.html, – Lena Mar 08 '21 at 08:40
  • You can use the branch by installing qiskit-terra from source – Yael Ben-Haim Mar 08 '21 at 13:12
  • Hi @YaelBen-Haim , are the features to draw Pauli Measurements ready? I tried building from source but am getting errors when I try to draw the circuit: circuit = QuantumCircuit(6, 6) circuit.measure_pauli('x', [0], [0]) display(circuit.draw()) – shashvat Mar 09 '21 at 03:35
  • @Lena those are some interesting ideas, thanks for sharing. For the moment I'll try other methods but might return to your ideas. – shashvat Mar 09 '21 at 03:37
  • Did you checkout the relevant pull request? It's not in the master branch. – Yael Ben-Haim Mar 09 '21 at 07:12
  • Yes I believe so, here is the error message I am getting if that helps.

    ... ~/anaconda3/envs/paulimeas/lib/python3.6/site-packages/qiskit/visualization/text.py in _instruction_to_gate(self, instruction, layer) 1002 gate = MeasureFrom() 1003 else: # measure_pauli -> 1004 basis = instruction.params.upper() 1005 gate = MeasureFrom(basis) 1006 layer.set_qubit(instruction.qargs[0], gate)

    AttributeError: 'DAGNode' object has no attribute 'params'

    – shashvat Mar 09 '21 at 09:52

0 Answers0