-
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
Implementation of the Gray-Synth and Patel–Markov–Hayes algorithms #2457
Conversation
I am receiving the following error and don't know what to do about it: |
Hi @BoschSamuel, thank you for your recent contributions! We will try to review them as soon as possible. About the error you are getting here, you have to do this:
|
I am also not sure why the "cyclic-import" error occurs. When I run |
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.
I had a quick look and left some comments.
This file should not be in the transpiler/passes
directory, because it is not a pass. Passes take a DAGCircuit and return a DAGCircuit (their classes inherit from AnalysisPass or TransformationPass).
I think we need a synthesis directory in the qiskit/transpiler
folder, dedicated to different synthesis algorithms. Would you like to create this? We should move statevector synthesis and unitary synthesis algorithms to it as well.
…le gates applied to same state)
…le gates applied to same state) also during the algorithm
Co-Authored-By: Ali Javadi-Abhari <[email protected]>
…put GraySynth algorithm into it. More changes to follow
…ack functionality, and added raise Exception for numpy.ndarray
…y arbitrary phase-gate rotation
@boschmitt I had to read the GraySynth and Patel-Markov-Hayes algorithms in detail in order to review this, so it took me a bit of time. But I think it is ready now. I made some changes. The commit history should be descriptive, but here is the gist:
|
return circ | ||
|
||
|
||
def _lwr_cnot_synth(state, n_sections): |
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.
I think the n_sections
argument should actually be section_size
, because that is how it is used in the paper, and that is how you seem to be interpreting it in line 259.
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.
I agree!
cnots_copy = np.transpose(np.array(copy.deepcopy(cnots))) | ||
state = np.eye(n_qubits).astype('int') # This matrix keeps track of the state in the algorithm | ||
|
||
# Check if some T-gates can be applied, before adding any C-NOT gates |
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.
I don't quite follow this part of the code, what is the benefit of adding the phase gates early?
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.
The idea of this part of the code is just to apply those phase-shift gates before the actual algorithms starts (it should say phase-shift gates, not T-gates...I fixed this now). It is just there to speed things up, as the whole algorithm then doesn't have to deal with such trivial gates
@ajavadia Thank you for the detailed review. I will work on this as soon as possible, as things are a bit crazy for me this and next week :) |
This looks good to me now, thanks for the effort! I'll open an issue about that double-controlled Z synthesis to be investigated further. |
…iskit#2457) * implemented Gray-Synth algorithm * fixed formatting of the code * added functionality for processing matrices with same columns (multiple gates applied to same state) * added functionality for processing matrices with same columns (multiple gates applied to same state) also during the algorithm * fixed 2 bugs in lwr_cnot_synth() and in graysynth() * minor formatting fixes * Created test_graysynth.py file, for checking if graysynth.py works properly * minor improvements * fixed error as explained by @ajavadia * changed __init__.py * Fixed cyclic import error (suggested by @ajavadia) Co-Authored-By: Ali Javadi-Abhari <[email protected]> * Created new folder transpiler/synthesis for synthesis algorithms and put GraySynth algorithm into it. More changes to follow * upated testing function accordingly * added function documentations, removed redundant state = np.matrix(state) line * removed storage class, and replaced it with regular list using its stack functionality, and added raise Exception for numpy.ndarray * added documentation for Exception in function cnot_synth() * instead of using T-gates by default, it is now possible to specify any arbitrary phase-gate rotation * changelog.md * type fix angels -> angles * docstring edits * remove qreg from cnot_synth args * remove number (n_qubits) from function args as it can be inferred * specify a default of 2 for n_sections * simplify test via Operator class, and add test from paper example * make cnot_synth standalone (not cnot appender), and use QiskitError * fix bug in cnot_synth and add test * cnot_synth takes python lists or numpy ndarray * lint * Update graysynth.py * renamed n_sections --> section_size
Summary
I added an implementation of the Gray-Synth algorithm [1] and the Patel–Markov–Hayes algorithm [2]
Details and comments
Hello again,
my name is Samuel Bosch, and I am a master's student at EPFL in Switzerland. I work in the group of Prof. Giovanni de Micheli on Quantum Computing. My supervisors are Dr. Mathias Soeken and Bruno Schmitt. I started programming in Qiskit quite recently and would like to make my second contribution to Qiskit-Terra.
The implementation of the Gray-Synth algorithm is explained in detail in reference [1] in section 4. The code of the algorithm is based on the pseudo-code named "Algorithm 1. Algorithm for synthesizing a parity network".
The implementation of the Patel–Markov–Hayes algorithm (which is needed in the Gray-Synth algorithm) can be found in reference [2]. The code of the algorithm is based on the pseudo-code named "Algorithm 1: C-NOT Circuit Synthesis".
I wasn't really sure where to put my code, so I put it under "qiskit-terra ▸ qiskit ▸ transpiler ▸ passes", which might not be the optimal location. Let me know if there is anything I can change in the code.
Best regards,
Samuel