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

[RTM] Added the commit ID + version to sol #806

Merged
merged 4 commits into from
Nov 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions bioptim/examples/getting_started/pendulum.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,12 @@ def main():
sol.print_cost()
sol.animate(n_frames=100)

# # --- Save the solution --- #
# import pickle
# with open("pendulum.pkl", "wb") as file:
# del sol.ocp
# pickle.dump(sol, file)


if __name__ == "__main__":
main()
21 changes: 21 additions & 0 deletions bioptim/optimization/solution/solution.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from scipy.interpolate import interp1d
from casadi import vertcat, DM, Function
from matplotlib import pyplot as plt
import git

from ...limits.objective_functions import ObjectiveFcn
from ...limits.path_conditions import InitialGuess, InitialGuessList
Expand Down Expand Up @@ -233,6 +234,26 @@ def __init__(
self._stochastic_variables["unscaled"],
)

@property
def bioptim_version_used(self) -> dict:
"""
Returns info on the bioptim version used to generate the results for future reference.
"""
repo = git.Repo(search_parent_directories=True)
commit_id = str(repo.commit())
branch = str(repo.active_branch)
tag = repo.git.describe("--tags")
bioptim_version = repo.git.version_info
date = repo.git.log("-1", "--format=%cd")
version_dic = {
"commit_id": commit_id,
"date": date,
"branch": branch,
"tag": tag,
"bioptim_version": bioptim_version,
}
return version_dic

@classmethod
def from_dict(cls, ocp, _sol: dict):
"""
Expand Down
1 change: 1 addition & 0 deletions environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ dependencies:
- bioviz
- python-graphviz
- pyqtgraph
- gitpython
10 changes: 10 additions & 0 deletions tests/shard3/test_global_getting_started.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
Node,
ControlType,
PhaseDynamics,
__version__,
)

from tests.utils import TestUtils
Expand Down Expand Up @@ -116,6 +117,15 @@ def test_pendulum(ode_solver, use_sx, n_threads, phase_dynamics):

sol = ocp.solve()

# Test the bioptim version feature (this is the only test)
version_dic = sol.bioptim_version_used
print(version_dic["commit_id"])
print(version_dic["date"])
print(version_dic["branch"])
np.testing.assert_equal(version_dic["tag"].split("-")[0], f"Release_{__version__}")
print(version_dic["bioptim_version"])
print(sol.bioptim_version_used)

# Check objective function value
f = np.array(sol.cost)
np.testing.assert_equal(f.shape, (1, 1))
Expand Down