Python Qiskit Quantum Entanglement Coding
Here is some example code in Qiskit that demonstrates quantum entanglement:
from qiskit import QuantumCircuit, execute, Aer
# Create a quantum circuit with 2 qubits and 2 classical bits
qc = QuantumCircuit(2, 2)
# Add a H gate on qubit 0, and CX (CNOT) gate on control qubit 0 and target qubit 1
qc.h(0)
qc.cx(0, 1)
# Add a Measure gate to see the state.
measure_z = QuantumCircuit(2, 2)
measure_z.measure(0, 0)
measure_z.measure(1, 1)
qc = qc + measure_z
# Execute the circuit and print the result
result = execute(qc, backend=Aer.get_backend('qasm_simulator')).result()
print(result.get_counts(qc))
The output of this code will be a dictionary that maps measurement outcomes to their probabilities. For example, the output may look something like this:
{'00': 0.5, '11': 0.5}
This output indicates that there is a 50% probability of measuring both qubits as 0 and a 50% probability of measuring both qubits as 1. This is an example of quantum entanglement, where the state of one qubit is "linked" to the state of the other qubit, even though they are separated by a large distance.
No comments: