0
$\begingroup$

This seems like a basic operation, but I can't see how it's done in qiskit.

The solution here Measuring tensor products of Pauli operators doesn't work anymore.

I get an error "qiskit has no attribute 'aqua'".

Stim has MPP command that does the job, but I'm working with qiskit on this circuit.

$\endgroup$

1 Answer 1

3
$\begingroup$

Note: The answer below is for measuring a single Pauli string, which turns out not to be what the question wants (after clarification).

You can implement your own function of Pauli measurement.

QuantumCircuit.measure is, by definition, a Pauli $Z$ measurement. Putting an $H$ gate before that gives you an $X$ measurement; Putting (e.g.) $HS^{-1}$ before that gives you an $Y$ measurement. These can be confirmed by $$ \begin{aligned} HZH = X,\quad (HS^{-1})^\dagger Z(HS^{-1}) = SXS^{-1} = Y. \end{aligned} $$ Besides, measurements of Pauli strings are just tensor products of single-qubit Pauli measurements, so you just need to do the above qubit-by-qubit.

Below is a piece of code I use to generate circuit for Pauli measurement at a certain index (just remember to add QuantumCircuit.measure at the end of the circuit).

def measure_pauli_1q(circuit,index,pauli=None):
    if pauli == 'I' or pauli == 'Z':
        circuit.id([index])
    elif pauli == 'X':
        circuit.h([index])
    elif pauli == 'Y':
        circuit.s([index])
        circuit.s([index])
        circuit.s([index])
        circuit.h([index])
    else:
        assert 1==0
$\endgroup$
3
  • $\begingroup$ I don't think this will work. I need to measure multiple stabilizers (for example $X_1 Z_2 X_3 X_4$ and $Z_1 X_3 Z_4$...) qubit 1 would be involved as $X_1$ in first and $Z_1$ in second. Measuring a "qubit" is not well defined...you measure operators not qubits. $\endgroup$
    – unknown
    Commented Sep 6, 2022 at 22:29
  • $\begingroup$ So the task is to measure multiple Pauli strings that are not bit-wise commuting. In that case, yes, one cannot measure “qubit-by-qubit” as measuring $Z_1$ destroy the information of $X_1$. My understanding is that one needs to rotates to the common eigenbasis of all Pauli strings before measuring, or introduces ancillas. (PS. I would suggest editing the question to make this point clear. The pauli_measurement method mentioned here also measure qubit-by-qubit, as far as I can tell) $\endgroup$ Commented Sep 7, 2022 at 2:36
  • 1
    $\begingroup$ Edited title to be more explicit. Note that stim handles this directly with MPP command. $\endgroup$
    – unknown
    Commented Sep 7, 2022 at 2:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.