Recipe
Quantum Simulation
This recipe shows how to use the Synaptiq API to simulate quantum systems and visualize the results.
Overview
Synaptiq's quantum simulation capabilities allow you to model quantum systems, run simulations, and visualize the results. This is particularly useful for researchers in quantum physics, quantum computing, and related fields.
Example: Bell State Preparation
In this example, we'll use the Synaptiq API to simulate the preparation of a Bell state, one of the simplest examples of quantum entanglement.
from openai import OpenAI
client = OpenAI(
api_key=SYNAPTIQ_API_KEY,
base_url="https://api.synaptiq.contact/v1",
)
prompt = """
Simulate the following quantum experiment: Bell state preparation.
Initialize two qubits in the |00⟩ state.
Apply a Hadamard gate to the first qubit.
Apply a CNOT gate with the first qubit as control and the second as target.
Show the mathematical derivation, quantum circuit, and measurement statistics.
"""
completion = client.chat.completions.create(
model="synaptiq-2-quantum",
messages=[
{"role": "user", "content": prompt}
]
)
print(completion.choices[0].message.content)
Response Format
The response will include:
- Mathematical Formalism: Step-by-step derivation of the quantum state evolution
- Quantum Circuit: ASCII representation of the quantum circuit
- Measurement Statistics: Probabilities of different measurement outcomes
- Insights: Explanation of the quantum phenomena demonstrated
Example Response
Bell State Preparation and Analysis
Mathematical Formalism
We begin with a 2-qubit system in the ground state:
|ψ₀⟩ = |00⟩
First, we apply a Hadamard gate to the first qubit:
H|0⟩ = (1/√2)(|0⟩ + |1⟩)
So our state becomes:
|ψ₁⟩ = (1/√2)(|0⟩ + |1⟩) ⊗ |0⟩ = (1/√2)(|00⟩ + |10⟩)
Next, we apply a CNOT gate with the first qubit as control and the second as target:
CNOT|ψ₁⟩ = (1/√2)(|00⟩ + |11⟩)
This is the Bell state |Φ⁺⟩, one of the maximally entangled two-qubit states.
Quantum Circuit
q_0: ──[H]──●──
│
q_1: ────────X──
Measurement Statistics
When we measure this Bell state, quantum theory predicts we should observe either both qubits in state |0⟩ or both in state |1⟩, with equal probability (50% each).
| Measurement | Count | Probability |
|-------------|-------|------------|
| 00 | 512 | 0.5 |
| 11 | 512 | 0.5 |
| 01 | 0 | 0.0 |
| 10 | 0 | 0.0 |
Insights
This experiment demonstrates quantum entanglement, one of the most profound phenomena in quantum mechanics. The key observations:
- The qubits are in a superposition of states until measured.
- After entanglement, the measurement outcomes of the two qubits are perfectly correlated - if one is measured as |0⟩, the other will always be |0⟩, and similarly for |1⟩.
- This correlation persists regardless of the spatial separation between the qubits, which Einstein famously referred to as "spooky action at a distance."
- The Bell state created here (|Φ⁺⟩) is maximally entangled, meaning it cannot be factored into a product of individual qubit states.
Advanced Options
You can customize your quantum simulation by specifying additional parameters:
- Number of qubits: Specify the number of qubits in your simulation
- Gate sequence: Specify the sequence of quantum gates to apply
- Measurement basis: Specify the basis in which to measure the qubits
- Visualization type: Request specific visualizations, such as Bloch sphere or probability histogram