Creating the four Bell states with quantum computing in Qiskit. https://quantumcomputing.stackexchange.com/a/2260
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) |
Author
primaryobjects
commented
Aug 2, 2021
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment