Qiskit-terra: Pulse Schedule should have a __len__ attribute which returns its number of instructions

Created on 17 Apr 2020  路  6Comments  路  Source: Qiskit/qiskit-terra


What is the expected enhancement?

The pulse schedule should have a length attribute and return the number of instructions contained in the schedule. This will enable checking if a Schedule is empty and statements such as.

if not Schedule(): print('Empty')

A test should be included for this feature.

good first issue help wanted enhancement

Most helpful comment

Hi @neonipun, my apologies for the delay,

  1. For now __len__ should be based on instructions. I agree it is inefficient, however, there is an upcoming refactor that will mitigate this problem.
  2. Testing with a method test__len__ in test/python/pulse/test_schedule.py seems fine.
  3. I do not think we need to add this to ScheduleComponent as this will be deprecated shortly.

All 6 comments

Hello, this looks very doable to me as my first issue for Qiskit! Can I be assigned to this?!
If so let me know what kind of additional help and prerequisites are needed from me.
Looking forward to it :).

Hi Nipun! Great to see around here! Assigned to you. Let me know if I can help.

Hey @taalexander and @1ucian0!
I think I am done with the code but need help to decide on a few things, which are:

  • I found two ways to make __len__ work, which I think are right but correct me if I am wrong. Also, one of those two is a bit efficient since self.instructions gives back a sorted list while self._children is a property that just gives back the tuple that self.instructions uses. Code and some %timeit examples are below, and here is the example code I tried it on. I will finalize on either one of them after I hear from you.
  • Do you think adding an @abstractmethod __len__ to ScheduleComponent interface is a good idea? Then changes to the Instruction class would also be required. Let me know about that or maybe this can be another issue?
  • I need help on where and how a test should be added to the codebase. I saw a couple """Test __len__ method.""" inside 'test', but any more information on that would help me.

Here are the images/code for reference:
image
image

Hey @1ucian0 @taalexander! Any comments/Updates? Should I move forward with a PR of just len(self.instructions) in the Schedule class?

Hi @neonipun, my apologies for the delay,

  1. For now __len__ should be based on instructions. I agree it is inefficient, however, there is an upcoming refactor that will mitigate this problem.
  2. Testing with a method test__len__ in test/python/pulse/test_schedule.py seems fine.
  3. I do not think we need to add this to ScheduleComponent as this will be deprecated shortly.

Fixed via #4394

Was this page helpful?
0 / 5 - 0 ratings

Related issues

nonhermitian picture nonhermitian  路  6Comments

ajavadia picture ajavadia  路  5Comments

chowington picture chowington  路  4Comments

manoelmarques picture manoelmarques  路  4Comments

1ucian0 picture 1ucian0  路  5Comments