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

Hack in SimpleNamespace-like functionality to Options #7347

Merged
merged 3 commits into from
Dec 2, 2021

Conversation

jakelishman
Copy link
Member

@jakelishman jakelishman commented Dec 2, 2021

Summary

This is an awful hack to support various SimpleNamespace-like operations
that qiskit-experiments are using. We need to transition downstream
packages to the new Options API, but in the meantime, this makes the
Options class behave as much like a SimpleNamespace as it can, while
still keeping the new instance attributes and methods.

Details and comments

This passes the qiskit-experiments tests on my machine. The real problem is how qiskit-experiments accesses options.__dict__, so this involves some terrible behaviour to make that work as expected.

It's an absolutely horrific hack, and I regret ever learning Python.

@eggerdj - this passes the tests on my machine, but could you check it does everything you need as well?

This is an awful hack to support various SimpleNamespace-like operations
that qiskit-dynamics are using.  We need to transition downstream
packages to the new Options API, but in the meantime, this makes the
Options class behave as much like a SimpleNamespace as it can, while
still keeping the new instance attributes and methods.
@jakelishman jakelishman requested review from chriseclectic, jyu00 and a team as code owners December 2, 2021 19:44
@mtreinish mtreinish added Changelog: None Do not include in changelog priority: high labels Dec 2, 2021
@mtreinish mtreinish added this to the 0.19 milestone Dec 2, 2021
mtreinish
mtreinish previously approved these changes Dec 2, 2021
Copy link
Member

@mtreinish mtreinish left a comment

Choose a reason for hiding this comment

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

This LGTM, thanks for figuring all these hairy things out. Before we tag it automerge and put it in the merge queue though we should verify it works for qiskit-experiments. @eggerdj @nkanazawa1989 @chriseclectic if you could test this that would be great.

@coveralls
Copy link

coveralls commented Dec 2, 2021

Pull Request Test Coverage Report for Build 1532598027

  • 16 of 16 (100.0%) changed or added relevant lines in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.003%) to 83.089%

Totals Coverage Status
Change from base Build 1532511696: 0.003%
Covered Lines: 51444
Relevant Lines: 61914

💛 - Coveralls

chriseclectic
chriseclectic previously approved these changes Dec 2, 2021
Copy link
Member

@chriseclectic chriseclectic left a comment

Choose a reason for hiding this comment

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

I ran qiskit-experiments tests locally with this branch and had no failures

I was surprised at how little pylint complained about the actual
implementation, but it complains about the usage.

This could conceivably be called a pylint bug; because we override
`__setattr__`, pylint should perhaps recognise that general attribute
setting might be allowed.
@jakelishman jakelishman dismissed stale reviews from chriseclectic and mtreinish via d6ab60f December 2, 2021 21:14
@jakelishman
Copy link
Member Author

jakelishman commented Dec 2, 2021

It's possible that qiskit-experiments' CI may fail after this on the linting stage with pylint's assigning-non-slot. If so, you may want to consider just temporarily suppressing that warning; to some degree, it's kind of a pylint bug, because I overrode __setattr__ to make the assignments work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Changelog: None Do not include in changelog priority: high
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants