Add Gaussian signal processing examples and runbook - #47
Conversation
We do not need monotonic time here, and we are generally dealing with UNIX time everywhere else (including in p4p and pcaspy)
- gaussian_sim.py: Noisy Gaussian beam profile simulator (p4p direct) - gaussian_classical.py: Classical denoiser using scipy curve_fit - gaussian_train.py: Train PyTorch MLP for Gaussian parameter estimation - gaussian_ml.py: ML-based denoiser using trained neural network - lume-pva-runbook.md: Comprehensive getting-started guide The Gaussian examples demonstrate: - Independent multi-process architecture (simulator + model) - Remote PV subscription (continuous mode) - Classical vs ML approaches to the same problem - Side-by-side real-time comparison via EPICS PVs
…d EPICS_CA_NAME_SERVERS
Two modes for PV ack'ing: * immediate: Ack the pvput/caput request as soon as it's been inserted into the update queue. * complete: Ack the pvput/caput request after the model is done simulating. Requires timeout changes on the client side for long-simulating models. Also adds a model state PV that gets updated with the model's current state.
|
I was able to get the examples running. I think it makes sense to remove some sections from the runbook - Part 2 Installation and configuring conda environment since software engineers are able to do that by themselves. The example are also a bit long and can be cleaned up. |
|
@JJL772 — Ready for review whenever you get a chance. |
Merge pr-fix-put-timeouts: adds prefix CLI, put-mode, and STATUS PV
All PV names are now configurable at runtime: - gaussian_sim.py: --pv-prefix (default: SIM:) - gaussian_classical.py: --pv-prefix (default: example:) + --sim-prefix (default: SIM:) - gaussian_ml.py: --pv-prefix (default: example:) + --sim-prefix (default: SIM:) No more hardcoded PV names. Multiple instances can run simultaneously with different prefixes. Uses add_common_test_args from upstream.
|
This will be merged after #40 |
| """ | ||
| Classical denoiser: estimates Gaussian parameters from noisy signal | ||
| using nonlinear least-squares curve fitting. | ||
|
|
||
| Inputs: | ||
| - noisy_signal (256-point array from simulator) | ||
| - x_axis (256-point array from simulator) | ||
|
|
||
| Outputs: | ||
| - est_mean (estimated center position) | ||
| - est_sigma (estimated width) | ||
| - est_amplitude (estimated peak height) | ||
| - denoised_signal (reconstructed clean Gaussian from fit) | ||
| - fit_quality (R-squared goodness of fit, 0 to 1) | ||
| """ |
There was a problem hiding this comment.
Please follow the syntax guidelines for docstrings (See runner.py for the syntax; I believe it's Google-style docstrings or something)
There was a problem hiding this comment.
We actually use numpy-style docstrings
https://sphinxcontrib-napoleon.readthedocs.io/en/latest/example_numpy.html
There was a problem hiding this comment.
whoops- thanks for clarifying. I always get these mixed up
| """ | ||
| ╔══════════════════════════════════════════════════════════════╗ | ||
| ║ NEURAL NETWORK INFERENCE ║ | ||
| ║ ║ | ||
| ║ Instead of curve_fit (iterative optimization, ~2ms), ║ | ||
| ║ we do ONE forward pass through a trained network (~0.1ms). ║ | ||
| ║ ║ | ||
| ║ The network has already "memorized" the mapping from ║ | ||
| ║ noisy signals to parameters during training. ║ | ||
| ╚══════════════════════════════════════════════════════════════╝ | ||
| """ |
There was a problem hiding this comment.
Same thing: Please follow the docstring format
- start-all.sh: launches all 5 servers with verification - Individual run-*.sh scripts for each server - Includes EPICS env setup (suppresses CA beacon warnings) - Self-documenting: prints PV names, prefixes, and demo commands
|
This should reference |
tangkong
left a comment
There was a problem hiding this comment.
Why is this being added to lume-pva? This looks like an exercise in basic machine learning, rather than demonstrating capabilities of lume-pva.
This should probably be distilled into an example of how to configure monitoring of remote PVs, without all the machine learning machinery.
| from typing import Any | ||
|
|
||
| import numpy as np | ||
| from scipy.optimize import curve_fit |
There was a problem hiding this comment.
This isn't currently installed. If you really want to support it, it should be added to the dev dependencies
| """ | ||
| Classical denoiser: estimates Gaussian parameters from noisy signal | ||
| using nonlinear least-squares curve fitting. | ||
|
|
||
| Inputs: | ||
| - noisy_signal (256-point array from simulator) | ||
| - x_axis (256-point array from simulator) | ||
|
|
||
| Outputs: | ||
| - est_mean (estimated center position) | ||
| - est_sigma (estimated width) | ||
| - est_amplitude (estimated peak height) | ||
| - denoised_signal (reconstructed clean Gaussian from fit) | ||
| - fit_quality (R-squared goodness of fit, 0 to 1) | ||
| """ |
There was a problem hiding this comment.
We actually use numpy-style docstrings
https://sphinxcontrib-napoleon.readthedocs.io/en/latest/example_numpy.html
|
|
||
| tmux kill-session -t $SESSION 2>/dev/null | ||
| tmux new-session -d -s $SESSION | ||
| tmux send-keys -t $SESSION "conda activate lume-pva && source $ENVSCRIPT && cd $SRCDIR && python -m examples.math_model --pv-prefix '$PREFIX' --put-mode $PUT_MODE" Enter |
There was a problem hiding this comment.
tmux is not installed in every environment by default, and this script makes many assumptions about the environment this is being run in.
This type of script isn't really appropriate to package with lume-pva. It belongs external to this repository, at best
- examples/__init__.py: add --pv-server-protocol CLI flag (default: ca pva) - gaussian_classical.py, gaussian_ml.py: wire flag into Runner config - run-gauss-*.sh: use PVA-only mode, source epics-env-localhost.sh - start-all-pva.sh: launch 3 gaussian servers in PVA-only mode - epics-env-localhost.sh: EPICS env for local development When --pv-server-protocol pva is set, Runner skips pcaspy entirely. Zero CA listeners. Clients use pvxget/pvxput/pvxmonitor. pvua client side (subscribing to remote PVs) is unaffected.
|
After talking with Ernest, he decided that this PR belongs in a separate sandbox, since there are already some smaller examples here. |
Summary
Adds a Gaussian beam profile signal processing pipeline demonstrating lume-pva's core capabilities.
New Files
examples/gaussian_sim.py— Noisy Gaussian beam profile simulator (p4p direct)examples/gaussian_classical.py— Classical denoiser using scipy curve_fitexamples/gaussian_train.py— Train PyTorch MLP for Gaussian parameter estimationexamples/gaussian_ml.py— ML-based denoiser using trained neural networkexamples/lume-pva-runbook.md— Comprehensive getting-started guideWhat These Demonstrate
How to Run