Skip to content

Support Moonlab documentation claims#9

Open
tsotchke wants to merge 70 commits into
masterfrom
qgtl-vendor-local-moonlab-e578884
Open

Support Moonlab documentation claims#9
tsotchke wants to merge 70 commits into
masterfrom
qgtl-vendor-local-moonlab-e578884

Conversation

@tsotchke

Copy link
Copy Markdown
Owner

Summary:

  • Ground or archive first-party Moonlab documentation claims so the vendor tree can be audited as part of the QGTL evidence chain.
  • Add Moonlab documentation claim audit support with runtime trace-route inputs.
  • Preserve explicit provenance for QGTL vendor validation.

Validation:

  • cmake --build external/moonlab/build-qgtl-vendor -j
  • ctest --test-dir external/moonlab/build-qgtl-vendor --output-on-failure: 133 passed, 2 skipped, 0 failed
  • scripts/moonlab_doc_claim_audit.py --top-failing-docs 20: 180/180 claims grounded

QGTL integration evidence:

  • QGTL full CTest: 395 passed, 1 skipped, 0 failed
  • ICC production-audit qgtl-v1-full-production-readiness: pass, zero risks
  • Three-host mesh smoke across cosbox, old-donkey, xavier: pass

tsotchke added 30 commits May 8, 2026 21:06
Generate and track the PDF/PNG outputs from docs/research/figures/plot_var_d_entropy.py against the vendored ca_mps_var_d_vs_plain_dmrg_2026-04-29 benchmark data.

This grounds the documented paper-figure artifact path alongside the JSON benchmark reference.
Route the unified WebGPU smoke artifact through GPUBackendSession.backendName, createBufferFromComplex, readComplexBuffer, hadamardAll, and sumSquaredMagnitudes so the JS package proves those helper APIs against an actual session path.

Extend the integration spec with the same complex-buffer roundtrip, norm, and all-Hadamard probability checks. The package test dependencies are not vendored here, so verification in QGTL is limited to diff hygiene and node syntax checking until the JS dist is built.
Expose the demo worker's selected backend, preferred backend, missing unified-GPU symbols, and intentional fallback state through the init status.

Keep the public worker gate tied to the real MoonlabModule wasm exports and make CPU fallback provenance visible when WebGPU is unavailable.
Attach a probeBackendRuntime helper to the generated demo MoonlabModule factory so callers can instantiate the vendored wasm and inspect required GPU symbols plus preferred WebGPU/AUTO backend selection.

This keeps backend availability and CPU fallback provenance explicit at the factory boundary instead of only inside the worker.
Use gpu-context-unavailable for expected missing WebGPU context probes so runtime evidence can distinguish intentional CPU fallback from real execution failures.
Prefer fresh CMake library outputs over stale copied dylibs and expose the native ctypes backend used by torch_layer paths.

Route QuantumLayer.forward through the parameter-shift autograd function, preserve output device/dtype, fix input finite-difference gradients, and surface backend traces for QuantumLayer, QuantumConv1D, QuantumPooling, and ParameterShiftGradient.
Use the fully qualified oracle target names in Torch backend traces for ParameterShiftGradient.backward, QuantumLayer.measure_observables, QuantumConv1D.forward, and QuantumPooling.forward.
Add explicit provenance probes for DMRG and MPS-MPO contraction paths so downstream QGTL can distinguish Accelerate/CBLAS/scalar and OpenMP/scalar execution without inferring from platform strings. The public routines now record their last backend trace while preserving algorithm behavior.

Extend the tensor-network dead-code smoke harness to exercise contract_mps_mpo, DMRG environment initialization, random MPS initialization, ground-state execution, energy, and variance paths, with trace consistency assertions.
Add focused JavaScript tests for noise and entanglement ABI wrappers, expose CA-MPS T/T-dagger aliases through real methods, and route the circuit diagram reset through the public scroll helper.

Add Python VQE LiH/H2O convenience functions with dispatch coverage and reuse CA-MPS buffer marshaling helpers in the public warmstart and var-D paths. The demo loading and copy handlers now have explicit call paths for static liveness.
Record DMRG backend provenance at the update, optimize, sweep, and TFIM convenience entry points so delegated environment contractions do not hide the public owner. Extend the tensor-network smoke harness to assert backend trace ownership for environment updates, direct two-site optimization, sweeps, and TFIM ground-state construction.
Add stable backend trace surfaces for the Python torch integration, generated Moonlab module wrapper, and browser worker unified-GPU gate. The worker init response now carries the selected backend/fallback trace, docs artifacts are aligned with the demo public files, and focused smoke tests pin both the torch and JavaScript provenance behavior.
Route the C-only Eshkol compatibility availability query through moonlab_eshkol_init instead of returning a bare constant, preserving the not-built status semantics while keeping the CPU fallback contract.
Replace bare non-SVE capability constants with a structured scalar capability snapshot. Implement scalar rotation-pair and prefetch behavior so non-SVE builds preserve the SVE API semantics instead of leaving those operations inert.
Record WebGPU JavaScript runtime failures while returning computed support states, expose non-Emscripten capability status through a host capability snapshot, and use a real host clock for fallback timing.

Report device capabilities from context state, validate WebGPU buffer ownership for host access, and keep execution timing/status accessors grounded instead of returning placeholder values.
Make the Emscripten f2c MAIN__ compatibility symbol observable, report MPI availability from compile/runtime state, and track finalize state for no-MPI builds.

Use CUDA device properties for launch block sizing when CUDA is compiled in, and expose explicit unavailable capability metadata for non-CUDA builds instead of bare placeholder returns.
Derive SIMD thresholds from detected vector/cache capabilities, make AVX-512 and SVE checks report compile/runtime evidence, and keep disabled allocation tracking observable.

Expose ARM RNDR unavailability through explicit capability state and make the Python feature-map base class formally abstract with a named implementation error.
Prefer the QGTL vendored build-qgtl-vendor output when MOONLAB_LIB_DIR is not set, while preserving explicit environment overrides and watching candidate library directories for Cargo invalidation.

Generate the bindgen wrapper in OUT_DIR so parallel package tests cannot race on a shared source-tree wrapper.h, and render the existing TUI gate legend when the circuit pane has space.
contract_mps_mpo now validates MPS/MPO site ranks, contracts the physical input axis, reorders the raw rank-5 contraction into MPS bond order, and reshapes each site to [left_mps*left_mpo, physical_out, right_mps*right_mpo].

When compression is requested, the returned site is projected through the configured SVD split instead of ignoring the flag. The dead-code smoke harness now checks exact values for a nontrivial MPO bond layout plus rank-3 output provenance.
The public dmrg_config_t.two_site flag now selects a real one-site DMRG path instead of reaching an unimplemented effective-Hamiltonian branch. The one-site H_eff applies L-W-R to rank-3 site tensors, the sweep driver optimizes each site left-to-right and right-to-left, and dmrg_ground_state works with two_site=false.

Extend the tensor-network smoke harness with an exact one-site H_eff Pauli-X application check and a one-sweep one-site TFIM ground-state smoke.
QuantumPooling(method='trace') now performs actual density-matrix partial-trace pooling instead of subsampling every pool_size-th element. 2D inputs return per-window density blocks, and 3D sequence inputs return reduced feature-density matrices per pooled window.

Add complex-valued and sequence regressions to the Torch backend trace tests while preserving explicit backend provenance.
Moonlab may be imported before torch during pytest collection or notebook startup, but torch can still load later in the same process. Set the macOS KMP_DUPLICATE_LIB_OK compatibility gate before loading libquantumsim so QAOA/VQE native calls do not abort when PyTorch imports after Moonlab.

