# How to create the logical $|0_L\rangle$ state for the Steane's 7-qubit code?

I don't know how to prepare using Qiskit the following state in order to implement a Steane's 7-qubit code circuit (I omit the normalization factor): \begin{align*} |0_L\rangle =&|0000000\rangle+|1010101\rangle+|0110011\rangle+|1100110\rangle+ \\ +&|0001111\rangle+|1011010\rangle+|0111100\rangle+|1101001\rangle \end{align*} Furthermore, I was wondering if it exists a general procedure in order to prepare an arbitrary multipartite state like $$|0_L\rangle$$.

• You have to use the initialize() function. Look at this post: quantumcomputing.stackexchange.com/questions/1413/… Jul 24, 2020 at 7:19
• Thank you! What if I wanted to use only gates (even if it is not necessary since initialize() exists)? Is there a rule to prepare this kind of states (like for example the combo Hadamard on first qubit+ CNOT for Bell basis in bipartite case)? Jul 24, 2020 at 7:27
• I am not aware of a general rule. Specific states may have ultra-optimized circuits. The initialize() function is based on a nice algorithm (which is not very recent, and I would like to know if there are even better ones). Note: in your example the $|1011010\rangle$ state appears twice. Jul 24, 2020 at 7:40
• Thank you again, I've edited the question, now it should be correct. Jul 24, 2020 at 7:47
• Did you look at this question: quantumcomputing.stackexchange.com/questions/13024/…? It gives the theory, although not the specific qiskit implementation. Jul 24, 2020 at 8:27

Here is a circuit that can create the desired state (similar ideas were discussed in this answer), if all mentioned measurements yield $$|0\rangle$$ state: or in a more compact form (the circuits are constructed via quirk). The first three qubits are ancillary qubits and the rest are the qubits where $$|0_L\rangle$$ will be created if after the measurements all ancillary qubits are in the $$|000\rangle$$ state, otherwise one should repeat the procedure until the desired measurement result will be archived.

Let's go step by step. The circuit has three parts and in each step, we assume that the measured state of the ancillary is $$|0\rangle$$. The normalization factors are omitted.

1. The state after measuring the first ancillary qubit in the $$|0\rangle$$ state: (measuring $$XIXIXIX$$ stabilizer)

$$|000\rangle \big( |0000000\rangle + |1010101\rangle \big)$$

1. The state after measuring the second ancillary qubit in the $$|0\rangle$$ state: (measuring $$IXXIIXX$$ stabilizer)

$$|000\rangle \big( |0000000\rangle + |1010101\rangle + |0110011\rangle + |1100110\rangle\big)$$

1. The state after measuring the third ancillary qubit in the $$|0\rangle$$ state: (measuring $$IIIXXXX$$ stabilizer)

$$|000\rangle |0_L\rangle = |000\rangle \big( |0000000\rangle + |1010101\rangle + |0110011\rangle + |1100110\rangle \\ |0001111\rangle + |1011010\rangle +|0111100\rangle + |1101001\rangle \big)$$

After disregarding the ancillary qubits that are in the $$|000\rangle$$ state we will have the desired $$|0_L\rangle$$ state. The probability that each measurement outcome will be $$|0\rangle$$ is $$0.5$$, thus the probability of creating the $$|0_L\rangle$$ state with this circuit is $$0.125$$. For Qiskit, one can implement the circuit mentioned above, then apply any algorithm or gate that is needed on the $$|0_L\rangle$$ state, and after the computation disregard all the results where ancillary qubits are not in the $$|000\rangle$$ state.

• Very clear, but I don't understand the part about the probability of the outcome. I mean, on the three ancillary qubits you have two Hadamards thus, provided that $H\cdot H=I$, where $I$ is the identity, you should get $|0\rangle$ with probability 1, or am I missing something? Jul 24, 2020 at 16:58
• @HubOne, There is no place where we have $H \cdot H$, we always have control gates in the middle of Hadamards in this circuit. The probabilities can be seen from the link that I have shared for the equivalent circuit. Also, the probabilities can be obtained by calculating the state before, for example, the first measurement. Jul 24, 2020 at 17:17
• @HubOne, let me try to explain with a simpler circuit. Can you find the state before the measurement of this two-qubit circuit? What is the probability of measuring $|0\rangle$ state? CNOT is a two qubit gate and it changes the state of both qubits. For example, if after CNOT we created an entangled state, that already means that the state of both qubits is changed (the control qubit's state inclusive...it will have some correlation with the target qubit). Jul 25, 2020 at 9:19
• Is the state before the measurement $\frac{1}{\sqrt{2}}(|+\rangle |0\rangle + |-\rangle |1\rangle)$? However, I can see the problem now, it totally makes sense. Thank you Jul 25, 2020 at 9:32
• No problem :) you can change the title Jul 25, 2020 at 9:39

Here's a direct circuit to produce the logical $$\bar{|0\rangle}$$ state from https://arxiv.org/abs/1501.02524: I'm not a qiskit expert, but in Cirq, I can check the superposition created by this:

import cirq

q = cirq.LineQubit.range(7)
state = cirq.Circuit(
cirq.H(q),
cirq.H(q),
cirq.H(q),
cirq.CNOT(q, q),
cirq.CNOT(q, q),
cirq.CNOT(q, q),
cirq.CNOT(q, q),
cirq.CNOT(q, q),
cirq.CNOT(q, q),
cirq.CNOT(q, q),
cirq.CNOT(q, q),
cirq.CNOT(q, q),
).final_state_vector(0, qubit_order=q)
print(cirq.dirac_notation(state))


results in

0.35|0000000⟩ + 0.35|0001111⟩ + 0.35|0110011⟩ + 0.35|0111100⟩ + 0.35|1010101⟩ + 0.35|1011010⟩ + 0.35|1100110⟩ + 0.35|1101001⟩


Qubits are initialized at 0 so would you be wanting to flip certain qubits to 1?

I’m tempted to just apply x gates to obtain the necessary bits.

For example: |ψ⟩=...+|1010101⟩+...

from qiskit import QuantumCircuit qc = QuantumCircuit(7) qc.x([0, 2, 4, 6])

I hope I understood your question :)

• I don't think that with this method you can obtain the superposition I need on the state $|\psi\rangle$, maybe you can prove that I'm wrong. Jul 24, 2020 at 7:13
• I guess that I have to use a combination of Hadamard and $\sigma_x$, but I don't know how to do that efficiently. Jul 24, 2020 at 7:17