A Julia-based web API for quantum network operations, built with the Genie web framework and QuantumSavory quantum computing library. This API provides endpoints for creating, preparing, and running quantum network simulations.
-
Clone the repository:
git clone <repository-url> cd cqn
-
Install Julia dependencies:
julia --project=. -e 'using Pkg; Pkg.instantiate()'
./bin/serverThe server will start on http://localhost:8000 by default.
The user interface is available at http://localhost:8000.
- Create Network (
POST /parse_network_graph) - Upload network graph definition - Prepare Simulation (
POST /prepare_simulation) - Launch protocols and setup network - Run Simulation (
POST /run_simulation) - Execute simulation for specified time units - Monitor State (
GET /get_state) - Check simulation status and progress - Cleanup (
POST /destroy_simulation) - Remove simulation and free resources
- Pause Simulation (
POST /pause_simulation) - Pause a running simulation- Requires simulation to be currently running
- Sets
simulation_pausedflag totrue - Simulation will stop at the next loop iteration
- Returns error if simulation is not running
The simulation state includes a simulation_paused boolean field that indicates whether the simulation has been paused by user request. When paused, the simulation stops gracefully and can be monitored through the state endpoint.
# Start a simulation
curl -X POST http://localhost:8000/run_simulation \
-H "Content-Type: application/json" \
-d '{"name": "my-simulation", "time_units": 100}'
# Pause the simulation
curl -X POST http://localhost:8000/pause_simulation \
-H "Content-Type: application/json" \
-d '{"name": "my-simulation"}'
# Check simulation state
curl http://localhost:8000/get_state?name=my-simulationThe state response will show simulation_paused: true and simulation_running: false when the simulation has been paused.
GET /background_types- Available background noise modelsGET /slot_types- Available quantum slot typesGET /protocol_types- Available protocol types with parametersGET /protocols/:name/:protocol_id- Details for a protocol instance in a simulationGET /slots/:name/:slot_id- Details for a slot in a simulationGET /simulations- List existing simulations withnameandstatusGET /known_functions- List of supported Julia functions usable as argument valuesPOST /test_code- Test Julia code in a sandboxed environmentPOST /test_symbolic_expression- Evaluate a symbolic expression and return LaTeXGET /platform_info- Versions: Julia, QuantumSavory (if installed), and app versionGET /logs/:name- Fetch log events for a simulation; supportspurgequery (defaulttrue). Example:/logs/my-sim?purge=falseGET /status- Server health checkGET /docs- Interactive Swagger UI
created- Network parsed and storedprepared- Protocols launched, ready to runcomplete- Simulation executed and finished
When monitoring simulation state via GET /get_state, the response includes a simulation object with:
simulation_running- Boolean indicating if simulation is actively runningsimulation_paused- Boolean indicating if simulation was paused by user requestsimulation_time- Total time units for the simulationsimulation_progress- Current simulation time progresssimulation_error- Error message if simulation failed
The best way to explore the API is through the interactive Swagger documentation at /docs. It provides:
- Complete endpoint documentation
- Request/response schemas
- Interactive testing interface
- Example payloads and responses
Use POST /test_symbolic_expression to evaluate a symbolic expression in a sandboxed module with QuantumSavory preloaded and get its LaTeX representation.
Example request body:
{ "expr": "(Z₁⊗Z₁+Z₂⊗Z₂) / √2" }Successful response:<
{ "success": true, "latex": "... LaTeX string ..." }On error, you'll receive:
{ "success": false, "error": "<message>", "error_type": "<ExceptionType>" }This project includes unit tests and integration tests.
- Unit tests validate core logic and helpers without requiring a running server.
- Integration tests exercise the HTTP API and require the server to be running at
http://localhost:8000.
cd test
julia --project runtests.jl test_unitNotes:
- Unit tests include deterministic checks for the background cleanup via
cleanup_stale_simulations_once(). - When creating states from payloads in tests, always call
Cqn.validate_payload(payload)beforeCqn.parse_network_graph(...).
-
Start the server (in a separate terminal):
./bin/server
-
In another terminal, run:
cd test julia --project runtests.jl test_integration
The system includes a background task that periodically cleans up simulations that have been inactive for more than 30 minutes.
-
Service function:
Cqn.cleanup_stale_simulations()(insrc/services.jl) -
Frequency: every 60 seconds
-
Threshold: 30 minutes of inactivity
-
Skips cleanup when
state.is_running == true -
Startup: launched from
routes.jlinsidebootstrap()via@async Cqn.cleanup_stale_simulations() |> errormonitor
-
Logging: before destroying a stale simulation, an event is logged with the simulation's state using the Logger module macro:
@log_event state Logging.Info "Stopping simulation $simulation_name after $CLEANUP_THRESHOLD minutes of inactivity"
You can trigger a single cleanup pass manually (useful in tests) via Cqn.cleanup_stale_simulations_once().