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

Timestamped experiments #2616

Merged
merged 51 commits into from
Jun 16, 2023
Merged

Conversation

brosaplanella
Copy link
Member

@brosaplanella brosaplanella commented Jan 25, 2023

Description

Enable functionality to "timestamp" experiment steps so they only get triggered at that date & time. At the moment the timestamps can be defined as:

  • "Day D HH:MM:SS"
  • "YYYY-MM-DD HH:MM:SS"

I am using the datetime package so the flexibility with the format (e.g. padding zeros) is that of datetime.

Fixes #1839

Type of change

Please add a line in the relevant section of CHANGELOG.md to document the change (include PR #) - note reverse order of PR #s. If necessary, also add to the list of breaking changes.

  • New feature (non-breaking change which adds functionality)
  • Optimization (back-end change that speeds up the code)
  • Bug fix (non-breaking change which fixes an issue)

Key checklist:

  • No style issues: $ flake8
  • All tests pass: $ python run-tests.py --unit
  • The documentation builds: $ cd docs and then $ make clean; make html

You can run all three at once, using $ python run-tests.py --quick.

Further checks:

  • Code is commented, particularly in hard-to-understand areas
  • Tests added that prove fix is effective or that feature works

@brosaplanella brosaplanella marked this pull request as draft January 25, 2023 12:37
@codecov
Copy link

codecov bot commented Jan 25, 2023

Codecov Report

Patch coverage: 100.00% and no project coverage change.

Comparison is base (997b758) 99.71% compared to head (f641985) 99.71%.

Additional details and impacted files
@@           Coverage Diff            @@
##           develop    #2616   +/-   ##
========================================
  Coverage    99.71%   99.71%           
========================================
  Files          248      248           
  Lines        18683    18736   +53     
========================================
+ Hits         18629    18682   +53     
  Misses          54       54           
Impacted Files Coverage Δ
pybamm/experiment/experiment.py 100.00% <100.00%> (ø)
pybamm/simulation.py 100.00% <100.00%> (ø)
pybamm/solvers/solution.py 100.00% <100.00%> (ø)
pybamm/step/_steps_util.py 100.00% <100.00%> (ø)

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

@brosaplanella brosaplanella marked this pull request as ready for review April 20, 2023 08:53
@brosaplanella brosaplanella requested a review from rtimms April 28, 2023 09:36
@brosaplanella
Copy link
Member Author

@tinosulzer, following #2960, do we want the tags to be in the string or just as an option in _Step? I guess the latter, but just wanted to double check before undoing some of the changes.

@valentinsulzer
Copy link
Member

I think just an option. I made it so you can pass a single tag or a list of tags

@brosaplanella
Copy link
Member Author

I think this is ready to review

@@ -256,6 +257,23 @@ def set_up_and_parameterise_model_for_experiment(self):
)
self.experiment_unique_steps_to_model[repr(op)] = parameterised_model

# Set up rest model if experiment has timestamps
Copy link
Contributor

Choose a reason for hiding this comment

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

How come we need a separate model for this? Can't we use the current model and set the current to be zero like we do for a rest?

Copy link
Member Author

Choose a reason for hiding this comment

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

I thought it would be more robust to have a separate model for rest, in case the user only has, for example, power driven steps (unlikely, I know).

Copy link
Contributor

Choose a reason for hiding this comment

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

ah ok, yeah, makes sense

Copy link
Contributor

@rtimms rtimms left a comment

Choose a reason for hiding this comment

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

looks good, thanks @brosaplanella !

Copy link
Member

@valentinsulzer valentinsulzer left a comment

Choose a reason for hiding this comment

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

Functionality looks good. In terms of API I am wondering whether timestamp is the best name (what about start_time?). Also wondering whether we should just always require a datetime object, instead of providing support for some (but not all) datetime formats. It's not too much work for someone to write their own function to create a datetime object from a string.

@brosaplanella
Copy link
Member Author

Functionality looks good. In terms of API I am wondering whether timestamp is the best name (what about start_time?).

We could call it start_time (I agree, I think it is clearer) and then the other variables could be next_start_time and end_time. That would make everything clearer I think.

Also wondering whether we should just always require a datetime object, instead of providing support for some (but not all) datetime formats. It's not too much work for someone to write their own function to create a datetime object from a string.

Currently what we do is process the string by using datetime.strptime (https://www.digitalocean.com/community/tutorials/python-string-to-datetime-strptime) so we could push this on the user's side. In any case, if later we want to support string it is way easier to add it at a later stage than include it now and remove it later.

Will make these changes and then I will merge.

@valentinsulzer valentinsulzer merged commit c2ca937 into develop Jun 16, 2023
@valentinsulzer valentinsulzer deleted the issue-1839-time-based-experiments branch June 16, 2023 22:49
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.

Time-based events in experiments
3 participants