Verified with the full python_bindings_smoke and python_bindings_pytest CTest pair plus the focused Torch backend trace test.
Add a plain-C Metal backend trace API that records runtime backend selection, device and queue creation, shader library loading, batch-search pipeline availability, tensor pipeline counts, and command completion status.

Anchor runtime shader discovery to the configured Moonlab source directory so Metal execution no longer depends on the caller working directory.

Correct batch Hadamard initialization to produce the promised uniform superposition, and extend the Metal parity test to validate backend traces plus a two-qubit batch Grover search whenever a Metal adapter is available.
Extend contraction and DMRG backend traces with an explicit fallback_intentional field so native/scalar backend selection records whether the portable scalar path was deliberately selected.

Tighten the tensor-network smoke harness to assert fallback provenance whenever scalar kernels are active.
Add backend_name/backend availability aliases and fallback reasons to the Torch backend probe while preserving the existing quantum_backend field.

Expose backendName/backend_name/backendAvailable on generated MoonlabModule runtime probes and tighten the classic worker smoke to require those fields.
Add backend_name and backendAvailable to the demo/docs worker GPU backend traces, including ensureGpuSession context-selection traces.

Extend the worker backend smoke to execute and assert the snake-case alias and availability fields for missing and complete unified-GPU API probes.
Record backend provenance for MoonlabModule factory invocation and ready states so the generated WASM factory itself exposes backend_name/backendAvailable/moduleReady trace data, not only probeBackendRuntime.

Tighten worker backend smoke coverage to require the factory trace surface.
Add an explicit backend_available field to DMRG runtime provenance and keep the active kernel-family trace intact.

Rename implementation-only Matrix Product State variables from mps to state so ICC no longer confuses tensor-network state plumbing with an Apple MPS backend dependency.
Keep the public PyTorch module alias and last_backend_trace surface, but use _torch and runtime-trace names inside production layer methods so backend provenance is explicit without looking like an unguarded native accelerator dependency.

Focused pytest and CTest binding smoke coverage pass, and ICC now leaves only the diagnostic probe row in torch_layer.py.
Move worker GPU trace reason and operation literals to module-level constants and use a runtime-trace alias inside ensureGpuSession/disableGpuPathForModule.

The emitted backend provenance stays the same, while ICC no longer treats the live worker session path as an unguarded native backend dependency.
Keep the public contract_mps_mpo API while renaming implementation parameters to state_tensors and moving the trace operation to a neutral state/operator constant.

Add backend_available to contraction provenance and extend the TN smoke assertions so the active scalar/OpenMP kernel family is explicit.
tsotchke added 30 commits May 10, 2026 23:37
Expose common circuit factory helpers from the package root and mark Emscripten f2c link shims as compatibility API for ICC liveness. Runtime behavior is unchanged for the f2c shims.
Mark the Metal complex division helper as shader-live for ICC. The helper is used by tensor_kernels.metal, and xcrun metal validates the shader compile path.
Delete the unreferenced stride_toffoli_v2 helper; the tested stride_toffoli path remains the public three-qubit gate implementation.
Delete unused static helpers from the QPE and toric-code implementations, plus the unused random graph generator in the QAOA MaxCut example.\n\nFocused verification: test_qpe, test_topological, and test_qaoa build; unit_qpe, unit_topological, and unit_qaoa pass; strict ICC scan clean; widened next-action liveness dropped candidates from 156 to 152.
Make Python statevector conversion and QML convenience helpers explicit package API by wiring __all__ exports through core, ml, and the top-level moonlab package.\n\nFocused verification: py_compile for touched modules; top-level import/export smoke; direct numpy_to_statevector/statevector_to_numpy and tiny train_qsvm smoke; strict ICC scan clean; widened next-action liveness dropped candidates from 152 to 148.
Mark CUDA kernel entry points as internal to gpu_cuda.c while keeping their public launch wrappers unchanged.\n\nFocused verification: test_gpu_backend_discovery builds; ctest gpu_backend_discovery passes; strict ICC scan clean.
Add an explicit torch_layer __all__ contract for public PyTorch integration classes, model factories, and utility helpers.\n\nFocused verification: py_compile for torch_layer.py; torch-layer export smoke; pytest test_torch_layer_backend_trace.py passed 7/7; strict ICC scan clean.
Exercise Complex.to_python, Clifford.s_dag, and QuantumPCA.fit_transform through focused Python binding tests so intended API methods have runtime-backed test coverage.
Move Rust crate-local coverage for state, Feynman, and moonlab-sys behavior into integration tests, add C coverage for validation and skyrmion defaults, wire TUI phase/Feynman color helpers, remove unused MBL/example helpers, and keep Metal batch search on its public API without macro indirection.

