Skip to content

refactoring + add getters and setters #249

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

Merged
merged 5 commits into from
Aug 18, 2024
Merged

refactoring + add getters and setters #249

merged 5 commits into from
Aug 18, 2024

Conversation

ocots
Copy link
Member

@ocots ocots commented Aug 14, 2024

I have made some modifications. I have added getters for a solution but I have also renamed getters for a model. It is clearer for me with the prefix get_. I have thus updated the Project.toml.

I will take a look at #144 (comment).

I have also restructured the code to simplify in the future documentation, the organisation of the presentation the model, the solution and their setters and getters.

@PierreMartinon @jbcaillau Please comment.

@ocots ocots linked an issue Aug 14, 2024 that may be closed by this pull request
@github-actions github-actions bot requested a review from jbcaillau August 14, 2024 11:54
@ocots ocots marked this pull request as draft August 14, 2024 11:54
@ocots ocots requested review from PierreMartinon and jbcaillau and removed request for jbcaillau August 14, 2024 15:51
@ocots ocots marked this pull request as ready for review August 15, 2024 11:10
@ocots ocots marked this pull request as draft August 15, 2024 11:17
@ocots
Copy link
Member Author

ocots commented Aug 15, 2024

@jbcaillau We should make the v0.12.5 release before merging this PR.

@jbcaillau
Copy link
Member

@jbcaillau We should make the v0.12.5 release before merging this PR.

👍🏽 go ahead!

@ocots ocots marked this pull request as ready for review August 15, 2024 11:39
@ocots
Copy link
Member Author

ocots commented Aug 15, 2024

@jbcaillau We should make the v0.12.5 release before merging this PR.

👍🏽 go ahead!

Done!

@ocots ocots marked this pull request as draft August 15, 2024 11:55
@ocots
Copy link
Member Author

ocots commented Aug 15, 2024

In the future documentation, if we use the getters, then, we will have something like:

sol = solve(ocp)
x = get_state(sol)

Do we prefer:

sol = solve(ocp)
x = state(sol)

Here is the list of getters:

# OptimalControlModel

get_dim_control_constraints
get_dim_state_constraints
get_dim_mixed_constraints
get_dim_path_constraints
get_dim_boundary_constraints
get_dim_variable_constraints
get_dim_control_range
get_dim_state_range,
get_dim_variable_range
get_model_expression
get_initial_time
get_initial_time_name
get_final_time
get_final_time_name
get_time_name
get_control_dimension
get_control_components_names
get_control_name
get_state_dimension
get_state_components_names
get_state_name
get_variable_dimension
get_variable_components_names
get_variable_name
get_lagrange
get_mayer
get_criterion
get_dynamics

# in the previous getters, some are common with OptimalControlSolution

# OptimalControlSolution

get_times
get_control
get_state, get_variable
get_costate
get_objective
get_iterations
get_stopping
get_message
get_success
get_infos

@ocots
Copy link
Member Author

ocots commented Aug 15, 2024

The most used by the user I guess are those on an OptimalControlSolution. Maybe, we can keep _get for those on an OptimalControlModel and for the others:

times    # or time_grid since times is very common
control # this will be used to define also some control law. Will be there any conflict?
state
variable
costate
objective
iterations
stopping
message
success
infos

If we have that, not clear to write something like: success = success(sol) or state = state(sol).

Usually we would write:

times = time_grid(sol)
u = control(sol)
x = state(sol)
v = variable(sol)
p = costate(sol)
obj = objective(sol)
Niter = iterations(sol)
stopping # ??
message # ??
success # ??
infos # ??

@ocots
Copy link
Member Author

ocots commented Aug 15, 2024

@PierreMartinon @jbcaillau Please make a comment.

@jbcaillau
Copy link
Member

@PierreMartinon @jbcaillau Please make a comment.

Thanks @ocots I like this best:

times = time_grid(sol)
u = control(sol)
x = state(sol)
v = variable(sol)
p = costate(sol)
obj = objective(sol)
Niter = iterations(sol)
...
  • actually, does it make sense (and is it a good / common practice in Julia) to use field(sol) for the getter, and field!(sol, val) for the setter?
  • in the end, if there are not clear choice, we can also keep the two with aliases (state = get_state, etc.)

@ocots
Copy link
Member Author

ocots commented Aug 16, 2024

If you have several types, getters are a good idea. We just have one but with getters we can make some checkings, some computations, etc.

Maybe we can have both as you said with aliases.

We can make the aliases inside OptimalControl.jl and let in CTBase.jl the functiins with get_.

@ocots
Copy link
Member Author

ocots commented Aug 17, 2024

@jbcaillau @PierreMartinon I will rename some getters to have something like

times = time_grid(sol)
u = control(sol)
x = state(sol)
v = variable(sol)
p = costate(sol)
obj = objective(sol)
Niter = iterations(sol)
...

@ocots
Copy link
Member Author

ocots commented Aug 18, 2024

I have removed all the prefixes get_.

I make a push soon.

@ocots ocots marked this pull request as ready for review August 18, 2024 11:19
@ocots ocots merged commit b8610ae into main Aug 18, 2024
9 checks passed
@ocots ocots deleted the 244-getters branch August 18, 2024 11:28
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.

Getters
2 participants