-
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
Raise error for invalid section_size
in synth_cnot_count_full_pmh
#12166
Raise error for invalid section_size
in synth_cnot_count_full_pmh
#12166
Conversation
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:
|
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:
|
Pull Request Test Coverage Report for Build 8785363931Warning: 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 |
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.
Hi @Tarun-Kumar07 - thank you very much for providing this high-quality contribution into qiskit. However, as you pointed out, changing the default value of section_size
may provide a non-optimal circuit with increased circuit depth or number of CX gates.
I think that a better solution could be to have a default value of None
and then if section_size
is not provided, to calculate it based on the state
dimension N
.
I think that according to PMH paper, the optimal section_size
should be log(N)
(maybe up to some factor?) and not 2
.
Perhaps you could do some experiments with random matrices to check what could be the optimal default value of section_size
that provides optimal CX count and/or circuit depth ?
Thank you, @ShellyGarion. I'll experiment with the default value. Do we have a documentation repository where we document such experiments for future reference? |
Please summarize your results in the PR comments. |
Hey @ShellyGarion, I'm not sure why the code below is failing when I provide different import numpy.testing as np
import qiskit.quantum_info as qi
from qiskit.synthesis import synth_cnot_count_full_pmh
from qiskit.synthesis.linear import random_invertible_binary_matrix
mat = random_invertible_binary_matrix(6, seed=1234)
qc_4 = synth_cnot_count_full_pmh(mat, section_size=4)
op_4 = qi.Operator(qc_4)
qc_2 = synth_cnot_count_full_pmh(mat, section_size=2)
op_2 = qi.Operator(qc_2)
np.assert_equal(op_4.data, op_2.data) # Fails For the given binary matrix of shape (6,6), something seems off with
Do you have any insight into why this is happening? Thanks! |
@Tarun-Kumar07, thanks for spotting this bug - now the issue is significantly more problematic than what I originally thought. A quick experiment on my end (varying the number of qubits and considering 100 random invertible binary matrices for each) gives the following output:
Would you be interested to take a deeper look both at the paper and the code and see if you can fix the problem? |
For reference, here is my python script (based on yours):
|
@alexanderivrii , I will investigate further and let you know |
In a previous version of this code there was the following comment on |
@Tarun-Kumar07 - are you still working on this ? |
I'm currently tied up with some personal matters and will be able to resume work after June 15th. Is that okay with you? Thanks for understanding! |
@ShellyGarion @alexanderivrii I want you hopefully to reproduce this edited version of function
|
@Abdalla01001 - thanks for your suggestion. Could you perhaps verify the correctness of your suggested code? |
@ShellyGarion Yeah: |
thanks @Abdalla01001 for checking this. Could you also check that with your code, for large number of qubits (say, 20, 50, 100, 200, 500, 1000), the value of |
@ShellyGarion
results:
|
Hi @Abdalla01001, |
@Tarun-Kumar07 sure! |
@ShellyGarion @alexanderivrii Any updates? |
@Abdalla01001 - I've already assigned you in the issue #12106, so feel free to open a new PR, and then we'll close this one. |
@ShellyGarion Done! #12712 |
As discussed above, I'm closing this PR in favor of #12712 |
Summary
This PR enforces the validation that
section_size
must be less than or equal to num_qubits for proper functioning of the synth_cnot_count_full_pmh algorithm, as described in Efficient Synthesis of Linear Reversible Circuits.It fixes #12106
Description of change
section_size
<= number of qubits.section_size
to proportional tonp.log(num_qubits)
.