Spaces:
Running on Zero
Running on Zero
Upload 5 files
Browse files- .dockerignore.txt +6 -0
- Dockerfile.txt +29 -0
- app.py +75 -0
- requirements.txt +5 -0
- server.py +21 -0
.dockerignore.txt
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
__pycache__/
|
| 2 |
+
*.pyc
|
| 3 |
+
.git/
|
| 4 |
+
.gitignore
|
| 5 |
+
build/
|
| 6 |
+
.DS_Store
|
Dockerfile.txt
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
FROM python:3.11-slim-bookworm
|
| 2 |
+
|
| 3 |
+
# Install C++20 toolchain (g++ & CMake) for Layer 1 Firmware and Layer 2 Middleware
|
| 4 |
+
RUN apt-get update && \
|
| 5 |
+
apt-get install -y --no-install-recommends g++ cmake make && \
|
| 6 |
+
rm -rf /var/lib/apt/lists/*
|
| 7 |
+
|
| 8 |
+
# Create non-root user (UID 1000) required by Hugging Face Spaces
|
| 9 |
+
RUN useradd -m -u 1000 user
|
| 10 |
+
USER user
|
| 11 |
+
ENV HOME=/home/user \
|
| 12 |
+
PATH=/home/user/.local/bin:$PATH \
|
| 13 |
+
PYTHONUNBUFFERED=1
|
| 14 |
+
|
| 15 |
+
WORKDIR $HOME/app
|
| 16 |
+
|
| 17 |
+
# Install Python dependencies for Layer 3 Quantum Co-Processor & Layer 4 Gateway
|
| 18 |
+
COPY --chown=user:user requirements.txt .
|
| 19 |
+
RUN pip install --no-cache-dir --upgrade -r requirements.txt fastapi uvicorn[standard]
|
| 20 |
+
|
| 21 |
+
# Copy full 4-layer repository into container
|
| 22 |
+
COPY --chown=user:user . .
|
| 23 |
+
|
| 24 |
+
# Compile Layer 1 (quantum_core_driver) and Layer 2 (swarm_wci_dtn_node) C++20 binaries
|
| 25 |
+
RUN cmake -B build && cmake --build build -j4
|
| 26 |
+
|
| 27 |
+
EXPOSE 7860
|
| 28 |
+
|
| 29 |
+
CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
|
app.py
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import subprocess
|
| 2 |
+
from pathlib import Path
|
| 3 |
+
from fastapi import FastAPI
|
| 4 |
+
from fastapi.responses import FileResponse, JSONResponse
|
| 5 |
+
from fastapi.staticfiles import StaticFiles
|
| 6 |
+
|
| 7 |
+
from quantum_co_processor.q_navigation_engine import (
|
| 8 |
+
ObstaclePolygon,
|
| 9 |
+
QUAVTrajectoryPlanner,
|
| 10 |
+
PQCQuantumRLAttitudeController,
|
| 11 |
+
RelativisticSpacetimeQFIEstimator,
|
| 12 |
+
)
|
| 13 |
+
import numpy as np
|
| 14 |
+
|
| 15 |
+
app = FastAPI(title="Q-SNASB & Q-MCT v4.2 Flight Deck", version="4.2.0")
|
| 16 |
+
|
| 17 |
+
BASE_DIR = Path(__file__).resolve().parent
|
| 18 |
+
UI_DIR = BASE_DIR / "ui"
|
| 19 |
+
BUILD_DIR = BASE_DIR / "build"
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
@app.get("/")
|
| 23 |
+
async def serve_flight_deck():
|
| 24 |
+
return FileResponse(UI_DIR / "q_mct_flight_deck.html")
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
@app.get("/api/telemetry")
|
| 28 |
+
async def get_live_layer_telemetry():
|
| 29 |
+
# Execute Layer 1 C++20 Quantum Core Firmware binary
|
| 30 |
+
l1_proc = subprocess.run(
|
| 31 |
+
[str(BUILD_DIR / "quantum_core_driver")],
|
| 32 |
+
capture_output=True,
|
| 33 |
+
text=True,
|
| 34 |
+
timeout=5,
|
| 35 |
+
)
|
| 36 |
+
|
| 37 |
+
# Execute Layer 2 C++20 Swarm WCI & DTN Middleware binary
|
| 38 |
+
l2_proc = subprocess.run(
|
| 39 |
+
[str(BUILD_DIR / "swarm_wci_dtn_node")],
|
| 40 |
+
capture_output=True,
|
| 41 |
+
text=True,
|
| 42 |
+
timeout=5,
|
| 43 |
+
)
|
| 44 |
+
|
| 45 |
+
# Execute Layer 3 Python Quantum Co-Processor diagnostics
|
| 46 |
+
obstacles = [ObstaclePolygon(center_xy=(500.0, 200.0), radius_m=120.0)]
|
| 47 |
+
planner = QUAVTrajectoryPlanner(start_xy=(0.0, 0.0), end_xy=(1000.0, 400.0), obstacles=obstacles)
|
| 48 |
+
candidates = [
|
| 49 |
+
[(0.0, 0.0), (500.0, 210.0), (1000.0, 400.0)],
|
| 50 |
+
[(0.0, 0.0), (480.0, 460.0), (1000.0, 400.0)],
|
| 51 |
+
]
|
| 52 |
+
quav_res = planner.evaluate_candidate_paths(candidates)
|
| 53 |
+
|
| 54 |
+
qrl = PQCQuantumRLAttitudeController(n_qubits=4, n_layers=3)
|
| 55 |
+
qrl_actions = qrl.forward_expectation_z(np.array([0.12, -0.08, 0.04, -0.15])).tolist()
|
| 56 |
+
qfim_res = RelativisticSpacetimeQFIEstimator.compute_qfim_and_qcrb(
|
| 57 |
+
r_meters=7.0e6, photon_freq_hz=3.84e14
|
| 58 |
+
)
|
| 59 |
+
|
| 60 |
+
return JSONResponse(
|
| 61 |
+
{
|
| 62 |
+
"status": "NOMINAL",
|
| 63 |
+
"layer1_firmware_stdout": l1_proc.stdout.strip().splitlines(),
|
| 64 |
+
"layer2_middleware_stdout": l2_proc.stdout.strip().splitlines(),
|
| 65 |
+
"layer3_quantum_coprocessor": {
|
| 66 |
+
"quav_qaoa": quav_res,
|
| 67 |
+
"pqc_qrl_expectations": qrl_actions,
|
| 68 |
+
"relativistic_qfim": qfim_res,
|
| 69 |
+
},
|
| 70 |
+
}
|
| 71 |
+
)
|
| 72 |
+
|
| 73 |
+
|
| 74 |
+
# Mount static HTML/CSS/JS assets at root so cross-page links resolve cleanly
|
| 75 |
+
app.mount("/", StaticFiles(directory=str(UI_DIR), html=True), name="ui")
|
requirements.txt
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
numpy>=1.26.0
|
| 2 |
+
scipy>=1.12.0
|
| 3 |
+
qiskit>=1.0.0
|
| 4 |
+
fastapi>=0.110.0
|
| 5 |
+
uvicorn[standard]>=0.29.0
|
server.py
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from fastapi import FastAPI
|
| 2 |
+
from fastapi.responses import FileResponse
|
| 3 |
+
import subprocess
|
| 4 |
+
import sys
|
| 5 |
+
|
| 6 |
+
app = FastAPI(title="Q-SNASB & Q-MCT v4.2")
|
| 7 |
+
|
| 8 |
+
@app.get("/")
|
| 9 |
+
def serve_flight_deck():
|
| 10 |
+
return FileResponse("index.html")
|
| 11 |
+
|
| 12 |
+
@app.get("/api/sil-diagnostics")
|
| 13 |
+
def run_sil_diagnostics():
|
| 14 |
+
fw = subprocess.run(["/app/build/quantum_core_driver"], capture_output=True, text=True)
|
| 15 |
+
mw = subprocess.run(["/app/build/swarm_wci_dtn_node"], capture_output=True, text=True)
|
| 16 |
+
ai = subprocess.run([sys.executable, "/app/quantum_co_processor/q_navigation_engine.py"], capture_output=True, text=True)
|
| 17 |
+
return {
|
| 18 |
+
"layer1_firmware": fw.stdout.strip(),
|
| 19 |
+
"layer2_middleware": mw.stdout.strip(),
|
| 20 |
+
"layer3_quantum_ai": ai.stdout.strip()
|
| 21 |
+
}
|