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

Add __len__ to Schedule in Pulse along with related tests. #4394

Merged
merged 4 commits into from
May 5, 2020

Conversation

neonipun
Copy link
Contributor

@neonipun neonipun commented May 5, 2020

Summary

Issue: #4171

This commit adds a __len__ function to the Schedule class in Pulse, allowing users to obtain the number of instructions present in that Schedule object with len().

Enabling the use of len() on a Schedule object also allows for checking if a schedule is empty. It acts as a replacement for bool() in the following situation - if not Schedule(): print('Empty'), which will now print 'Empty'.

Tests related to the above were written in test/python/pulse/test_schedule.py by asserting that an empty schedule is False and len() equal to zero. Asserting the equality of len() and number of instructions appended to a schedule at each step were also tested.

Details and comments

Although __len__ being based on self.instructions is a bit inefficient, I was assured that it will be mitigated in a new refactor.

Copy link
Contributor

@taalexander taalexander left a comment

Choose a reason for hiding this comment

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

Thank you for your contribution @neonipun! just one small change I suggest.

test/python/pulse/test_schedule.py Outdated Show resolved Hide resolved
@neonipun
Copy link
Contributor Author

neonipun commented May 5, 2020

Thank you for your contribution @neonipun! just one small change I suggest.

Done! I committed your suggested change. Let me know if I missed or messed up a step for this PR to be merged!

@neonipun neonipun requested a review from taalexander May 5, 2020 16:31
Co-authored-by: Thomas Alexander <thomasalexander2718@gmail.com>
@mergify mergify bot merged commit 706f87a into Qiskit:master May 5, 2020
faisaldebouni pushed a commit to faisaldebouni/qiskit-terra that referenced this pull request Aug 5, 2020
* Add __len__ to Schedule in Pulse along with its related tests (Qiskit#4171)

* Update __len__ in Pulse Schedule (Qiskit#4171)

* Update function name to test __len__ of Schedule in Pulse (Qiskit#4171)

Co-authored-by: Thomas Alexander <thomasalexander2718@gmail.com>

Co-authored-by: Thomas Alexander <thomasalexander2718@gmail.com>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
@mtreinish mtreinish added the Changelog: New Feature Include in the "Added" section of the changelog label Aug 6, 2020
@1ucian0 1ucian0 added the mod: pulse Related to the Pulse module label Jan 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Changelog: New Feature Include in the "Added" section of the changelog mod: pulse Related to the Pulse module
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants