Quantum Computing Asked by Shivam on January 30, 2021
In qiskit, how can I initialise a qubit in a complex state, specifically in the state:
$$left|qright> = frac{1}{sqrt2} left|0right> + i frac{1}{sqrt2} left|1right>$$
You can generate a general quantum state $|psirangle$ in Qiskit by using their Custom package.
from qiskit.aqua.components.initial_states import Custom
import math
state_vector = [1, 1j]
Psi = Custom(1,state_vector = state_vector).construct_circuit()
Psi.draw()
Running the above code in Qiskit would give you something like below:
But also notice that your state $|qrangle = dfrac{1}{sqrt{2}}big( |0rangle + i | 1rangle big) $ is actually resulting from
$$ dfrac{Z + Y}{sqrt{2}} |0rangle = |qrangle $$
where $Z$ and $Y$ are the Pauli matrices and $|0rangle = begin{bmatrix} 1 0 end{bmatrix} $.
Answered by KAJ226 on January 30, 2021
You can use initialize
function. Here is a code constructing your one qubit state:
from qiskit import ClassicalRegister, QuantumRegister, QuantumCircuit, Aer, execute
import math as m
quantumState = [
1 / m.sqrt(2) * complex(1, 0),
1 / m.sqrt(2) * complex(0, 1)]
q = QuantumRegister(1, name = 'q')
c = ClassicalRegister(1, name = 'c')
circuit = QuantumCircuit(q,c)
circuit.initialize(quantumState, [q[0]])
You can prepare multiqubit states as well, for example for $|psirangle = frac{1}{2}(|00rangle + |01rangle+|10rangle+|11rangle)$:
from qiskit import ClassicalRegister, QuantumRegister, QuantumCircuit, Aer, execute
import math as m
quantumState = [0.5,0.5,0.5,0.5]
q = QuantumRegister(2, name = 'q')
c = ClassicalRegister(2, name = 'c')
circuit = QuantumCircuit(q,c)
circuit.initialize(quantumState, [q[0],q[1]])
Answered by Martin Vesely on January 30, 2021
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP