-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Remove marshmallow from result/ and requirements #4030
Conversation
1734e57
to
dd3a458
Compare
This commit finishes the process of removing marshmallow from terra. It rebuilds the result class as bare python classes or SimpleNamespace subclasses (for classes that allow arbitrary fields). After the result class has been converted there is nothing using marshmallow or all the support code in qiskit/validation. So this continues the removal process by removing those and removing marshmallow and marshmallow-polyfield from the requirements list. This commit depends on Qiskit#4027 and Qiskit#4016 and can't be merged without those.
dd3a458
to
c542e11
Compare
Now Qiskit#4016 has merged this is unblocked on the terra side. This commit makes some changes and fixes issues found from testing.
While both Result and ExperimentResult take arbitrary key value date via the kwargs using SimpleNamespace as a parent class like in other places is not a good fit. This is because the signatures for these classes are signfiicantly different from the base SimpleNamespace. So when Results are pickled via async execution (like in the BasicAer and Aer providers) this causes it to either fail or if a custom __reduce__ method is defined it to not work as expected. This commit pivots the new classes to be bare objects that store the arbitrary kwargs as a private dictionary attribute. Attribute access for these fields are implemented via a custom __getattr__.
The results tests were using a raw Marshmallow.Obj object in the tests to construct the Result qobj headers and relying on the schema to convert it to a QobjExperimentHeader when it was passed to the Result constructor. When marshmallow was removed this was updated to a dict() since that was the closest mapping, but that ignored the transform marshmallow would do. This commit corrects that oversight and constructs QobjExperimentHeader object where dict was incorrectly used before. This is probably what the original tests should have done for clarity anyway.
This is still on hold because this will break the ibmq-provider until Qiskit/qiskit-ibmq-provider#553 is fixed. Once that's done we can safely merge this. (this is also what's blocking the docs builds because the ibmq provider fails to import with this applied) |
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.
A couple minor comments but overall looks good!
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.
LGTM!
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 looks fine. The only question I have is do we make it clear that to_dict
and from_dict
are designed to serialize/deserialize JSON? It might be possible to the wrong idea from the function name alone.
Honestly, I'm not sure if that's a concern for this PR. Those methods are there for backwards compatibility with marshmallow only, if I could I would have just removed them. Ideally if I were to add json support to these classes I would have done it with
mostly because the marshmallow based classes had poor documentation and if you were going to construct a Results object using the constructors it relied on three layers of nested class construction so |
The |
* Remove marshmallow from result/ and requirements This commit finishes the process of removing marshmallow from terra. It rebuilds the result class as bare python classes or SimpleNamespace subclasses (for classes that allow arbitrary fields). After the result class has been converted there is nothing using marshmallow or all the support code in qiskit/validation. So this continues the removal process by removing those and removing marshmallow and marshmallow-polyfield from the requirements list. This commit depends on Qiskit#4027 and Qiskit#4016 and can't be merged without those. * Fixes from testing Now Qiskit#4016 has merged this is unblocked on the terra side. This commit makes some changes and fixes issues found from testing. * Abandon SimpleNamespace for Result and ExperimentResult While both Result and ExperimentResult take arbitrary key value date via the kwargs using SimpleNamespace as a parent class like in other places is not a good fit. This is because the signatures for these classes are signfiicantly different from the base SimpleNamespace. So when Results are pickled via async execution (like in the BasicAer and Aer providers) this causes it to either fail or if a custom __reduce__ method is defined it to not work as expected. This commit pivots the new classes to be bare objects that store the arbitrary kwargs as a private dictionary attribute. Attribute access for these fields are implemented via a custom __getattr__. * Use correct header type in tests The results tests were using a raw Marshmallow.Obj object in the tests to construct the Result qobj headers and relying on the schema to convert it to a QobjExperimentHeader when it was passed to the Result constructor. When marshmallow was removed this was updated to a dict() since that was the closest mapping, but that ignored the transform marshmallow would do. This commit corrects that oversight and constructs QobjExperimentHeader object where dict was incorrectly used before. This is probably what the original tests should have done for clarity anyway. * Fix lint * Fix docstring * Add release notes * Fix docs issues from review comments Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
In the removal of marshmallow from the Result class (and terra as a whole) in Qiskit#4030 the descriptive repr for the objects was lost. This is inconvenient because the default representation for an object is just the class name and the memory address of the object. This commit adds back a string representation of the objects which were missing by adding a __repr__ method to the classes.
* Add back repr for Result and related classes In the removal of marshmallow from the Result class (and terra as a whole) in #4030 the descriptive repr for the objects was lost. This is inconvenient because the default representation for an object is just the class name and the memory address of the object. This commit adds back a string representation of the objects which were missing by adding a __repr__ method to the classes. * Fix lint * Add test * Fix lint Co-authored-by: Luciano Bello <luciano.bello@ibm.com>
Summary
This commit finishes the process of removing marshmallow from terra. It
rebuilds the result class as bare python classes or SimpleNamespace
subclasses (for classes that allow arbitrary fields). After the result
class has been converted there is nothing using marshmallow or all the
support code in qiskit/validation. So this continues the removal process
by removing those and removing marshmallow and marshmallow-polyfield
from the requirements list.
Details and comments
This commit depends on #4027 and #4016 and can't be merged (or tested) without
those applied.