-
Notifications
You must be signed in to change notification settings - Fork 69
Adding type hints to circuit module #271
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
base: master
Are you sure you want to change the base?
Conversation
arg_label: Optional[str] = None, | ||
index: Optional[List[int]] = None, | ||
classical_controls: Optional[List[int]] = None, | ||
control_value: None = 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.
This should be
control_value: Optional[int] = None
I think
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.
Overall looks good. I found some edge cases in the comments.
classical_controls: Optional[List[int]] = None, | ||
control_value: None = None, | ||
classical_control_value: Optional[int] = None, | ||
style: None = 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.
This style
was added in the rendering project right? The docstring is also missing. Would be nice to add the possible options here.
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.
Or just add a docstring pointing to the options we have.
gates: Union[ | ||
Tuple[Gate, Gate, Gate, Gate], | ||
Tuple[Gate, Gate, Gate, Gate, Gate, Gate, Gate, Gate], | ||
], |
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 is definitely not right lol. It should be a list or tuple of gates.
def add_circuit(self, qc, start=0, overwrite_user_gates=False): | ||
def add_circuit( | ||
self, | ||
qc: "QubitCircuit", |
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.
Why does this use a string but not an imported class name?
): | ||
state: Qobj, | ||
cbits: Optional[List[int]] = None, | ||
U_list: None = 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.
This is a bug, U_list
is no longer used. We can remove it.
def initialize( | ||
self, | ||
state: Optional[Qobj] = None, | ||
cbits: Optional[List[int]] = None, | ||
measure_results: Optional[ | ||
Union[List[int], Tuple[str, str], Tuple[str, str, str], Tuple[()]] | ||
] = 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.
This is wrong again. I guess probably we should not return tuples with undetermined length in the code and should use a list instead? What do you think?
This should be list of int or str.
measure_results: Optional[ | ||
Union[List[int], Tuple[str, str], Tuple[str, str, str], Tuple[()]] | ||
] = 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.
Same
probabilities: Union[List[int], float64, int, List[float64]], | ||
cbits: Optional[Union[List[List[int]], List[int], List[int64]]] = 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.
The float64 and int64 are a bit weird. I don't see the reason.
PR Summary
This PR introduces type hints to the codebase using
MonkeyType
. Initial applied to a single circuit module, and if feasible, can be extended to other modules. (Issue: #262)Encountered issues with
pytest decorators
while running through the test suite. This was resolved using pytest-monkeytype lib, which allowsMonkeyType
to work correctly with pytest. Still requires a bit post processing, but it is minimal.QuTiP-QIP supports Python 3.9+
, so we are unable to use Python 3.10+ syntax (e.g.,|
forUnion
). Also,MonkeyType
is unable to generate in this format directly.Files Type Hint Status
_decompose.py
base_renderer.py
(already present)circuit.py
circuitsimulator.py
color_theme.py
(not needed)mat_renderer.py
already present)texrenderer.py
text_renderer.py
(already present)