Page 1 of 1

How would you create a circuit that entangles two qubits where each qubit is different (that is, 01, 10)?

Posted: Sat Aug 12, 2023 4:49 am
by quantumadmin
To create a circuit that entangles two qubits, each initially in a different state (01 and 10), you can use a combination of Hadamard (H) gates and controlled-NOT (CNOT) gates. The Hadamard gate creates superposition, and the CNOT gate entangles the qubits based on their initial states. Here's how you can construct the circuit:

Code: Select all

from qiskit import QuantumCircuit, Aer, execute

# Create a quantum circuit with 2 qubits
circuit = QuantumCircuit(2)

# Apply Hadamard gate to the first qubit
circuit.h(0)

# Apply CNOT gate with the first qubit as the control and the second qubit as the target
circuit.cx(0, 1)

# Simulate the circuit
simulator = Aer.get_backend('statevector_simulator')
job = execute(circuit, simulator)

# Get the result
result = job.result()

# Get the final state vector
final_state_vector = result.get_statevector()

# Print the final state vector
print("State Vector:", final_state_vector)
In this code, we start with two qubits in the states |01⟩ and |10⟩. We then apply a Hadamard gate to the first qubit to create a superposition (|00⟩ + |01⟩), and finally, we apply a CNOT gate to entangle the two qubits. The result will be a Bell state, which is an entangled state: (|00⟩ + |11⟩).

When you run this code, you should observe that the final state vector matches the expected Bell state (|00⟩ + |11⟩), which signifies that the two qubits are entangled.