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

Make tape mode default #1040

Merged
merged 43 commits into from
Jan 28, 2021
Merged
Changes from 3 commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
4df4002
fixes so far
josh146 Jan 26, 2021
5951d93
more
josh146 Jan 26, 2021
973dc5b
more
josh146 Jan 26, 2021
016ea50
Update
josh146 Jan 26, 2021
eea1885
openqasm
josh146 Jan 26, 2021
573daa3
inverse
josh146 Jan 26, 2021
ff4aa03
black
josh146 Jan 26, 2021
2e1ae19
black
josh146 Jan 26, 2021
20c1b36
fixes
josh146 Jan 26, 2021
1d63f2c
more tests passing
josh146 Jan 26, 2021
bba5743
more
josh146 Jan 26, 2021
db93789
Update pennylane/tape/__init__.py
josh146 Jan 26, 2021
e470446
more
josh146 Jan 26, 2021
5ca97e4
Merge branch 'make-tape-default' of github.com:PennyLaneAI/pennylane …
josh146 Jan 26, 2021
1930dfa
more
josh146 Jan 26, 2021
a4f91cb
remove enable_tape from docs
josh146 Jan 26, 2021
3416709
sampling fixes
josh146 Jan 26, 2021
dc5f45d
Merge branch 'master' into make-tape-default
josh146 Jan 26, 2021
4de4e28
more
josh146 Jan 26, 2021
a0c00c7
Merge branch 'make-tape-default' of github.com:PennyLaneAI/pennylane …
josh146 Jan 26, 2021
14149d4
add test
josh146 Jan 26, 2021
883591b
Merge branch 'master' into make-tape-default
antalszava Jan 26, 2021
52fdd9d
Apply suggestions from code review
josh146 Jan 27, 2021
5372913
Update tests/beta/test_default_tensor_tf.py
josh146 Jan 27, 2021
992bdbc
suggested changes
josh146 Jan 27, 2021
8c8c165
Merge branch 'make-tape-default' of github.com:PennyLaneAI/pennylane …
josh146 Jan 27, 2021
826aca1
revert max-depth to 2
josh146 Jan 27, 2021
8d367e0
Merge branch 'master' into make-tape-default
josh146 Jan 27, 2021
05676ac
remove import
josh146 Jan 27, 2021
d06ad0e
Merge branch 'make-tape-default' of github.com:PennyLaneAI/pennylane …
josh146 Jan 27, 2021
3768dd7
bug fix
josh146 Jan 28, 2021
77864ca
lint
josh146 Jan 28, 2021
20e469a
lint
josh146 Jan 28, 2021
027c2df
fix docstrings
josh146 Jan 28, 2021
206fbe3
fix templates
josh146 Jan 28, 2021
bc8dfbf
fix templates
josh146 Jan 28, 2021
3580382
Merge branch 'master' into make-tape-default
mariaschuld Jan 28, 2021
345be59
Tape hash (#1041)
antalszava Jan 28, 2021
54fc9de
no PL import in tape circuit graph
antalszava Jan 28, 2021
681d739
Update tests/beta/test_default_tensor_tf.py
josh146 Jan 28, 2021
6c8bfc4
Update pennylane/circuit_graph.py
josh146 Jan 28, 2021
8156079
Update pennylane/_qubit_device.py
josh146 Jan 28, 2021
51a4120
Merge branch 'master' into make-tape-default
josh146 Jan 28, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion pennylane/templates/decorator.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,18 @@ def circuit():
Returns:
callable: The wrapper function
"""
# pylint: disable=import-outside-toplevel

@wraps(func)
def wrapper(*args, **kwargs):
with OperationRecorder() as rec:
import pennylane as qml
Copy link
Contributor

Choose a reason for hiding this comment

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

This import feels hacky and cyclical. Can't we import the needed modules at the top of this file?

Copy link
Member Author

Choose a reason for hiding this comment

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

hahaha I tried so many combinations (including having it at the top of the file), and constantly ran into cyclical import errors. This was the only combination that didn't result in a cyclical import error.

I'm okay with this for now, since

  • we can remove it next week when we rip out the old core
  • PennyLane has already been imported by this point, so there is no overhead here, it simply makes the namespace available to the function.


recorder_class = OperationRecorder

if qml.tape_mode_active():
recorder_class = qml.tape.TapeOperationRecorder

with recorder_class() as rec:
Copy link
Contributor

Choose a reason for hiding this comment

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

Just to understand, why is it not

     if qml.tape_mode_active():
            import pennylane as qml
            recorder_class = qml.tape.TapeOperationRecorder
     else: 
        recorder_class = OperationRecorder

Copy link
Contributor

Choose a reason for hiding this comment

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

If tape mode is active to reimport, else you use the old one?

Copy link
Member Author

@josh146 josh146 Jan 28, 2021

Choose a reason for hiding this comment

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

If PennyLane is already imported in the Python session, import pennylane as qml won't actually do anything (e.g., the __init__.py won't be re-executed).

The import pennylane as qml is just to make the qml namespace available in this file, so that we can access the tape_mode_active and TapeOperationRecorder functions/classes.

I couldn't include this import at the top of the file due to circular imports, so that's the only reason it is inside the decorator :(

Copy link
Contributor

Choose a reason for hiding this comment

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

Makes sense. I never understood circular imports, maybe we should solve the issue once and for all...

func(*args, **kwargs)

return rec.queue
Expand Down