Skip to content
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

Fixes gate label import #63

Closed
wants to merge 3 commits into from
Closed

Conversation

purva-thakre
Copy link
Contributor

@purva-thakre purva-thakre commented Jun 21, 2021

Fixes import of gate labels when gates were moved to operations folder. See related comment.

Tested with examples in this notebook.

The notebook also needs a separate PR to change how gates are imported + deprecation warning in In [62]. This will be added later.

Following code block is for future reference in relation to In [62] :

<ipython-input-60-0c4e722f5dae>:3: DeprecationWarning: `np.complex` is a deprecated alias for the builtin `complex`. To silence this warning, use `complex` by itself. Doing this will not modify any behavior and is safe. If you specifically wanted the numpy scalar type, use `np.complex128` here.
Deprecated in NumPy 1.20; for more details and guidance: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations
  mat = np.zeros((4, 4), dtype=np.complex)

@@ -57,7 +57,7 @@
'gate_expand_1toN', 'gate_expand_2toN', 'gate_expand_3toN',
'qubit_clifford_group', 'expand_operator', '_single_qubit_gates',
'_para_gates', '_ctrl_gates','_swap_like','_toffoli_like',
'_fredkin_like']
'_fredkin_like','_GATE_NAME_TO_LABEL','_gate_label']
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We shouldn't add these _ constants and functions to __all__ I don't think and we don't need to import _GATE_NAME_TO_LABEL in circuit.py at all.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we don't need to import _GATE_NAME_TO_LABEL in circuit.py at all

We do actually. It's used in circuit.py. I tried running one of the notebooks with _gate_label and that caused some errors.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$ ag _GATE_NAME_TO_LABEL .
src/qutip_qip/operations/gates.py
171:            if (name in _GATE_NAME_TO_LABEL) and (arg_value is not None):
226:_GATE_NAME_TO_LABEL = {
263:    if name in _GATE_NAME_TO_LABEL:
264:        gate_label = _GATE_NAME_TO_LABEL[name]

I'm not seeing it used anywhere other than in gates.py? Could you provide a link to where else it is used?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I was confused between _gate_label and _GATE_NAME_TO_LABEL. You are right. Only _gate_label has to be imported.

Although, for this issue Boxi wanted a separate PR. Feel free to close this PR if that's changed.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I was asking for a separate PR mainly because the decomposition is a new feature and this is a bug fix. Mixing them might cause some confusion if someone checks the history one day. As #66 is all about bug fixing and cleaning, I can just merge that one and saves you the trouble of updating it for _GATE_NAME_TO_LABEL. But thank you anyway!

@hodgestar
Copy link
Contributor

@purva-thakre Thank you for noticing this. I came across it independently and addressed it in a slightly different in #66. If #66 is merged, I'll close this PR. Apologies for not finding this PR before I fixed the bug in mine.

@hodgestar
Copy link
Contributor

#66 also adds a test for .latex_code().

@purva-thakre
Copy link
Contributor Author

@purva-thakre Thank you for noticing this. I came across it independently and addressed it in a slightly different in #66. If #66 is merged, I'll close this PR. Apologies for not finding this PR before I fixed the bug in mine.

No problem @hodgestar

@purva-thakre purva-thakre deleted the gate_import branch June 26, 2021 03:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants