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

Add functional option to circuit_key primitives util #8775

Merged
merged 6 commits into from
Sep 26, 2022

Conversation

pedrorrivero
Copy link
Member

@pedrorrivero pedrorrivero commented Sep 20, 2022

Summary

Adds optional kwarg to request a purely functional key from the circuit_key primitives utility. This is necessary to avoid recomputation on circuits which are functionally equivalent but vary in non-functional data (e.g. name, id).

Details and comments

Default behavior is set to False (i.e. default key is not purely functional) this decision has been made for compatibility with the previous implementation, but I think setting the default to True would be preferred.

EDIT: default behavior set to True after discussion (see below).

@pedrorrivero pedrorrivero requested review from a team, ikkoham and t-imamichi as code owners September 20, 2022 21:59
@qiskit-bot qiskit-bot added the Community PR PRs from contributors that are not 'members' of the Qiskit repo label Sep 20, 2022
@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:

@mtreinish mtreinish added this to the 0.23.0 milestone Sep 20, 2022
@coveralls
Copy link

coveralls commented Sep 20, 2022

Pull Request Test Coverage Report for Build 3126566913

  • 4 of 5 (80.0%) changed or added relevant lines in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.1%) to 84.421%

Changes Missing Coverage Covered Lines Changed/Added Lines %
qiskit/primitives/utils.py 4 5 80.0%
Totals Coverage Status
Change from base Build 3126106140: 0.1%
Covered Lines: 59599
Relevant Lines: 70597

💛 - Coveralls

ikkoham
ikkoham previously approved these changes Sep 21, 2022
Copy link
Contributor

@ikkoham ikkoham left a comment

Choose a reason for hiding this comment

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

I understood the necessity of the feature. I approve this change, but note that _circuit_key is only a workaround in the first place, which is why it is set to private.

t-imamichi
t-imamichi previously approved these changes Sep 21, 2022
Copy link
Member

@t-imamichi t-imamichi left a comment

Choose a reason for hiding this comment

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

I'm personally fine to remove id from this key. We need to discuss it in the future.

@pedrorrivero
Copy link
Member Author

I believe that id might cause issues as a matter of fact: if we are mapping the same circuits on the client and server sides, their ids will differ and so will the keys, since these are assigned by the interpreter and server and client use different interpreters. This subtlety should be considered before committing to it.

I am removing id from the non-functional key, and setting the default to functional=True.

@pedrorrivero pedrorrivero dismissed stale reviews from t-imamichi and ikkoham via 32e14ec September 21, 2022 14:27
@t-imamichi
Copy link
Member

id was kept in the previous PR #8604 because I heard from @ikkoham that @jyu00 and @ikkoham had an agreement to make a composite key in addition to id. #8604 (comment)
If they agree to remove id and name, I'm fine to remove them. It makes the function simpler.

@t-imamichi t-imamichi removed the Community PR PRs from contributors that are not 'members' of the Qiskit repo label Sep 21, 2022
@woodsp-ibm woodsp-ibm added the mod: primitives Related to the Primitives module label Sep 21, 2022
@pedrorrivero pedrorrivero requested review from ikkoham and t-imamichi and removed request for ikkoham and t-imamichi September 21, 2022 19:08
@jyu00
Copy link
Contributor

jyu00 commented Sep 21, 2022

Yeah we talked about using id and len(data), but this is much better. I agree with removing id. In fact do we even have a use case for specifying functional=False?

@t-imamichi
Copy link
Member

Thank you, Jessie. We can simplify the code by removing id and name. Let's go for it.

@ikkoham
Copy link
Contributor

ikkoham commented Sep 22, 2022

IMO, I like to stay on the safe side for these rare cases, in which circuits have different id and name but same functionality. As Imamichi-san indicated in the previous PR, collisions are occurring in the corner cases. There are probably collisions that we are not aware and id and name might help.

It is a preference which way to fall on the tradeoff between efficiency and safety, so let's take the efficiency side in this case.
I believe it is unlikely in normal use and let's hope no bug reports come in 🤞

@pedrorrivero
Copy link
Member Author

pedrorrivero commented Sep 22, 2022

Okay, let's do the following then:

  1. We add the functional kwarg to allow @ikkoham to include non-functional data when needed.
  2. We default to functional=True since this seems to be the best approach to avoid recomputation.
  3. We add name to the non-functional key to better handle corner cases.
  4. We get rid of id since it may cause conflicts when running different interpreters (e.g. client and server), and when running a single interpreter it stands in it of itself as a unique key: hence making all other values inconsequential in that case.

The PR should now be ready to merge as soon as tests pass 😉

Copy link
Member

@t-imamichi t-imamichi left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Contributor

@ikkoham ikkoham left a comment

Choose a reason for hiding this comment

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

Thanks. LGTM.

@ikkoham ikkoham added automerge Changelog: None Do not include in changelog labels Sep 26, 2022
@ikkoham ikkoham removed the automerge label Sep 26, 2022
@ikkoham
Copy link
Contributor

ikkoham commented Sep 26, 2022

Since this PR is not a new feature, but a follow-up of #8604 to improve efficiency, I would put it in at 0.22.

@ikkoham ikkoham modified the milestones: 0.23.0, 0.22 Sep 26, 2022
@mergify mergify bot merged commit a74dfdf into Qiskit:main Sep 26, 2022
@pedrorrivero pedrorrivero deleted the circuit-key branch September 26, 2022 15:00
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 mod: primitives Related to the Primitives module
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

8 participants