-
Notifications
You must be signed in to change notification settings - Fork 63
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
Add gate class #96
Merged
Merged
Add gate class #96
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
508c6bb
to
7cf287e
Compare
BoxiLi
commented
Mar 29, 2022
@@ -179,55 +177,6 @@ def test_add_gate(self): | |||
assert qc.gates[6].targets == [5] | |||
assert qc.gates[5].arg_value == 1.570796 | |||
|
|||
# Test Exceptions # Global phase is not included |
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.
These tests are removed because they are too detailed and only checking ValueError
without the error message also does not correctly check if the exception raised is the correct one. In addition, in the new gate class structure, the input control is moved to each class.
The classical control value does not yet work if the control_value is a tuple.
They are the same gates and hence should not have different names. This is another example that shows that using name to identify gate is not a good approach. If isinstance is used for the class name, the result will always be consistent.
It is more common to put control before target, such as CNOT(0, 1)
These tests are removed because they are too detailed and only checking ValueError without the error message also does not correctly check if the exception raised is the correct one. In addition, in the new gate class structure, the input control is moved to each class.
Disable "Line too long", which is already covered in Black.
This makes sure sure that gate defined using CSIGN will always be recognized by isinstance(gate, CSIGN). To compare the generated gate it is better to use the fidelity measure.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The first step of refactoring the gate representation. It defines a gate class for each gate function as a subclass of
Gate
, this simplifies several things:isinstance
andissubclass
, instead of by the name attribute.get_compact_operator
method.circuit.py
Docstrings are also added to each gate class with examples.
See also #15 for more details.
There is a few codeclimate issues regarding Line too long and Similar blocks. I don't plan to fix them because the similar gate class are by design and the long lines are just docstrings with code example output. They are better like this.