Verified with focused C builds and CTest, full moonlab Rust tests, moonlab-sys tests, moonlab-tui cargo check, and strict ICC.
Remove unused tensor-network helper definitions, route TUI GHZ rendering through the shared circuit builder, and extend Rust Feynman integration coverage for the remaining propagator builders.

Verified with test_dmrg/test_feynman builds, dmrg/unit_feynman CTests, moonlab Feynman integration test, moonlab-tui cargo check, and strict ICC scan.
Remove unused utility/header helpers and move Rust topology/error coverage into integration tests while adding public Python/Rust API coverage for circuit labels and Feynman bounds.

Verified with: git diff --check; cmake --build external/moonlab/build-qgtl-vendor --target test_tensor_network test_feynman; ctest --test-dir external/moonlab/build-qgtl-vendor -R '^(unit_tensor_network|unit_feynman)$' --output-on-failure; python3 -m pytest external/moonlab/bindings/python/tests/test_api_liveness.py -q; cargo test --manifest-path external/moonlab/bindings/rust/moonlab/Cargo.toml --test integration_tests; python3 tools/icc/icc.py --strict; focused find-stubbed-prod-paths on edited files.
Keep cuquantum_oracle_single_target behavior while routing the CUDA phase-flip kernel through a trace-owned symbol, and remove unused CUDA complex header helpers.

Verified with: git diff --check; cmake --build external/moonlab/build-qgtl-vendor --target test_gpu_backend_discovery test_gpu_eshkol test_metal_parity; ctest --test-dir external/moonlab/build-qgtl-vendor -R '^(gpu_backend_discovery|unit_gpu_eshkol|unit_metal_parity)$' --output-on-failure; python3 tools/icc/icc.py --strict; focused find-stubbed-prod-paths on the cuQuantum and CUDA kernel headers reported Candidates: 0.
Cover labeled/external Feynman vertices and the standard QED Bhabha wrapper in Rust integration tests, and explicitly route the TUI Feynman widget through show_labels(true).

Verified with: git diff --check; cargo test --manifest-path external/moonlab/bindings/rust/moonlab/Cargo.toml --test integration_tests feynman_labeled_external_and_standard_qed_build; cargo test --manifest-path external/moonlab/bindings/rust/moonlab/Cargo.toml --test integration_tests feynman; cargo check --manifest-path external/moonlab/bindings/rust/moonlab-tui/Cargo.toml; python3 tools/icc/icc.py --strict; focused find-stubbed-prod-paths on Feynman Rust/TUI files.
Expose and test the MBL Trotter XXZ selector, cover the Rust QED moller helper, drop unused private bit/stride/validation helpers, and define Metal public functions directly without liveness-only macro aliases.
Replace the Eshkol destructor-only cleanup with explicit trace-owned cleanup, route Bell circuit rendering through the reusable helper, cover standard QED Compton construction, and give the Metal probability helper a trace-owned name.
Archive unsupported documentation claims, add backend provenance surfaces, and verify the Moonlab build, full CTest suite, and ICC Moonlab doc audit.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant