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

plugin convenience function for getting the entry point object #9275

Merged
merged 10 commits into from
Apr 18, 2023

Conversation

1ucian0
Copy link
Member

@1ucian0 1ucian0 commented Dec 10, 2022

I was playing with staged pass managers when a wild plugin appears!

from qiskit.transpiler.preset_passmanagers import generate_preset_pass_manager
from qiskit.transpiler.preset_passmanagers.plugin import list_stage_plugins

for s in generate_preset_pass_manager(1).stages:
    print(s, list_stage_plugins(s))
init []
layout []
routing ['basic', 'lookahead', 'none', 'sabre', 'stochastic']
translation ['ibm_dynamic_circuits']
optimization []
scheduling []

I never saw ibm_dynamic_circuits before so I was curious to understand where it was coming from. I can imagine this might happen more and more often as the Qiskit plugin ecosystem grows. So I created entry_point_obj to get extra information about it:

from qiskit.transpiler.preset_passmanagers.plugin import entry_point_obj
entry_point_obj('translation', 'ibm_dynamic_circuits')
<qiskit_ibm_provider.transpiler.plugin.IBMTranslationPlugin at 0xdeadbeef>

In this way, you can not only know from where the plugin is coming, but also check the docstrings and get more help on what it does.

@1ucian0 1ucian0 requested a review from a team as a code owner December 10, 2022 21:38
@qiskit-bot
Copy link
Collaborator

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:

  • @Qiskit/terra-core

@coveralls
Copy link

coveralls commented Dec 10, 2022

Pull Request Test Coverage Report for Build 4490507190

  • 8 of 8 (100.0%) changed or added relevant lines in 1 file are covered.
  • 6 unchanged lines in 4 files lost coverage.
  • Overall coverage decreased (-0.004%) to 85.39%

Files with Coverage Reduction New Missed Lines %
qiskit/circuit/tools/pi_check.py 1 91.23%
qiskit/transpiler/passes/synthesis/unitary_synthesis.py 1 94.64%
qiskit/visualization/circuit/text.py 1 94.96%
qiskit/pulse/library/waveform.py 3 91.67%
Totals Coverage Status
Change from base Build 4474816332: -0.004%
Covered Lines: 68022
Relevant Lines: 79660

💛 - Coveralls

Copy link
Contributor

@taalexander taalexander left a comment

Choose a reason for hiding this comment

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

This seems reasonable, would it also make sense to return a dict of all possibilities?

@1ucian0
Copy link
Member Author

1ucian0 commented Feb 13, 2023

You mean something like this?

>>> entry_point_obj_by_stage('routing')
{'basic': <obj>, 'lookahead': <obj>, ...}

Copy link
Member

@jakelishman jakelishman left a comment

Choose a reason for hiding this comment

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

This seems generally useful to me for easy discoverability for me. I'd perhaps prefer to call the function something that makes it clear that it relates to pass manager stage plugins since "entry point" is just generic Python terminology and Qiskit also has entry points for synthesis plugins.

I'm fine to add the idea that Thomas suggested as well, though left to my own devices I probably wouldn't bother - as far as I understand it, it just boils down to

def passmanager_stage_plugin_map(stage):
    manager = getattr(PassManagerStagePluginManager(), f"{stage}_plugins")
    return {name: manager[name].obj for name in manager.names()}

which I'm not sure is worth the extra function, but I think it's a very subjective answer, so I don't feel strongly.

qiskit/transpiler/preset_passmanagers/plugin.py Outdated Show resolved Hide resolved
test/python/transpiler/test_stage_plugin.py Outdated Show resolved Hide resolved
@1ucian0
Copy link
Member Author

1ucian0 commented Mar 10, 2023

I'd perhaps prefer to call the function something that makes it clear that it relates to pass manager stage plugins since "entry point" is just generic Python terminology and Qiskit also has entry points for synthesis plugins.

I went for passmanager_stage_plugins to make it slightly shorter. But it is basically your code now (adding you as co-author). See b21c622

@@ -161,10 +161,11 @@ def pass_manager(self, pass_manager_config, optimization_level):
PassManagerStagePlugin
PassManagerStagePluginManager
list_stage_plugins
entry_point_obj
Copy link
Member

Choose a reason for hiding this comment

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

I think the docs failure is just because this line needs updating with the new name.

Copy link
Member Author

Choose a reason for hiding this comment

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

yeap.. forgot that. Fixed in 6135d9f

from qiskit.transpiler.preset_passmanagers.plugin import passmanager_stage_plugins
routing_plugins = passmanager_stage_plugins('routing')
basic_plugin = routing_plugins['basic']
?basic_plugin
Copy link
Member

Choose a reason for hiding this comment

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

This ? syntax is specific to IPython - you maybe want to use the standard Python built-in help instead.

Copy link
Member Author

Choose a reason for hiding this comment

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

fixed in 6135d9f

@jakelishman
Copy link
Member

Symengine 0.10!! 🎉

jakelishman
jakelishman previously approved these changes Apr 17, 2023
Copy link
Member

@jakelishman jakelishman left a comment

Choose a reason for hiding this comment

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

This was proposed well ahead of the 0.24 feature freeze (and the 0.23 feature freeze!) and its test failures were related to other problems in CI at the time. I've just brought it up-to-date (I was already a co-author), and assuming its tests pass immediately, I'm happy to just fold it into the rest of the release.

@jakelishman jakelishman added the Changelog: New Feature Include in the "Added" section of the changelog label Apr 17, 2023
@jakelishman jakelishman added this pull request to the merge queue Apr 18, 2023
Merged via the queue into Qiskit:main with commit c4f1b0b Apr 18, 2023
king-p3nguin pushed a commit to king-p3nguin/qiskit-terra that referenced this pull request May 22, 2023
…t#9275)

* plugin convenience function for getting the entry point object

* simpler code, thanks to Jake

Co-authored-by: Jake Lishman <jake.lishman@ibm.com>

* typehint and docstring

* reno update

* thanks Jake

* Fix docs build

---------

Co-authored-by: Jake Lishman <jake.lishman@ibm.com>
@1ucian0 1ucian0 deleted the entry_point_obj/1 branch August 14, 2023 08:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Changelog: New Feature Include in the "Added" section of the changelog
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants