Skip to content

Bax visualization extension - #275

Open
MitchellAV wants to merge 35 commits into
mainfrom
develop-bax-extension
Open

Bax visualization extension#275
MitchellAV wants to merge 35 commits into
mainfrom
develop-bax-extension

Conversation

@MitchellAV

@MitchellAV MitchellAV commented Jul 3, 2026

Copy link
Copy Markdown
Collaborator

PR #275 — Changelog

Added new BAX visualization extension which displays plots related to BAX algorithm runs

  • New Bax Visualizer extension added to the extensions palette (button wired in extensions_palette.py, BaxVisualizer class in analysis_extensions.py)
  • Includes two tabs which display two sets of plots
  • Plot variables can be independently controlled or excluded to produce 1D versions of plots
  • Plot options are dynamic to which algorithm was used. Currently supported: GridOptimize, EmittanceAlgorithm, and PathwiseSolenoidAlignment — plot options and result keys differ per algorithm, and unused options are hidden
  • New widget package under src/badger/gui/components/bax_visualizer/ (bax_widget.py, controls.py, plotting.py, ui.py)
  • Palette now guards all three extensions (Pareto, BO, BAX) with a warning dialog if opened before a routine is started
  • bax generator un-excluded from ALGO_EXCLUDED in factory.py so it's selectable in the UI

Added reference-point support to BAX and BO extensions

  • New get_latest_reference_points() helper in extension_utilities.py
  • Reference-point controls added to the BAX and BO visualizer control areas, defaulting to the latest data point

BADGER_TEMP_DIRECTORY additions

  • Added BADGER_TEMP_DIRECTORY setting, used by the BAX generator to store files
  • Added the directory to the settings UI; defaults to the OS-appropriate Badger config folder under temp (e.g. ~/Library/Application Support/Badger/temp)
  • If the bax algorithm is used, creates a new temp folder inside BADGER_TEMP_DIRECTORY matching the archive file name
  • get_or_create_temp_directory() in settings.py: migrates older/relative configs to an absolute path under the user config folder, ensures it exists, and falls back to the config folder on permission errors
  • build_bax_results_file() helper in gui/utils.py and filter_generator_config BAX branch that set algorithm_results_file; used from home_page.py to create the per-run folder
  • badger info CLI now reports the temporary directory (actions/__init__.py)
  • Settings dialog also now persists BADGER_LOG_DIRECTORY (previously never saved) alongside the new temp directory (settings_dialog.py)
  • Added temp-directory support to mock_settings and test fixtures

Pydantic editor changes

  • Added specific exceptions to the pydantic editor to allow external BAX algorithms from bax-algorithms that live outside Xopt BaxGenerator._supported_algorithms
  • Added an exclusion list for pydantic fields with unsupported data types (e.g. pd.DataFrame)
  • COMMON_EXCLUDED_FIELDS / GENERATOR_EXCLUDED_FIELDS framework via get_excluded_fields(); excludes computation_time and algorithm_results_file
  • Tensor-typed fields are parsed to a plain string so values round-trip cleanly
  • Renders the class_path computed field so vendored BAX algorithms appear in the editor

BO Visualizer & Pareto Front fixes

  • Fixes various issues with the BO Visualization and Pareto Front extensions
  • AnalysisExtension base changed from QDialog to a top-level QWidget (Window flag) for consistent lifetime/stacking
  • AnalysisWidget reworked: added reset_widget() and rebuilt requires_reinitialization() run/data-growth tracking
  • Pareto Front widget reworked to reference UI components the same way as the other extensions (pf_viewer/pf_widget.py, pf_viewer/types.py)

Packaging / pyproject.toml

  • Added bax-algorithms as a dependency for the required external BAX algorithms
  • Bumped minimum xopt to >=3.2.1
  • Fixed coverage target (--cov=badger instead of --cov=badger/) so coverage data is collected
  • Replaced deprecated [options] table with [tool.setuptools]
  • Migrated license to SPDX (license = "GPL-3.0-or-later" + license-files), removed the deprecated license classifier, and bumped setuptools>=77.0.0

CI / tooling

  • Updated .pre-commit-config.yaml: pre-commit-hooks v5→v6, ruff v0.12.2→v0.15.16 added a commented-out mypy hook
  • Bumped GitHub Actions across docs.yml, lint.yml, pypi_release.yml, tests.yml: checkout v4→v7, setup-node v4→v7, setup-python v5→v7, setup-miniconda v3→v4
  • Updated AGENTS.md coverage note

Tests

  • conftest.py: added mock_temp_directory fixture and temp-dir setup/teardown
  • test_factory.py: added a bax generator instantiation case
  • test_cli_basic.py: expected badger info line count 11→12
  • test_gui_basic.py: hardened the low-noise-prior assertion for generators that hide the key
  • test_settings.py: patches get_or_create_temp_directory in the init-settings test

Misc

  • Added type annotations and import-ordering cleanup across GUI components (run_monitor.py, routine_page.py, utils.py, and others)

@MitchellAV

Copy link
Copy Markdown
Collaborator Author

@dylanmkennedy Test the extension with the updated Xopt and bax-algorithm PR changes referenced to confirm desired function

