This experiment, using qiskit and IBM's 127-Qubit Osaka, creates a quantum circuit to generate a complex entangled state across 100 qubits. It involves initializing the qubits, applying Hadamard and CNOT gates to create entanglement, and then performing ancilla-assisted and system wide measurements. The aim is to observe the behavior of this large-scale quantum system when subjected to specific quantum operations and measurements.
Code Walkthrough
1. Quantum Circuit Initialization:
The circuit is set up with 100 qubits.
The first 5 qubits are designated as ancilla qubits, and the remaining 95 qubits are system qubits.
Let ∣ψ_0⟩ represent the initial state of the entire circuit with 100 qubits.
Ancilla qubits:
2. Entanglement Generation:
The Hadamard gates H applied to each qubit create a superposition state. Mathematically, the action of a Hadamard gate on a single qubit is described by:
3. Ancilla-Assisted Measurement:
We add additional ancilla qubits to indirectly measure the state of the system qubits. Additional CNOT gates entangle each ancilla qubit with a corresponding system qubit. The state of the system qubit affects the state of its paired ancilla qubit due to this entanglement.
The measurement of a quantum state is a projection operation. When the ancilla qubits are measured, their state collapses to either ∣0⟩ or ∣1⟩. The measurement operators are M_0 = ∣0⟩⟨0∣ and M_1 = ∣1⟩, which project the qubit onto the ∣0⟩ and ∣1⟩ states respectively.
This method helps in preserving the entangled state of the system qubits, as direct measurement would collapse their quantum state.
4. Measurement:
All qubits (both ancilla and system) are measured, collapsing their quantum states into classical bits. The measurement collapses the superposition of each qubit into a definite state, which can be 0 or 1. This collapse is probabilistic and is described by the Born rule.
The Born Rule is a fundamental principle in quantum mechanics that provides the probability of observing a particular outcome. According to this rule, the probability P of measuring a qubit in state ∣0⟩ is P(∣0⟩) = ∣α∣^2, and similarly, the probability of measuring it in state ∣1⟩ is P(∣1⟩) = ∣β∣^2.
Important to note that ∣α∣^2 + ∣β∣^2 = 1, ensuring the total probability sums up to 1.
5. Execution on Osaka:
The transpilation step optimizes the quantum circuit for execution on Osaka's hardware. This optimization involves decomposing gates into elementary gates, rearranging gates for optimal execution, and handling hardware-specific constraints.
The experiment is executed for 1000 shots.
6. Result Analysis:
Complex numbers and datetime objects are handled using a custom JSON serialization function.
All results and backend data are saved to a Json for further analysis.
Code:
# Imports
import json
from datetime import datetime
from qiskit import QuantumCircuit, execute, transpile, IBMQ
from qiskit.visualization import plot_histogram
from qiskit_ibm_provider import IBMProvider
import matplotlib.pyplot as plt
# Enter your IBMQ API key here
ibm_api_key = 'Your_API_Key_Mfer'
provider = IBMProvider(ibm_api_key)
# backend name
backend = provider.get_backend('ibm_osaka')
# Define the quantum circuit for 100 qubits
num_qubits = 100
ancilla_qubits = [0, 1, 2, 3, 4] # Ancilla qubits
system_qubits = list(range(5, num_qubits)) # System qubits
circuit = QuantumCircuit(num_qubits, num_qubits) # Add classical bits for measurement
# Function to create a complex entangled state
def create_complex_entangled_state(circuit, num_qubits):
for qubit in range(num_qubits):
circuit.h(qubit)
for qubit in range(num_qubits - 1):
circuit. cx(qubit, qubit + 1)
# Function for Ancilla-Assisted Measurements
def ancilla_assisted_measurement(circuit, ancilla_qubits, system_qubits):
for ancilla, system in zip(ancilla_qubits, system_qubits):
circuit. cx(system, ancilla)
# Initialize the complex entangled state
create_complex_entangled_state(circuit, num_qubits)
# Apply Ancilla-Assisted Measurements
ancilla_assisted_measurement(circuit, ancilla_qubits, system_qubits)
# Measure the ancilla qubits
circuit.measure(ancilla_qubits, list(range(len(ancilla_qubits))))
# Add measurements to all system qubits
circuit.measure(system_qubits, list(range(len(ancilla_qubits), num_qubits)))
# Execute the circuit on the quantum computer
transpiled_circuit = transpile(circuit, backend)
job = execute(transpiled_circuit, backend, shots=1000)
result = job.result()
# Function to handle complex numbers and datetime objects for JSON serialization
def complex_to_json(obj):
if isinstance(obj, complex):
return {"real": obj.real, "imag": obj.imag}
if isinstance(obj, datetime):
return obj.isoformat() # Convert datetime objects to ISO format
raise TypeError(f"Object of type {obj.__class__.__name__} is not JSON serializable")
# Display histogram of the results
plot_histogram(result.get_counts(circuit))
plt. show()
# Prepare data for JSON serialization
data = {
"raw_counts": result.get_counts(circuit),
"backend_properties": backend. properties().to_dict()
}
# Specified path for saving the results
json_path = 'c:\\Users\\Desktop\\100_Macro_State_Collapse_results.json'
# Serialize and save the data to a JSON file
with open(json_path, "w") as f:
json.dump(data, f, default=complex_to_json)
print(f"Results saved to {json_path}")