Skip to content

Fix parallel notebook - #443

Open
ChristopherMayes wants to merge 5 commits into
mainfrom
update_parallel_notebook
Open

Fix parallel notebook#443
ChristopherMayes wants to merge 5 commits into
mainfrom
update_parallel_notebook

Conversation

@ChristopherMayes

Copy link
Copy Markdown
Collaborator

Summary

This PR fixes two Pydantic warnings that appeared when running Xopt on Python 3.14, and adds the missing gest-api dependency to the conda environment.

Changes

  • Replaced the deprecated from pydantic.v1.json import custom_pydantic_encoder import in xopt/pydantic.py with a small, self-contained encoder. This removes the repeated "Core Pydantic V1 functionality isn't compatible with Python 3.14 or greater" warning while preserving the original encoding behavior.
  • Declared _loaded_population and _toolbox as PrivateAttr in xopt/generators/ga/cnsga.py. These attributes were previously set in __init__ without being declared, which caused Pydantic to emit PydanticSerializationUnexpectedValue warnings during serialization.
  • Added gest-api to environment.yml so the dependency is installed with the conda environment.

Testing

  • Restarted the notebook kernel and re-ran docs/examples/basic/xopt_parallel.ipynb. The previously affected cells now run cleanly with no warnings.
  • Verified in a fresh interpreter that importing xopt.pydantic no longer raises the Pydantic v1 warning and that the custom encoder correctly serializes NumPy values.

@codecov

codecov Bot commented Jul 6, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 36.36364% with 7 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
xopt/pydantic.py 12.50% 7 Missing ⚠️

📢 Thoughts on this report? Let us know!

@ChristopherMayes
ChristopherMayes marked this pull request as ready for review July 7, 2026 20:40

@electronsandstuff electronsandstuff 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.

Looks ok, we should eventually modernize how datatypes like np.ndarray and torch.Tensor are serialized instead of integrating pydantic v1 things here, but I think it gets it working for the meantime. I will put in an issue about it to remember.

Also, run pre-commit run --all first.

)
_children: List[Dict] = PrivateAttr([])
_offspring: Optional[pd.DataFrame] = PrivateAttr(None)
_loaded_population: Optional[pd.DataFrame] = PrivateAttr(None)

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.

Use more modern syntax. Also suggest for other fields in this file.

Suggested change
_loaded_population: Optional[pd.DataFrame] = PrivateAttr(None)
_loaded_population: pd.DataFrame | None = PrivateAttr(None)

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.

2 participants