Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement Parameters as Pydantic BaseModels and improve exploration diagnostics #120

Merged
merged 78 commits into from
Dec 22, 2023

Conversation

AngelFP
Copy link
Member

@AngelFP AngelFP commented Oct 10, 2023

This PR implements a solution to the lack of parameter metadata in the history file. As proposed by @ax3l a couple of months ago, this solution is based on taking advantage of Pydantic's BaseModel to be able to serialize and save the exploration parameters to a JSON file. In this way, we can later recover these parameters and all their attributes for analyzing the output of an exploration.

Main changes

  • All Parameters (i.e., varying parameters, objectives, analyzed parameters, etc.) are now Pydantic BaseModels. This allows for a few nice things:

    • The inputs from the user are now automatically validated, and we can easily define custom validators for more complex attributes like the dtype of the parameters.
    • We can serialize the optimization parameters to JSON and save them to a file that can be read by post-processing tools/scripts. With this, it is no longer needed to add information to the libE history file about which parameters were inputs, objectives, etc. The complete information of these parameters is now contained in the JSON file.
  • A new ExplorationDiagnostics class has been implemented that allows for easily analyzing the output of an optimas Exploration. This class takes care of reading and processing the history file as well as the JSON file so that the user does not need to interact with them directly. The ExplorationDiagnostics replaces the old PostProcOptimization class, which was by now outdated (it was the last remnant of libE_opt).

  • Added new section to documentation with example usage of ExplorationDiagnostics. This requires installing mpi4py, for which the RTD environment had to be changed to mamba.

Notes

Example use of ExplorationDiagnostics

Since all information about the history and the parameters is included in the diagnostics, we can now use it for fully automated post-processing, for example:

from optimas.diagnostics import ExplorationDiagnostics

diags = ExplorationDiagnostics("/path/to/exploration")

fig, ax = plt.subplots()
vps = diags.varying_parameters
df = diags.history
f1 = diags.objectives[0]
ax.axvline(vps[0].lower_bound)
ax.axvline(vps[0].upper_bound)
ax.set_xlabel(vps[0].name)
ax.axhline(vps[1].lower_bound)
ax.axhline(vps[1].upper_bound)
ax.set_ylabel(vps[1].name)
ax.scatter(df[vps[0].name], df[vps[1].name], c=df[f1.name])

search_space

@AngelFP
Copy link
Member Author

AngelFP commented Oct 11, 2023

@delaossa this should fix #80 (which #81 was addressing) because now you no longer need to import the original optimas script for post-processing.

@ax3l ax3l added the enhancement New feature or request label Oct 13, 2023
Copy link
Collaborator

@ax3l ax3l left a comment

Choose a reason for hiding this comment

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

This is very cool, thank you! 🎉

Do you want to add a bit of docs on the JSON file to the manual to finalize?

@AngelFP AngelFP merged commit fdeac66 into main Dec 22, 2023
8 checks passed
@AngelFP AngelFP deleted the pydantic branch December 22, 2023 09:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants