Skip to content

Modernize nsga2 output_dir#445

Draft
ChristopherMayes wants to merge 1 commit into
mainfrom
modernize_nsga2_output_dir
Draft

Modernize nsga2 output_dir#445
ChristopherMayes wants to merge 1 commit into
mainfrom
modernize_nsga2_output_dir

Conversation

@ChristopherMayes

Copy link
Copy Markdown
Collaborator

Summary

This PR modernizes the output_dir option of NSGA2Generator so that it accepts more flexible input while still serializing cleanly as a string.

Changes

  • The output_dir field now accepts any os.PathLike value, such as a pathlib.Path, in addition to a plain string.
  • Environment variables such as $SCRATCH and the user home shortcut ~ are now expanded when output_dir is set, so paths like $SCRATCH/run1 resolve to their intended locations.
  • A new _expand_output_dir field validator performs this normalization by converting the input with os.fspath and expanding it with os.path.expandvars and os.path.expanduser, while leaving None unchanged.
  • The field description and the class docstring were updated to document the accepted input types and the expansion behavior.

Testing

  • I verified that pathlib.Path inputs, $VAR environment variables, ~ home expansion, and None are all handled correctly.
  • The full NSGA2Generator test suite in xopt/tests/generators/ga/test_nsga2.py continues to pass (32 tests).

Acknowledgment

These changes were developed with the assistance of GitHub Copilot.

@roussel-ryan

Copy link
Copy Markdown
Collaborator

Pull in main to fix the testing issues here

@electronsandstuff

Copy link
Copy Markdown
Collaborator

I can check out more later, but one point for thought: my preference is to keep the field as the raw value containing environment variables and home character and convert on usage (possibly through an .output_dir_expanded property). You can still convert from pathlib.Path to str.

That way the object reflects user input and can be serialized retaining their original data with environment variables. This is important, for instance, for the checkpointing feature of NSGA2Generator where the class is dumped. It would allow users to restart on different platforms as long as the env. variables match.

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.

3 participants