# how to apply pauli string depending on multiple control qubits (qiskit or stim)

I read and re-read the documentation for MCMT and MCX and still can't figure out how to do this. For example I have 10 qubits $$q_0,\cdots q_9$$; I want to apply pauli string $$X_2 Y_4 Z_5$$ with control bits $$q_7,q_9$$. How would this be done? I don't think this can be done in stim since these gates are not clifford; am I right?

• It's unclear to me if you're asking about how to do something in qiskit or if it can be done in stim. Questions should be one question. Sep 3, 2022 at 1:22
• @CraigGidney Actually both...I didn't think stim could do it based on non-clifford gate support...please correct if I'm wrong Sep 3, 2022 at 3:08

I think that MCMT allows one type of target gate only (i.e you can apply an $$X$$ gate for example on multiple target qubits, but applying $$X$$ on that qubit and $$Z$$ on another qubit, for example - is not supported).

However we can write a piece of code that does that pretty easily:

def pauliStringCustomGate(qubits_span, gates_list, qubits_list):
qc = QuantumCircuit(qubits_span)

count = 0
for g in gates_list:
if g == 'X':
qc.x(qubits_list[count])
elif g == 'Y':
qc.y(qubits_list[count])
elif g == 'Z':
qc.z(qubits_list[count])
count += 1

gate_qc = qc.to_gate(label = "Custom Pauli String")
return gate_qc

cps = pauliStringCustomGate(qubits_span = 4, gates_list = ['X','Y','Z'], qubits_list = [0,2,3])
qc = QuantumCircuit(10)
qc.append(instruction = cps.control(num_ctrl_qubits = 2), qargs = [7,9,2,3,4,5])


The quantum circuit you get is:

And the content of the "Custom Pauli String" box is:

• this also worked...it was a tossup to decide which answer to accept Sep 3, 2022 at 21:23

Qiskit provides PauliGate which makes it really easy to achieve that:

from qiskit.circuit.library import PauliGate

pauli_string = 'ZYX'
gate = PauliGate(pauli_string).control(2)
circ.append(gate, [7, 9, 2, 4, 5])


Where circ is you quantum circuit.

• thanks, this worked Sep 3, 2022 at 21:23

Stim doesn't allow multiple controls.

Actually, it doesn't even allow combining multiple classical controls, though in most other contexts those are considered okay for stabilizer circuits. It's due to an underlying algorithmic issue, where samples produces by circuits with such operations lack a group structure that enables extremely fast bulk simulations.

This refers specifically to what can be put into a stim.Circuit. Obviously nothing prevents the python code driving a stim.TableauSimulator from making decisions that depend on multiple measurement results in complex ways.

• I have to learn how you can still do QECC with this limitation...I think I'm missing some key ideas behind stim's approach. Sep 3, 2022 at 21:26
• @unknown You can't do universal computation under this constraint, even with magic states. But you can still determine what the error rates of those constructions would be. Sep 3, 2022 at 21:33