Skip to content

Conversation

KoheiSuda
Copy link

Summary

fixes #12059
This PR extends the random_circuit function in Qiskit to allow users to specify a distribution num_operand_distribution that defines the ratio of 1-qubit, 2-qubit, ..., n-qubit gates in the generated random circuit. For example, calling random_circuit with num_operand_distribution={1: 0.5, 2: 0.5} will produce random circuits with approximately 50% single-qubit gates and 50% two-qubit gates, while disallowing gates with more than 2 qubits.

Additionally, the following points have been addressed:

The parameter max_operands should take precedence, i.e. if max_operands is set, draw a random distribution num_operand_distribution. Raise an error if sum(num_operand_distribution.values()) != 1.0 or if max_operands is set at the same time as num_operand_distribution or if any key in num_operand_distribution is larger than the largest available n-qubit gate (see get_standard_gate_name_mapping).

Details and comments

I worked on this issue as part of unitaryHACK, so please assign this issue to me if this PR is accepted.

@KoheiSuda KoheiSuda requested a review from a team as a code owner May 29, 2024 03:28
@qiskit-bot qiskit-bot added the Community PR PRs from contributors that are not 'members' of the Qiskit repo label May 29, 2024
@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 following people are relevant to this code:

  • @Qiskit/terra-core

@CLAassistant
Copy link

CLAassistant commented May 29, 2024

CLA assistant check
All committers have signed the CLA.

@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.


KoheiSuda seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
You have signed the CLA already but the status is still pending? Let us recheck it.

@sbrandhsn sbrandhsn self-assigned this May 29, 2024
@sbrandhsn
Copy link
Contributor

Dear Kohei-san, thanks for showing interest in this issue. I will be on vacation and look into this PR next week! In the meantime make yourself familiar with https://github.com/Qiskit/qiskit/blob/main/CONTRIBUTING.md and the unitaryhack rules (if you have not already). :-)

@1ucian0 1ucian0 added the unitaryhack Issues/PR participating (now or in the past) in the UnitaryHack event see https://unitaryhack.dev/ label May 29, 2024
Copy link
Contributor

@sbrandhsn sbrandhsn left a comment

Choose a reason for hiding this comment

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

Thanks for this contribution @KoheiSuda! :-) This looks like an elegant solution that needs a couple of modifications before it can be accepted.

  • There are formatting issues which causes our CI to fail. Please run tox -eblack and tox -elint-incr locally to figure out what needs to be changed.
  • I think I made a mistake when specifying the precedence of max_operands, sorry! Having both set, max_operands and num_operand_distribution set is fine, please revert the initial default value of max_operands. If num_operand_distribution is not set but max_operands is set, draw a random num_operand_distribution and continue with your code or use the initial code.
  • Please add a test case with a distribution that disallows single-qubit gates, i.e. with {1:0, …}. I think some logic around how single-qubit gates are used to fill the non-used qubits in layer would fail such a test case with the current code.
  • Please add a test case with some distribution and specify a particularly long depth as a parameter. This should make your num_operand_distribution match closely what is contained in the returned random circuit.
  • The CLAAssistant appears to have an issue with your e-mail address, can you fix that? :-)

@KoheiSuda
Copy link
Author

KoheiSuda commented Jun 6, 2024

@sbrandhsn
Thank you for your thoughtful advice!

Please add a test case with a distribution that disallows single-qubit gates, i.e. with {1:0, …}. I think some logic around how single-qubit gates are used to fill the non-used qubits in layer would fail such a test case with the current code.

I have a question. If a distribution disallows single-qubit gates, how should I fill the non-used qubits in layer? Is it okay to use single-qubit gates?

@sbrandhsn
Copy link
Contributor

Dear @KoheiSuda, I'm sorry but a PR was submitted by a different user that addresses #12059 completely. Unfortunately, unitaryHACK explicitly allows multiple developers to work on the same issue at once ( https://unitaryhack.dev/rules/ ) and essentially requires us to select the first valid PR for the bounty. Qiskit still has open unitaryHACK issues available at https://github.com/Qiskit/qiskit/issues?q=is%3Aopen+label%3Aunitaryhack-bounty+is%3Aissue that (partially) attracted interest by other developers.

Apart from this, I was very happy about your elegant contribution so far and can only encourage you to continue your good work on open source projects that you find interesting! :-)

@KoheiSuda
Copy link
Author

@sbrandhsn
OK, Thank you for your reviewing!

@1ucian0 1ucian0 removed the unitaryhack Issues/PR participating (now or in the past) in the UnitaryHack event see https://unitaryhack.dev/ label Sep 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Community PR PRs from contributors that are not 'members' of the Qiskit repo
Projects
Status: No status
Development

Successfully merging this pull request may close these issues.

Controlling the Insertion of Multi-Qubit Gates in the Generation of Random Circuits
5 participants