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

Time vector #54

Open
jtheinen opened this issue Jul 12, 2022 · 3 comments
Open

Time vector #54

jtheinen opened this issue Jul 12, 2022 · 3 comments

Comments

@jtheinen
Copy link
Contributor

Is there an option to find the time vector to plot with the position solution? I have found problem.solution.tau, which always has a range from 0-1.

problem.solution.time just gives end time. Would multiplying tau by end time give a valid time vector?

@brocksam
Copy link
Owner

There is, but it's the incredibly unintuitive and bad-practice problem.solution._time_.

This highlights that the API here definitely needs changing and making more intuitive!

I would maybe suggest making problem.solution.time return the array of discretised time in normal units, problem.solution.initial_time and problem.solution.final_time would return the endpoints of the time array, and problem.solution.normalized_time return what is currently problem.solution.tau.

Part of the reason for the current behaviour is that we have problem.solution.state, problem.solution.control etc return the values of the actual decision variables used in the NLP subproblem, so problem.solution.time currently does the same for the time variables. I would probably need to think a bit more about my above suggestion because it does clobber this nice consistency that we currently have for the NLP decision variables.

What are your thoughts? What would you find most intuitive?

@jtheinen
Copy link
Contributor Author

I see that there are many variables stored double, such as:
._u = .control
._y = .state
._Tf = .final_time
and many more. Is there a reason for this? Do the variables starting with _ have something in common?

The reason why I didn't find problem.solution.time is because python does not give a suggestion to this option when I use a tab to check the options.

If changing the .time would clobber the consistency, would adding a .time_discretised maybe be an intuitive option?

@brocksam
Copy link
Owner

In Python, attributes (and variables) prepended with an underscore (e.g. ._u) are used to indicate "protected" attributes, i.e. ones that aren't part of a class's public API and should not be mutated by a user. The reason for duplication is so that Pycollo can internally mutate the protected versions and then the public versions (e.g. .control) are actually properties without setters, which means that the user can't accidentally overwrite these.

I suspect that the autocomplete didn't work was because problem.solution._time_ is technically protected. Replacing with a renamed public attribute should mean that you get autocompletion here.

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

No branches or pull requests

2 participants