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
circuit.library.graph_state needs testing #4349
Comments
Hi, I'd be interested in contributing if this issue is still available. This would be my first issue so I'm not completely sure where to start! |
Hi, I would like to work on this issue, would it be possible to assign this to me if it is not being worked on? |
Hi! Great that you want to contribute 🎉 So the task would be adding tests for the Ideally for such a circuit we would check the implementation on a theoretical level. This means we're checking the Qiskit implementation against what the maths says. This can e.g. be done by computing the unitary the circuit implements and then simulating the circuit in Qiskit. Another simpler way, which would already be a good start, is to compare the circuit to a hardcoded reference circuit. This is e.g. done for the You can check this reference files and let me know if you have any questions! What's the tactic you would like to pursue? |
Hi @Cryoris! Thank you so much for going into such details and explaining this so clearly! Your description has provided more than enough background for me to work on this 🙂 I would like to make a check on a theoretical level, it seems quite straightforward to calculate the matrix by hand for a particular graph. Would it be fine if I pick a smaller graph that can be implemented by up to 4 qubits to be used for testing, e.g., the graph No. 3 in FIG. 4 of the paper? I am also considering creating multiple tests for graphs of various sizes, but let me know if that would be too much. Thank you again for guidance! |
Hi again! I just wanted to give a quick update about this issue. I have looked into testing the graph states a bit more and I have come up with a piece of code that creates the expected unitary for a given adjacency matrix. I thought this might be a relevant update, because my previous point from the above comment that I would be calculating the matrix by hand is not valid anymore. I think it makes more sense to numerically calculate the expected matrix based on the adjacency matrix, since that would allow to change the test by simply changing the adjacency matrix. I can see that this is the approach used in other test cases, e.g., for As a quick outline, the way I calculate the expected matrix from the adjacency matrix is quite simple. First, I create the matrix for Hadamard gates for the number of qubits extracted from the adjacency matrix. Secondly, I create the matrices for the CZ gates based on the adjacency matrix. This step is slightly more involved, since I need to get the CZ gate for any given number of qubits and control-target connections. I do that by looping through an identity matrix and setting the value of the diagonal elements to -1 where both the control and target are in state |1>. Lastly, all the matrices are multiplied together to get the expected unitary. I have tested this approach and the results look good. I would now like to work on adding the mentioned code to |
Hi @mantcep, sounds great that you found a way to compute the generic unitary transformation that creates the graph state. A fixed comparison would also be good, but if we can do it generically that's of course better. It is easier to comment on the code if we can see it, so feel free to open a pull request already now and name it Sounds like a good plan 👍 |
Hi @Cryoris, I have created a pull request as suggested. I tried looking into a better way of getting the CZ gate, but I could not think of anything straightforward. Let me know what you think, I could put more time into vectorizing the loop over the identity matrix. Thank you for your time! 🙂 |
* Add test for graph state circuit (#4349) * Update graph state circuit test with stabilizers * Add symmetry check to graph state circuit test * Apply suggestions from code review * rm whitespaces Co-authored-by: Julien Gacon <gaconju@gmail.com>
* Add test for graph state circuit (Qiskit#4349) * Update graph state circuit test with stabilizers * Add symmetry check to graph state circuit test * Apply suggestions from code review * rm whitespaces Co-authored-by: Julien Gacon <gaconju@gmail.com>
The object
GraphState
(inqiskit/circuit/library/graph_state.py
) needs testing. No line is currently coveraged.The text was updated successfully, but these errors were encountered: