-
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
[unitaryHACK] Controlling the Insertion of Multi-Qubit Gates in the Generation of Random Circuits #12059 #12483
Conversation
…eration of Random Circuits Qiskit#12059
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:
|
Hi @shravanpatel30, thanks for the PR! the code has some linting issues. I'm moving this one to |
qiskit/circuit/random/utils.py
Outdated
@@ -21,7 +21,7 @@ | |||
|
|||
|
|||
def random_circuit( | |||
num_qubits, depth, max_operands=4, measure=False, conditional=False, reset=False, seed=None | |||
num_qubits, depth, num_operand_distribution: dict = None, max_operands=None, measure=False, conditional=False, reset=False, seed=None |
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.
In general, it is better not to change the order of the positional arguments. Otherwise, you might accidentally break callers like random_circuit(2, 4, 10)
Hi @1ucian0, thanks for reviewing the PR. I was able to fix the linting issues but I have a question about the testing. When I run |
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:
|
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.
Thanks for your contribution @shravanpatel30! :-) 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
andtox -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
andnum_operand_distribution
set is fine, please revert the initial default value ofmax_operands
. Ifnum_operand_distribution
is not set butmax_operands
is set, draw a randomnum_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 yournum_operand_distribution
match closely what is contained in the returned random circuit.
qiskit/circuit/random/utils.py
Outdated
qubits = np.array(qc.qubits, dtype=object, copy=True) | ||
|
||
counter = np.zeros(5, dtype=np.int64) # Counter to keep track of number of different gate types |
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.
What does the constant 5
refer to here? Can you derive the value for that constant from all_gate_lists
?
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 constant 5
here refers to an array that will have total length len(all_gate_lists) + 1
, so I can just derive this value from all_gate_lists
.
Also, you can fixing that failing test case in the described way seems fine to me. :-) |
Sorry for the multiple commits, but I am facing an issue with runnin @sbrandhsn I have addressed your comments in my recent commits. Here are some details about the changes:
Question
|
I did a quick plot to see how accurate the random circuit generation is and it looks pretty good. I was wondering whether you have an idea on why the ratios of 1-q and 4-q gates have a larger distance to the specified distribution than 2-q and 3-q gates. :-)
|
@sbrandhsn I'm not exactly sure why we are seeing this but here is what I think. The larger distance between 1-q and 4-q gates is because it is easier to fit in 1-q gates and harder to fit in 4-q gates using the current implementation. The function But if we look at the distribution of gates for a random circuit with 100 and 500 qubits, what I observed is that distance from the expected distribution decreases. We will observe a similar trend if we just draw a random distribution from only 1-q, 2-q and 3-q gates (excluding 4-q gates). Below is the plot for that |
This LGTM, thanks! Can you add some information we obtained from the plots to the code? Something along the lines of: |
@sbrandhsn I have added the comment in the code and in that I have also mentioned that for more details on how the gate distribution changes with no. of qubits and depth refer to this pull request. |
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, thanks!
I hope you don't mind the small update to the argument documentation - please update how you see fit. :-) Thanks for your contribution, I will accept the PR! |
Pull Request Test Coverage Report for Build 9414985165Warning: This coverage report may be inaccurate.This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.
Details
💛 - Coveralls |
Please go ahead and add a comment to #12059 so I can assign the issue to you, thanks! :-) |
Pull Request Test Coverage Report for Build 9415220376Warning: This coverage report may be inaccurate.This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.
Details
💛 - Coveralls |
Pull Request Test Coverage Report for Build 9415861397Details
💛 - Coveralls |
…eneration of Random Circuits Qiskit#12059 (Qiskit#12483) * unitaryHACK Controlling the Insertion of Multi-Qubit Gates in the Generation of Random Circuits Qiskit#12059 * Fixed linting issues * Fixed long lines and unused variable * Added requested changes * Removed unused imports * Added a test * Added the stochastic process comment and edited releasenotes * Update qiskit/circuit/random/utils.py * lint... --------- Co-authored-by: Sebastian Brandhofer <[email protected]>
This pull request is submitted as a solution for issue #12059.
I have added a feature to the random_circuit() function that will allow users to specify a 'num_operand_distribution' by which thay can control the distribution of 1-qubit, 2-qubit, 3-qubit, and 4-qubit gates in the circuit. Alongwith the code I have also updated the release notes and have included some tests.
Thank you in advance for reviewing.
Summary
Details and comments