QVM v0.4.0
[GitHub]
Docs/Web API and Dashboard

800 Web API and Dashboard Interface

The QVM exposes a web interface to allow users to interactively build circuits, configure compiler/simulator engines, run simulations, view historical executions, and view results. This is implemented via a FastAPI backend in api/app.py and a Next.js React dashboard in web/src/app/page.tsx.


🔌 FastAPI Routing & Endpoints

The API server (api/app.py) runs on standard port 8000 (started by src/qvm/server.py). It exposes the following REST endpoints:

  • GET /: Serves the Next.js production build and API status.
  • GET /health: Simple healthcheck route returning {"status": "ok"}.
  • POST /run: The main execution endpoint. It accepts a RunRequest JSON payload, runs the compilation and simulation steps, and returns a RunResponse JSON payload. For comprehensive parameter documentation and curl/Python examples, see 810 REST API Reference.
  • GET /circuits: Retrieve circuit library from Supabase (if configured).
  • GET /history: Retrieve recent simulation runs from Supabase (if configured).

📥 RunRequest Schema

The request payload allows full configuration of the execution pipeline:

Field NameTypeDefaultDescription
source_typeLiteral["json", "qasm"]"json"Format of input circuit definition.
circuitList[dict]NoneGate list when source_type="json".
qasmstrNoneOpenQASM code text when source_type="qasm". Handles OpenQASM 3.0 and 2.0.
nqubitsintNoneNumber of qubits (required for JSON inputs).
transpileboolFalseEnable mapping routing stage.
routingLiteral["greedy", "sabre"]"greedy"Router pathfinding algorithm to apply.
restore_mappingboolTrueRestore initial qubit index map after SABRE.
engineLiteral["statevector", "mps"]"statevector"Simulation engine backend.
seedintNoneRandom number generator seed.
shotsint0If >0> 0, runs shot-based sampling instead of exact probabilities.
noise_depolfloat0.0Global depolarizing noise rate (00 to 11).
noise_readoutfloat0.0Global readout flip rate (00 to 11).
noise_amp_dampfloat0.0Global amplitude damping (T1T_1) rate.
noise_phase_dampfloat0.0Global phase damping (T2T_2) rate.
device_backendstrNonePredefined hardware profile (e.g. "fake_5q", "fake_7q").
expectation_pauliDict[str, float]NonePauli string mapping to coefficients for expectation value calculation.

📤 RunResponse Schema

The response payload contains the execution results and visualizations:

Field NameTypeDescription
probabilitiesList[float]Exact quantum state probabilities for all 2N2^N states.
classical_memorydictFinal state of named classical bit registers.
transpiled_operationsList[dict]The final circuit operations array after routing and decomposition.
nqubitsintThe physical qubit count used.
circuit_plotstrBase64-encoded PNG image of the circuit diagram.
histogram_plotstrBase64-encoded PNG image of the probability histogram.
countsdictShot-based sampling measurement outcomes (if shots > 0).
openqasm2strEquivalent compiled circuit exported to OpenQASM 2.0.
expectation_valuefloatComputed expectation value ⟨H⟩\langle H \rangle (if requested).
noise_summarystrText summary of the noise channels applied.

🎨 Visualization Engine

The backend generates visual plots using Matplotlib (src/qvm/visual.py) and converts them to base64 strings so they can be embedded directly in the web UI:

python
def fig_to_base64(fig):
    buf = io.BytesIO()
    fig.savefig(buf, format="png", bbox_inches='tight')
    buf.seek(0)
    img_str = base64.b64encode(buf.read()).decode("utf-8")
    plt.close(fig)
    return img_str
  • plot_circuit: Renders a symbolic diagram of the circuit showing gates, controls, and measurements.
  • plot_histogram: Plots a bar chart of the basis state probabilities.

🖥️ Web Client Dashboard Interface (Next.js Dashboard)

The dashboard provides a single-page workspace layout:

Rendering diagram...

Dashboard Workflow:

  1. The user writes an OpenQASM 3.0 script in the text editor.
  2. Configures the simulation engine, seed, and transpilation settings in the left/middle configuration panels.
  3. Clicks Run.
  4. The client makes an asynchronous fetch("/run") POST call to the backend.
  5. On success, the React component updates its state (setResults(data)), which automatically re-renders the visual plots (circuit diagram, probability histogram), classical memory, and prints logs into the bottom Terminal Output container.