Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 11 additions & 24 deletions space_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import os

import numpy as np
import uvicorn
from fastapi import FastAPI, HTTPException
from fastapi.middleware.cors import CORSMiddleware
Expand Down Expand Up @@ -65,59 +66,45 @@ async def health_check():
async def run_vqe(request: VQERequest):
try:
# Use simplified VQE (fallback) - works without pyscf
from qiskit import QuantumCircuit
from qiskit_aer import AerSimulator
import numpy as np


# Simplified H₂ VQE using 2-qubit ansatz
def simplified_vqe(bond_length, shots=1024):
# Create a simple 2-qubit ansatz
theta = np.random.random() * 2 * np.pi

# Simulate VQE optimization
circuit = QuantumCircuit(2, 2)
Comment on lines 71 to 76
Copy link

Copilot AI Apr 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shots is accepted (and passed into simplified_vqe) but no longer used after removing the AerSimulator execution. This makes the API parameter effectively a no-op; either incorporate shots into the simplified simulation (e.g., scale the noise/error with shots) or remove/deprecate the parameter so clients aren’t misled.

Copilot uses AI. Check for mistakes.
circuit.ry(theta, 0)
circuit.cx(0, 1)
circuit.measure([0, 1], [0, 1])

backend = AerSimulator()
job = backend.run(circuit, shots=shots)
result = job.result()
counts = result.get_counts()


# Calculate approximate energy based on bond length
# H₂ ground state energy approximation
exact = -1.116 + 0.5 * (bond_length - 0.74)**2
exact = -1.116 + 0.5 * (bond_length - 0.74) ** 2
vqe_energy = exact + np.random.normal(0, 0.01) # Small error

return {
"energy": vqe_energy,
"error": abs(vqe_energy - exact),
"depth": circuit.depth(),
"iterations": np.random.randint(20, 50)
"iterations": np.random.randint(20, 50),
}
exact_energy = -1.116 + 0.5 * (request.bond_length - 0.74)**2

exact_energy = -1.116 + 0.5 * (request.bond_length - 0.74) ** 2
result = simplified_vqe(request.bond_length, request.shots)
Comment on lines +83 to 94
Copy link

Copilot AI Apr 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The H₂ ground-state energy approximation is duplicated (computed as exact inside simplified_vqe and again as exact_energy outside). Consider computing it once (or extracting a small helper) to avoid the two formulas drifting if updated in the future.

Copilot uses AI. Check for mistakes.

return {
"exact_energy": exact_energy,
"vqe_energy": result["energy"],
"error": result["error"],
"depth": result["depth"],
"iterations": result["iterations"],
"mode": "simplified"
"mode": "simplified",
}
except Exception as e:
raise HTTPException(status_code=500, detail=str(e)) from e


# Noisy Simulation Endpoint
}
except Exception as e:
raise HTTPException(status_code=500, detail=str(e)) from e


# Noisy Simulation Endpoint
@app.post("/api/noisy")
async def run_noisy_sim(request: NoisySimRequest):
Expand Down
Loading