Runtime server and kernel¶
The simulation server keeps one binding and its mutable simulation state in
one process. POST /api/step integrates one configured timestep; reset restores
the binding's initial state. Observing state, health or the WebSocket stream
does not advance the simulation.
Foreground startup¶
From a source checkout:
uv sync --locked --extra server --extra rust
.venv/bin/python tools/install_spo_kernel.py --check-only --json
.venv/bin/spo serve domainpacks/minimal_domain/binding_spec.yaml
The default address is 127.0.0.1:8000. Ctrl-C stops the process. The command
starts no persistent service and configures no automatic restart. On Windows,
use the corresponding executables under .venv/Scripts/.
The default --require-kernel admission first requires the selected binding's
simulation engine to dispatch to Rust. A NumPy selection raises RuntimeError
before the listener opens. Admission then executes actual native phase and
amplitude integration with analytical solutions. A missing or unusable kernel
refuses startup.
Install or update the kernel before starting the consumer process. A process that loaded SPO without the kernel can retain its earlier NumPy selection; required-native verification refuses it until the process is restarted. The verification report also requires an identifiable native library file so its hash can be recorded; an embedded module without that file is refused clearly.
An intentionally Python-only environment can install [server] and pass
--allow-python. This allows NumPy fallback; an installed usable kernel can
still be selected. The base Python package retains its documented numerical
fallbacks.
HTTP contracts¶
| Endpoint | Behaviour |
|---|---|
GET / |
Simulation dashboard. |
GET /api/state |
Current step, layer/global coherence, regime and amplitude summary. |
POST /api/step |
Advance one timestep and return the resulting snapshot. |
POST /api/reset |
Restore the initial simulation state. |
GET /api/config |
Binding name/dimensions/periods, amplitude mode, selected backend and kernel admission. |
GET /api/health |
Check simulation snapshot/coherence/regime without advancing it. |
GET /api/metrics |
Current Prometheus metrics. |
GET /api/studio-feed |
Current STUDIO feed envelope. |
WS /ws/stream |
Read-only snapshot stream. |
Configuration includes backend ("rust" or "numpy"), kernel_required,
and kernel. Required-native admission fills kernel with the verified
distribution version and native library sha256; optional admission leaves
that verification report null.
With SPO_ENV=production, SPO_API_KEY is mandatory. Mutable endpoints require
the matching X-API-Key header; production rate limits apply. Use one worker
for the shared in-process simulation. See
Production Deployment.
Public Python API¶
create_app(spec_path, require_kernel=False) returns a FastAPI application.
Direct Python callers explicitly select require_kernel=True when native
computation is part of their deployment contract. The CLI selects it by default.
verify_kernel() runs public UPDEEngine.step and
StuartLandauEngine.step against uncoupled analytical trajectories and returns
KernelVerification(version, extension, sha256). It creates its own engines
and does not advance an existing simulation. The report binds successful
numerical verification to the loaded native library.
kernel ¶
Verify the installed native kernel through public numerical consumers.
Classes¶
KernelVerification
dataclass
¶
Identity of a native binary that passed public numerical checks.
Attributes¶
version : str Installed spo-kernel distribution version. extension : str Absolute path of the loaded extension. sha256 : str SHA-256 of the loaded native library.
Functions:¶
verify_kernel ¶
Execute native phase and amplitude steps with analytical oracles.
Both engines integrate uncoupled oscillators: phase advances by omega * dt and a Stuart-Landau amplitude at its unit equilibrium stays one. The public engines must select Rust before either result can qualify native operation. This check does not advance a caller's simulation.
Returns¶
KernelVerification Installed binary identity after both real numerical operations pass.
Raises¶
ImportError The native extension cannot be loaded or has no identifiable library file. RuntimeError A public engine selected the NumPy fallback. AssertionError A native result disagrees with its analytical solution.
Source code in src/scpn_phase_orchestrator/runtime/kernel.py
create_app ¶
Create FastAPI app for the given binding spec.
Parameters¶
spec_path : str | Path Filesystem path to the binding-spec file. require_kernel : bool, default False Require native phase and amplitude verification and native dispatch in the configured simulation before accepting requests.
Returns¶
fastapi.FastAPI The configured FastAPI application.
Raises¶
RuntimeError If the configured simulation selects NumPy when native execution is required, or native verification fails. ImportError If a required optional dependency is not installed. HTTPException If the request is invalid.
Source code in src/scpn_phase_orchestrator/runtime/server.py
437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 | |
Command module¶
spo serve is implemented in scpn_phase_orchestrator.runtime.cli.serve.
serve ¶
Run a simulation API in the foreground with explicit native admission.
Functions:¶
serve ¶
Serve a binding's simulation until interrupted or terminated.
Parameters¶
spec_path : pathlib.Path Binding specification for the in-process simulation. host : str Listening address; defaults to host loopback. port : int TCP port in the range 1 through 65535. require_kernel : bool Refuse unavailable native computation unless Python is explicitly allowed.
Raises¶
click.ClickException A server dependency, binding or required native kernel is unusable.