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 sample_every argument for trange. #1384

Merged
merged 1 commit into from
Jun 16, 2018
Merged

Conversation

jgosmann
Copy link
Collaborator

@jgosmann jgosmann commented Nov 17, 2017

Motivation and context:
This allows to create matching tranges for probes with a sample_every parameter that is not a multiple of the simulator timestep.

Fixes #1368.

Interactions with other PRs:
none

How has this been tested?
added a test

How long should this take to review?

  • Quick (less than 40 lines changed or changes are straightforward)

Types of changes:

  • Bug fix (non-breaking change which fixes an issue)?
  • New feature (non-breaking change which adds functionality)?

Checklist:

  • I have read the CONTRIBUTING.rst document.
  • I have updated the documentation accordingly.
  • I have included a changelog entry.
  • I have added tests to cover my changes.
  • I have run the test suite locally and all tests passed.

Copy link
Member

@tbekolay tbekolay left a comment

Choose a reason for hiding this comment

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

So, the original intention of dt was to do essentially what this PR does with the new sample_every kwarg. It should not have been possible for trange to return timesteps that were not actually executed by the simulator, so I would consider this PR an important bugfix rather than a new feature.

Because of that, I added some commits to essentially deprecate the dt argument in favor of the sample_every argument. Let me know if this makes sense @jgosmann and @Seanny123 and if so I'll rewrite the changelog message and merge.

@Seanny123
Copy link
Contributor

Still LGTM.

@@ -347,5 +345,5 @@ def test_sample_every_trange(Simulator, sample_every):
with Simulator(model) as sim:
sim.run(0.01)

assert_almost_equal(
assert np.allclose(
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Out of curiosity, why do you prefer np.allclose over assert_almost_equal?

Copy link
Member

Choose a reason for hiding this comment

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

When an assertion is false, you get a traceback at that point. I'd rather that point be in the test itself than in a function called by the test, as I will often debug with pytest --pdb and it's a slight annoyance to move up the call stack to find the test frame.

@jgosmann
Copy link
Collaborator Author

I don't know whether I missed the notification or I didn't get one for the approval comment, but the changes look good to me.

This creates matching tranges for probes with a sample_every
parameter that is not a multiple of the simulator timestep.

Note that this essentially replaces the old dt argument.
For backwards compatibility reasons, it still exists
as a keyword argument, but will warn and use the logic
of sample_every.

Fixes #1368.
@tbekolay tbekolay merged commit ddb4a19 into master Jun 16, 2018
@tbekolay tbekolay deleted the trange-sample-every branch June 16, 2018 01:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

sample_every and trange(dt=sample_every) mismatch
3 participants