I wonder in Qiskit why the phase shift occurred in my simulation and how I can turn it off. I posted another question regarding the same simulation here, and while I tried to solve this on my own, I found that the phase shift disrupted my quantum teleportation simulation. FYI: This simulation is running quantum teleportation by parts so we can communicate through the terminal. Now, I'll describe my code and what's the problem with screenshots.

  1. Alice generates a random state
import numpy as np
from qiskit import QuantumCircuit, QuantumRegister, ClassicalRegister, execute, BasicAer, IBMQ
from qiskit import Aer
from qiskit.visualization import plot_histogram, plot_bloch_multivector
from qiskit import *
import matplotlib.pyplot as plt
from qiskit.visualization import plot_histogram
from qiskit.extensions import Initialize
from qiskit.quantum_info import Statevector, random_statevector
#randome statevector generated from |0> state.
def random_state(nqubits):
    """Creates a random nqubit state vector"""
    from numpy import append, array, sqrt
    from numpy.random import random
    real_parts = array([])
    im_parts = array([])
    for amplitude in range(2**nqubits):
        real_parts = append(real_parts, (random()*2)-1)
        im_parts = append(im_parts, (random()*2)-1)
    # Combine into list of complex numbers:
    amps = real_parts + 1j*im_parts
    # Normalise
    magnitude_squared = 0
    for a in amps:
        magnitude_squared += abs(a)**2
    amps /= sqrt(magnitude_squared)
    return amps
psi = random_state(1)
# Initialize the state to be teleported
init_gate = Initialize(psi)

And since this is an initialized object, I put this qubit into the quantum circuit to get the state vector.

#quantum circuit for getting statevector from initialize objects.
qc_init = QuantumCircuit(1,global_phase=0)
#Check initial random state
print("initial random state")
qc_init.append(init_gate, [0])
compiled_circuit_init = transpile(qc_init, Aer.get_backend('statevector_simulator'))
simulator_init = Aer.get_backend('statevector_simulator')
result_init = simulator_init.run(compiled_circuit_init).result()
init_statevector = result_init.get_statevector()

The result is same as the below: random qubit generation result

  1. Alice teleport through Bell state I created 3-compound qubit system using tensor product as below.
#use evolve to change Initialize method to Statevector.
statevector_bell = Statevector.from_label('00')
# Combine the individual statevectors using tensor product
compound_statevector = init_statevector.tensor(statevector_bell)
print("tensor product result\n")

The compound qubit system is the same as below: compound qubit system

And then, by using a standard quantum teleportation circuit, I proceed with quantum teleportation.

#qc is stage1. generate Bell state and operate in Alice's side
qc = QuantumCircuit(3, 2,global_phase=0)
# Prepare an entangled Bell pair between Alice and Bob
qc.cx(1, 2)
# Entangle the state to be teleported with Alice's qubit
qc.cx(0, 1)

#evolve compound statevector through evolve method.
compound_statevector = compound_statevector.evolve(qc)

Then I got below output. stage1

  1. Next,I put this compound state vector using the initialize method and measured Allice's part
#qc1 is stage2. measure Alice's side
qc1 = QuantumCircuit(3,2,global_phase=0)
# Measurement on Alice's qubits
qc1.measure([0, 1], [0, 1])
# Print the circuit and execute to obtain Alice's measurement result
print("Measurement outcomes for Alice's qubits:")

simulator = BasicAer.get_backend('statevector_simulator')
job_alice = execute(qc1, simulator, shots=1)
result_alice = job_alice.result()
statevector_alice = result_alice.get_statevector()
alice_measurement_result = list(result_alice.get_counts(qc1).keys())[0]

# Display Alice's measurement result and wait for user input
print("Alice's measured information:", alice_measurement_result)
input("Press Enter to continue and apply corrections to Bob's qubit")

The output will be the same as below. Alice's measurement As we can see, we got the same information bit except the phase shift. So I expected that when we apply appropriate quantum operation, we could get the same initial 3-quantum system which is the same as [-0.06990825-0.44371049j 0. -0.j 0. -0.j 0. -0.j 0.61540968+0.64769187j 0. +0.j 0. +0.j 0. +0.j ]

  1. However, when we implement the below code, we still have a phase shift.
#qc2 is stage3. Bob implement operation.
qc2 = QuantumCircuit(3, 1,global_phase=0)
#typing measured output and feed into bob's quantum circuit will be implemented.

qc2.initialize(statevector_alice, [0,1,2])
# Apply corrections to Bob's qubit based on Alice's measurement result
if alice_measurement_result[0] == '1':
if alice_measurement_result[1] == '1':
print("Complete Quantum Circuit:")
job_bob = execute(qc2, simulator, shots=1)
result_bob = job_bob.result()
statevector_bob = result_bob.get_statevector()
print("Measurement outcomes for Bob's qubit:")

bob's measurement I know that in real, Bob also has to measure his qubit, but in a simulation, we want to get the same compound state vector as our input. Also, I know that there is no need to run quantum teleportation simulation by parts like this, and it won't work in IBM Quantum, but for our purpose, running well in our local computer on the Qiskit is enough.

First, I thought that the global phase was the reason, so I put "global_phase=0" to make sure even I knew that the default value is 0 for the global phase.

After that, I'm still now sure what's the problem. We could see that the initial information reside in part 3 except the phase shift, and we couldn't change the phase shift appropriately.

Is there a misunderstanding from me regarding quantum teleportation? Please let me know if you have any concerns. Thank you for taking the time to read all of this.


1 Answer 1


Qiskit uses little-endian bit ordering (see this answer for details). It seems that you didn't take that into consideration in some places in your code. For example, to tensor product init_statevector with statevector_bell such that init_statevector is the first qubit you should use:

compound_statevector = statevector_bell.tensor(init_statevector)

instead of

compound_statevector = init_statevector.tensor(statevector_bell)

You may need to review all your code to make sure there are no other issues related to bit ordering.

Also, you should switch $X$ and $Z$ gates while applying the correction.

  • $\begingroup$ Thank you for the response, Egretta. I've tried the Aer simulator, but from my local computer, the error wasn't fixed. It seems like the post-quantum operation from Bob's side has no effect. I got Statevector([-0. +0.j , -0.03891094+0.92115625j, -0. +0.j , -0. +0.j , -0. +0.j , -0.15808367+0.35350624j, -0. +0.j , -0. +0.j ], for stage3 from the above $\endgroup$ Nov 7, 2023 at 13:11
  • $\begingroup$ , and I implement z operator. but the output is stillStatevector([-0. +0.j , -0.03891094+0.92115625j, -0. +0.j , -0. +0.j , 0. -0.j , 0.15808367-0.35350624j, 0. -0.j , 0. -0.j ], for stage4 from the above $\endgroup$ Nov 7, 2023 at 13:14
  • $\begingroup$ What version of Qiskit do you have? $\endgroup$ Nov 7, 2023 at 13:25
  • $\begingroup$ I am using 0.44.1 $\endgroup$ Nov 7, 2023 at 13:33
  • $\begingroup$ You are right. The issue is not related to the used simulator. Sorry about that. I edited my answer. $\endgroup$ Nov 7, 2023 at 17:20

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.