-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Implemented writing and reading of instruction duration and unit in qpy #10751
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
base: main
Are you sure you want to change the base?
Implemented writing and reading of instruction duration and unit in qpy #10751
Conversation
Thank you for opening a new pull request. Before your PR can be merged it will first need to pass continuous integration tests and be reviewed. Sometimes the review process can be slow, so please be patient. While you're waiting, please feel free to review other open PRs. While only a subset of people are authorized to approve pull requests for merging, everyone is encouraged to review open pull requests. Doing reviews helps reduce the burden on the core team and helps make the project's code better for everyone. One or more of the the following people are requested to review this:
|
Pull Request Test Coverage Report for Build 6038628513
💛 - Coveralls |
…skit-terra into fixissue10662branch
…d794f3dbd07e90.yaml
@mtreinish @jakelishman The qpy Changing this would break the qpy files created in past versions because then it will have a different structure. Suggestion-Create a FILE_HEADER_V2? But then still the problem will persist. Please help. Thank you |
There's no need to encode an integer as its ASCII character representation - the current one-byte integer encoding of the |
I haven't looked through the PR completely, but on a very quick scan, it looks like you're converting a lot of things to strings that shouldn't be strings; QPY is a binary format, and we should prefer to use denser type-code / numeric encodings wherever possible. For the most part, only things that were already strings should be written as strings, and not even all of those - for example, the |
@jakelishman Thank you so much for clearing my confusion. Also can you please elaborate a little on the idea concerning |
…skit-terra into fixissue10662branch
…d794f3dbd07e90.yaml
@mtreinish I think this pull request is now ready for a review. Thank you |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall this looks good, this is the basic framework of what's needed thanks for doing this. I left a couple inline comments on some improvements we can make to the actual struct format used to encode the duration and unit so that it's a bit more compact.
Besides those comments the only thing missing are tests and format documentation. It'd be good to have tests for the use of unit and duration in https://github.com/Qiskit/qiskit/blob/main/test/python/qpy/test_circuit_load_from_qpy.py to verify we can round trip serialize and deserialize these circuits (to ensure we don't regress). It'll also be good to add backwards compatibility tests to https://github.com/Qiskit/qiskit/blob/main/test/qpy_compat/test_qpy.py to ensure that moving forward we're able to load qpy files from old versions of qiskit that have unit and duration set.
Besides that the format documentation it would just be adding something to: https://github.com/Qiskit/qiskit/blob/main/qiskit/qpy/__init__.py#L148 to describe the new struct format and how it's read.
if duration == 0: | ||
duration = None | ||
# Load Unit | ||
unit = file_obj.read(instruction.unit_size).decode(common.ENCODE) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of using a string like this we can probably get by with a char
. The only supported units can all be represented by single characters:
"f": -15,
"p": -12,
"n": -9,
"u": -6,
"µ": -6,
"m": -3,
"k": 3,
"M": 6,
"G": 9,
"T": 12,
"P": 15,
Then we can just assign a special character for None
probably just use bytes(0) and d
for "dt"
. This will save us some space as we can tightly pack the unit and also it will be faster.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mtreinish Can you please elaborate on why the above map that you have given contains the integers as values since you are saying that these units can be stored as characters. Correct me if I am wrong but did you want to store the integer ( making the qpy file numerically dense) and read these numbers to retrieve character units? If yes then the struct pack should not have a 'c' at the end.
Thank you
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for the delay this fell through the cracks at the end of last year and I missed replying here until now. What I meant is that right now you've got an arbitrary width encoding for the unit field. But instead of doing this you can do a fixed single character encoding of the unit in the actual QPY payload. So you would replace unit_size
and the string decoding by putting a single character at the end of the struct packing. This will be the most efficient representation because it's just a single byte and then it's just about mapping that to the units that go in the instruction object's unit field.
else: | ||
pass |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is unnecessary as it's implicit if you don't have an else statement:
else: | |
pass |
"unit_size", | ||
], | ||
) | ||
CIRCUIT_INSTRUCTION_V3_PACK = "!HHHIIBHqIIII" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't duration normally a float, especially if it has an SI unit? If so I would make this:
CIRCUIT_INSTRUCTION_V3_PACK = "!HHHIIBHqIIII" | |
CIRCUIT_INSTRUCTION_V3_PACK = "!HHHIIBHqIIdI" |
to have duration be a double.
"unit_size", | ||
], | ||
) | ||
CIRCUIT_INSTRUCTION_V3_PACK = "!HHHIIBHqIIII" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Per my comment in circuits.py
I'd probably change this to:
"unit_size", | |
], | |
) | |
CIRCUIT_INSTRUCTION_V3_PACK = "!HHHIIBHqIIII" | |
"unit", | |
], | |
) | |
CIRCUIT_INSTRUCTION_V3_PACK = "!HHHIIBHqIIIc" |
and then handle the static mapping from single characters to value in the reader and writer.
Thanks for working on this @Abhiraj-Shrotriya. Are you going to respond to the requested changes soon or is it okay if I take over this PR? |
@vtomole Yes do intend to fix this issue. Thank you for your interest in helping. If I do however require help, I will contact you here :) I intend to fix this soon. Thank you again |
Hey @Abhiraj-Shrotriya , how's this going? |
@vtomole I asked a question to @mtreinish but did not get a reply in time. So I was not able to know what is expected of the code. That is why this PR is delayed. I am not blaming anyone since it is no one's fault. If you know what is required of the code for this PR, please feel free to take over it. I am sorry for the inconvenience and delay. |
@Abhiraj-Shrotriya Ah, i see. No worries then! Let's wait for @mtreinish. Thanks. |
@vtomole as I said earlier, if you know what is needed of this PR, please go ahead. @mtreinish maybe busy and is not getting time to respond to the queries raised, which is fine. It is of course not a good thing to keep this PR delayed for long. It would be best to resolve it as soon as possible no matter who does it. That is the spirit of open source development and I would like to to keep that spirit alive. I am quite confident that you will be able to fix it :) If, however, you are busy but do understand the work that needs to be done here, you can contact me with the guidance and I will work on it. I would recommend you to just check the latest comments on my code as I think that will help you to have a clear understanding of my situation here. Looking forward to progress :) Thank you |
Summary
Implemented a way of writing and reading duration and unit data of instructions in qpy.
closes #10662
Details and comments
Backward compatible