# qiskit:how can i get negative sign in encoding process simulation of error correction code

I want to make sure my code word has a minus sign or not, but when I use the get_count() function from Qiskit, I only can get back the sequence consisting of $$0's$$ and $$1's$$.

For example: '0000000000000 000000 000000', '1001000010100 000000 000000', '1001000111101 000000 000000', '1001001001110 000000 000000', '1001001100111 000000 000000', '1001010000000 000000 000000', '1001010101001 000000 000000', '1001011011010 000000 000000', '1001011110011 000000 000000', '1011100011101 000000 000000', '1011100110100 000000 000000', '1011101000111 000000 000000', '1011101101110 000000 000000', '1011110001001 000000 000000', '1011110100000 000000 000000', '1011111010011 000000 000000', '1011111111010 000000 000000', '1100100001110 000000 000000'

Before the circuit is the encoding process, the last step is the measurement.

• Note that the get_count() function only going to return the amount of times you observing $0$ or $1$ for the particular qubit you measured...hence that is why you see the sequence consisting of $0$ or $1$. – KAJ226 Nov 5 at 8:09
• If I measure a quantum state with a minus sign, how do I get a minus sign – Gao Think Nov 5 at 8:14
• Suppose I have a $| \psi \rangle = -|0 \rangle$ then when I measure this state in the computational basis $\{|0 \rangle, |1\rangle \}$ basis, I will get 100% probability of observing the state $|0 \rangle$ if my device was perfect. Now if I have another quantum state $|\phi \rangle = |0\rangle$ then measuring this state also give me a 100% of observing the state $|0 \rangle$. When you make a mesurement on a quantum computer, it is like asking whether the qubit which eigenbasis it is in. If it is already in one then you get 100%. – KAJ226 Nov 5 at 8:20
• when I initialize a qubit in [-1,0],then I measure this qubit ,use get_statevector(),I can get [-1.+0.j, 0.+0.j], but when there are many qubits,get_statevector() will return tensor product,so I wonder how can I get state of qubit one by one. – Gao Think Nov 5 at 8:34
• How many qubits are we talking about? because if we are talking about 20 or 30 qubits then that is an insanely huge vector to return since the state size is $2^{20}$ or $2^{30}$. Even if you can get it back, do you really want to go through a vector of such size? :) – KAJ226 Nov 5 at 8:43

For just measurement, this will never work, e.g. when you are measuring $$|\Phi^->$$ you may get either 00 or 11, not -11(I'll omit the normalization 1/sqrt(2) from time to time).

To detect this minus sign, we need to use the fact that $$<11|\Phi^->=-11$$.

Here comes my codes.

First, produce the state |11> and generate the corresponding state vector.

from qiskit import QuantumRegister,QuantumCircuit
from qiskit.aqua.operators import StateFn
qr0=QuantumRegister(2)# <11|
circ0=QuantumCircuit(qr0)
circ0.x(qr0)
psi=~StateFn(circ0)# Get state vector
# ~ calls the operation of transpose


Next, get the Bell state $$|\Phi^->$$ and its' state vector.

qr1=QuantumRegister(2)# |00>-|11>
circ1=QuantumCircuit(qr1)
circ1.h(qr1[0])
circ1.z(qr1[0])
circ1.cx(qr1[0],qr1[1])
phi=StateFn(circ1)# Get state vector


Finally, the expectation value comes:

exp=(psi@phi).eval()
print(exp)


and the output is

this is -1/sqrt(2), which satisfies our expectation, and now you can say that there is a minus sign in the Bell state $$|\Phi^->$$.

• That's a great way to do it! Thank you very much. But I use the classic register in my circuit, and I'm going to use at least 25 quantum registers, and this method doesn't work, but thank you very much – Gao Think Nov 5 at 13:13
• 同学您好 我看到您是中国科学院的研究生 我是西电的研究生 我看了您在另一个问题下的回答 我有一点关于qiskit仿真问题想问你 方便留一下邮箱吗 – Gao Think Nov 9 at 2:01
• mailto:wangyitian19@mails.ucas.edu.cn to contact me. Emm I think this is not violating the community rules. – Yitian Wang Nov 9 at 12:39