levisim.web.server

Local HTTP server and JSON API for the interactive levisim Three.js web labs.

Launch from the command line via:

levisim-web                          # serves on http://127.0.0.1:8765 and opens browser
levisim-web --port 8080 --no-open    # serve without opening a browser tab
python -m levisim.web --lab tweezer  # open directly to the free-space tweezer lab

Only the Python standard library is used for HTTP serving; physics calculations delegate directly to levisim.physics and levisim.analysis.

levisim.web.server.compute_tweezer_spectra(params)[source]

Computes live free-space tweezer motional and optical spectra using Trap.

Parameters:

params (dict) – Physical parameters (laser power, waists, wavelength, bead radius, gas pressure and temperature, cold feedback damping, directed force strength/angle, detection floor, photon recoil flag, and frequency grid).

Returns:

JSON-serialisable dictionary with frequency grid (kHz), one-sided motional PSDs Sxx, Syy, Szz [m²/Hz], co-/quad-spectra Cxy, Qxy [m²/Hz], thermal baselines, balanced optical detector spectra in shot-noise units, and derived trap telemetry.

Return type:

dict

levisim.web.server.run_tweezer_simulation(params)[source]

Runs a short stochastic Kasdin RK4 Simulation and returns Bartlett spectral estimates.

Parameters:

params (dict) – Free-space trap parameters plus optional num_samples, num_segments and seed.

Returns:

Estimated frequency bins (kHz) and one-sided Sxx, Syy and Cxy arrays.

Return type:

dict

levisim.web.server.dispatch_request(method, path, body=b'', *, static_dir=None, three_dir=None)[source]

Dispatches an HTTP request to static lab assets or JSON physics APIs.

Returns (status_code, content_type, body_bytes, cache_control).

Parameters:
Return type:

tuple[int, str, bytes, str]

levisim.web.server.create_server(host='127.0.0.1', port=8765, *, static_dir=None, three_dir=None)[source]

Creates a threaded HTTP server for the levisim Three.js web interfaces.

Parameters:
  • host (str) – Interface to bind (default '127.0.0.1').

  • port (int) – TCP port (0 selects an ephemeral port).

  • static_dir (Path, optional) – Override directory containing static web assets.

  • three_dir (Path, optional) – Optional local directory of the three npm package so HTML pages can load Three.js from /vendor/three/ without internet access.

Returns:

Ready-to-serve threaded HTTP server instance.

Return type:

http.server.ThreadingHTTPServer

levisim.web.server.serve(host='127.0.0.1', port=8765, *, lab='tweezer', open_browser=True, three_dir=None)[source]

Starts the levisim Three.js web server and blocks until interrupted.

Parameters:
Return type:

None

levisim.web.server.main(argv=None)[source]

Command-line entry point for levisim-web.

Parameters:

argv (list[str] | None)

Return type:

int