Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Creating the four Bell states with quantum computing in Qiskit. https://quantumcomputing.stackexchange.com/a/2260
def four_bell_states():
"""
Create all 4 Bell states.
https://quantumcomputing.stackexchange.com/a/2260
"""
# [00, 11] positive
qc = QuantumCircuit(2)
qc.h(0)
qc.cx(0, 1)
execute_bell(qc, '00-11')
# [01, 10] positive
qc = QuantumCircuit(2)
qc.h(0)
qc.cx(0, 1)
qc.x(1)
execute_bell(qc, '01-10')
# [00, 11] negative
qc = QuantumCircuit(2)
qc.h(0)
qc.cx(0, 1)
qc.z(0)
execute_bell(qc, '11-00')
# [01, 10] negative
qc = QuantumCircuit(2)
qc.h(0)
qc.cx(0, 1)
qc.z(0)
qc.x(1)
execute_bell(qc, '10-01')
def execute_bell(qc, name):
simulator = Aer.get_backend('statevector_simulator')
qobj = assemble(qc)
result = simulator.run(qobj).result()
output_state = result.get_statevector(qc)
print(output_state)
figure = plot_histogram(result.get_counts())
figure.savefig('bellstate-{}.png'.format(name))
@primaryobjects

This comment has been minimized.

Copy link
Owner Author

@primaryobjects primaryobjects commented Aug 2, 2021

[0.70710678+0.j 0.        +0.j 0.        +0.j 0.70710678+0.j]
[0.        +0.j 0.70710678+0.j 0.70710678+0.j 0.        +0.j]
[ 0.70710678+0.j -0.        +0.j  0.        +0.j -0.70710678+0.j]
[ 0.        +0.j -0.70710678+0.j  0.70710678+0.j -0.        +0.j]

bellstate-00-11
bellstate-01-10
bellstate-10-01
bellstate-11-00

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment