Use struct for NodeDurations in both ALAP and ASAP Scheduling Passes#15276
Use struct for NodeDurations in both ALAP and ASAP Scheduling Passes#15276alexanderivrii merged 14 commits intoQiskit:mainfrom
NodeDurations in both ALAP and ASAP Scheduling Passes#15276Conversation
- Add initial ``NodeDurations`` struct.
This commit is incomplete and most features will stop working.
- Add magic methods to `PyNodeDurations`.
- Add `items` method.
00bd40d to
90d3049
Compare
- Add an extra field to `PyNodeDurations` to keep mapping between indices and original dag nodes. - Add methods to update `NodeDurations` using mappings with a subset of the current nodes or new mappings as long as the user has the original dag. - Reverted some changes inside of Context Aware DD.
|
Does this PR need a release note? Although it is a very internal change, the property slot that stores it is mentioned in documentation, but its type is never mentioned explicitly. |
|
One or more of the following people are relevant to this code:
|
NodeDurations in both ALAP and ASAP Scheduling PassesNodeDurations in both ALAP and ASAP Scheduling Passes
alexanderivrii
left a comment
There was a problem hiding this comment.
Thanks Ray, I have left a few questions (in particular there is something about the equality of PyNodeDurations that I do not quite understand).
Co-authored-by: Alexander Ivrii <alexi@il.ibm.com>
alexanderivrii
left a comment
There was a problem hiding this comment.
Ray, thanks for explanations and quick updates. Based on Matthew's comment that node durations should only be used for look-ups by node id, I think that using HashMap to represent node durations and iterating over DAG's Delay nodes in dynamical decoupling both make sense.
This PR does change the type of property_set["node_duration"] from dict to class 'qiskit._accelerate.scheduling.NodeDurations, however I don't think this poses a problem from the backward compatibility standpoint.
As we discussed during the meeting today, we need to preserve backward compatibility as much as possible (in particular we need to go back to using IndexMap).
83127ae to
ae27bf5
Compare
- An oversight allowed an error variant to precompute itself even if the result was `Ok` via `ok_or`. Replaced it with `ok_or_else`. - Fix formatting issue.
|
@alexanderivrii I reverted the changes back to using |
alexanderivrii
left a comment
There was a problem hiding this comment.
Thanks for the updates, Ray!
I did not fully understand where the performance regression that you mentioned was coming from, is it from using HashMap instead of IndexMap?
Overall this looks very nice to me. I believe to fully look a Python dict, you should also implement the __iter__ magic method, what do you think?
Otherwise, it's ready to merge.
Oh, I forgot to explain it but it was part of the commit message of the last commit: The regression I introduced simply called Python's
I might be wrong but because the struct is specified to be a Update: it in fact does not make it iterable... |
|
Added iteration methods ( |
alexanderivrii
left a comment
There was a problem hiding this comment.
Thanks for the explanations, and thanks for remembering to also implement keys and values. After experimenting with the code, the NodeDurations data structure now looks like a dict and quacks like a dict, therefore for all practical purposes it's backwards compatible.
Summary
The following commits introduce a PyO3 class,
NodeDurations, that represents a mapping betweenDAGOpNodeinstances and their duration values in either units ofdtorseconds.The main purpose of this structure is to avoid the costly conversion from
PyDicttoHashMapand back in each instance.The following PR also restructures the directories for scheduling passes to allow this struct to live in its own file under a common directory.
Details and comments