I am new to Qiskit and I am trying to implement some very simple 1-qubit gates.
I want to initialize the state of the qubit (to 0 and then to 1) and then apply the gate and print the new state of the qubit.
def I(input):
q = QuantumRegister(1)
c = ClassicalRegister(1)
qc = QuantumCircuit(q, c)
if input == '1': #if input = 1, initialize the qubit to 1
qc.x(q[0])
qc.iden(q[0] )
qc.measure( q[0], c[0])
backend = Aer.get_backend('statevector_simulator')
result = qiskit.execute(qc, backend=backend, shots=1).result()
output = result.data(qc)
return output
And I call the function like this:
print('\nResults for the Iden gate')
for input in ['0','1']:
print(' Input',input,'gives output',I(input))
Now the output of all this is:
Results for the Iden gate
Input 0 gives output {'statevector': [[1.0, 0.0], [0.0, 0.0]], 'counts': {'0x0': 1}}
Input 1 gives output {'statevector': [[0.0, 0.0], [1.0, 0.0]], 'counts': {'0x1': 1}}
I know that the data() function returns the Instruction object, a list of Qubits objects and a list of classical bits with the order they added. So here the second list is the list with the qubits.
But when the qubit is '0', shouldn't it return a list with all 0? I am not sure about the meaning of the output.