@MitchellAV
MitchellAV marked this pull request as ready for review July 31, 2026 19:23
@MitchellAV
MitchellAV requested a review from michaellans August 3, 2026 21:40
@nstelter-slac
nstelter-slac self-requested a review August 4, 2026 16:26
@michaellans

michaellans commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

The main Badger GUI selects index 0 of the generator list as the 'default', which in this case becomes bax (alphabetical). I don't think this is intentional, it might be good to add something like set_default_algorithm("neldermead") instead

self.routine_editor.generator_box.cb.setCurrentIndex(0)

Didn't make it a separate method (and ui element names are slightly different) but something like this seems to work well 9dc4e30

@MitchellAV

Copy link
Copy Markdown
Collaborator Author

The main Badger GUI selects index 0 of the generator list as the 'default', which in this case becomes bax (alphabetical). I don't think this is intentional, it might be good to add something like set_default_algorithm("neldermead") instead

self.routine_editor.generator_box.cb.setCurrentIndex(0)

Didn't make it a separate method but something like this seems to work well 9dc4e30

I've made the change to have it default to "neldermead" instead of "bax" as the default. The generators were originally sorted alphabetically causing the change.

@michaellans

michaellans commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

Testing on mac the temp folder shows up where I'd expect, and badger settings dialog menu looks good.

This may be minor/separate, but might be helpful to have documentation/comments somewhere outside of the PR description on how badger uses temp files, it's not obvious that the /temp dir is for bax working files with /temp/[env-year-month-day-timestamp]/ , and then there's a separate dir /archive with /archive/.tmp for the badger routine .tmp files.

@MitchellAV

Copy link
Copy Markdown
Collaborator Author

Added description of new temp directory to docs. Requested @dylanmkennedy to put together a generator guide for the bax generator for the docs

@pluflou

pluflou commented Aug 4, 2026

Copy link
Copy Markdown
Collaborator

FYI the changes to the CI/packaging look good to me.

@pluflou

pluflou commented Aug 4, 2026

Copy link
Copy Markdown
Collaborator

One thing to note is that I don't think bax-algorithms is on conda-forge yet. So if we want to ship Badger with that as a core dependency, we need to add the package to conda-forge @dylanmkennedy

@nstelter-slac nstelter-slac left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice!

here are some of my initial thoughts on this PR:

  1. maybe i have things setup wrong but after pulling this PR, when i click from a different algo then to bax on the "Algorithms" tab, i get an error popup from "get_compatible_algorithms()". can u describe how u manually tested this in the commit msg?

  2. and tests for the new gui code functionality would be really nice

  3. this PR is too big for my tastes, and including style/formatting changes in the PR makes harder to see the actual functional changes. especially with ai making large changes now, i think we should make extra sure to keep PRs small and manageable for review

  4. will bax documentation be added when click "Open Docs" button for bax?

  5. and should the "gui guide" (https://github.com/xopt-org/Badger/blob/main/GUI_GUIDE.md) be updated with screenshots of the new gui windows?

  6. minor thing: this PR comes from a branch on slaclab:badger instead of a fork. should we standardize on using PRs from forks since badger is community wide open-source project? (and since only those with permissions can make branches).

Comment thread src/badger/gui/components/bax_visualizer/.gitignore Outdated
Comment thread .pre-commit-config.yaml Outdated
Comment thread src/badger/gui/components/bax_visualizer/bax_widget.py Outdated
Comment thread src/badger/gui/components/bax_visualizer/bax_widget.py Outdated
@MitchellAV

Copy link
Copy Markdown
Collaborator Author

nice!

here are some of my initial thoughts on this PR:

  1. maybe i have things setup wrong but after pulling this PR, when i click from a different algo then to bax on the "Algorithms" tab, i get an error popup from "get_compatible_algorithms()". can u describe how u manually tested this in the commit msg?

Both xopt and bax-algorithm had releases to support this PR. If you are experiencing errors I would suggest reinstalling badger to pickup the new package versions.

  1. and tests for the new gui code functionality would be really nice

There are no gui tests currently for any of the badger extensions. I can aim to add gui tests to bo visualizer, pareto front viewer, and bax visualizer extensions. At the moment, I don't see this as blocking and can happen in a follow up PR.

  1. this PR is too big for my tastes, and including style/formatting changes in the PR makes harder to see the actual functional changes. especially with ai making large changes now, i think we should make extra sure to keep PRs small and manageable for review

Yes, I agree that the PR has inflated in size over the last 2-3 months of work. I will aim to keep future PRs to a more manageable size.

  1. will bax documentation be added when click "Open Docs" button for bax?

I have requested @dylanmkennedy to put together documentation which will provide the info once the button is pressed.

  1. and should the "gui guide" (https://github.com/xopt-org/Badger/blob/main/GUI_GUIDE.md) be updated with screenshots of the new gui windows?

I can add a guide for the bax visualizer with images as I have done for the other extensions. The documentation was an oversight and will be added.

  1. minor thing: this PR comes from a branch on slaclab:badger instead of a fork. should we standardize on using PRs from forks since badger is community wide open-source project? (and since only those with permissions can make branches).

As a maintainer of the project I don't see any issues with where a PR comes from, as both are welcome. If you feel strongly we can have these meta discussions with the rest of the group.

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.

4 participants