Our version at qiskit/hello.py.
Our example uses a Bell state circuit to illustrate all the fundamental Qiskit basics.
Sample program output, counts are randomized each time.
First we take the quantum state vector immediately after the input.
input:
state:
Statevector([1.+0.j, 0.+0.j, 0.+0.j, 0.+0.j],
            dims=(2, 2))
probs:
[1. 0. 0. 0.]
We understand that the first element of Statevector is , and has probability of 1.0.
Next we take the state after a Hadamard gate on the first qubit:
h:
state:
Statevector([0.70710678+0.j, 0.70710678+0.j, 0.        +0.j,
             0.        +0.j],
            dims=(2, 2))
probs:
[0.5 0.5 0.  0. ]
We now understand that the second element of the Statevector is , and now we have a 50/50 propabability split for the first bit.
Then we apply the CNOT gate:
cx:
state:
Statevector([0.70710678+0.j, 0.        +0.j, 0.        +0.j,
             0.70710678+0.j],
            dims=(2, 2))
probs:
[0.5 0.  0.  0.5]
which leaves us with the final .
Then we print the circuit a bit:
qc without measure:
     ┌───┐
q_0: ┤ H ├──■──
     └───┘┌─┴─┐
q_1: ─────┤ X ├
          └───┘
c: 2/══════════

qc with measure:
     ┌───┐     ┌─┐
q_0: ┤ H ├──■──┤M├───
     └───┘┌─┴─┐└╥┘┌─┐
q_1: ─────┤ X ├─╫─┤M├
          └───┘ ║ └╥┘
c: 2/═══════════╩══╩═
                0  1
qasm:
OPENQASM 2.0;
include "qelib1.inc";
qreg q[2];
creg c[2];
h q[0];
cx q[0],q[1];
measure q[0] -> c[0];
measure q[1] -> c[1];
And finally we compile the circuit and do some sample measurements:
qct:
     ┌───┐     ┌─┐
q_0: ┤ H ├──■──┤M├───
     └───┘┌─┴─┐└╥┘┌─┐
q_1: ─────┤ X ├─╫─┤M├
          └───┘ ║ └╥┘
c: 2/═══════════╩══╩═
                0  1
counts={'11': 484, '00': 516}
counts={'11': 493, '00': 507}

Articles by others on the same topic (0)

There are currently no matching articles.