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

[WIP] Make a separate base quantum tape class #829

Merged
merged 12 commits into from
Oct 6, 2020

Conversation

mariaschuld
Copy link
Contributor

@mariaschuld mariaschuld commented Sep 28, 2020

For future development, for example when introducing a batch tape, it would be cleaner to have a "base" quantum tape class that only implements functionality for constructing, evaluating and validating circuits. The current QuantumTape class would inherit from this base class and add functionality for differentiation.

The aim of this PR is to check and discuss how invasive such a change would be.

About naming: we reserve the name QuantumTape for the new base tape class, and introduce JacobianTape for the tape that implements differentiation. JacobianTape has all functionality of the current QuantumTape class. While this is much clearer, it makes the PR quite large, even though most changes are just renamings.

Advantages: Conceptually, the representation of a circuit and the ability to compute its Jacobian are two separate features, one extending the other. Classes can now inherit from the base tape without inheriting a specific implementation of the jacobian method.

Disadvantages: Differentiation and circuit construction are not entirely distinct, since the circuit construction uses logic on differentiable and non-differentiable parameters. It seems that the only function that lives at this intersection is _update_gradient_info(), which adds the preferred diff method to trainable parameters. Here, this function is made a property of the jacobian quantum tape.

Note: At the moment, the PR does not contain any changes to documentation, which would have to be added if we decide to follow this route.

pennylane/tape/__init__.py Outdated Show resolved Hide resolved
@codecov
Copy link

codecov bot commented Sep 28, 2020

Codecov Report

Merging #829 into master will increase coverage by 0.00%.
The diff coverage is 99.10%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master     #829   +/-   ##
=======================================
  Coverage   97.68%   97.68%           
=======================================
  Files         135      136    +1     
  Lines        9107     9117   +10     
=======================================
+ Hits         8896     8906   +10     
  Misses        211      211           
Impacted Files Coverage Δ
pennylane/tape/interfaces/autograd.py 100.00% <ø> (ø)
pennylane/tape/interfaces/tf.py 96.22% <ø> (ø)
pennylane/tape/interfaces/torch.py 100.00% <ø> (ø)
pennylane/tape/tapes/cv_param_shift.py 99.20% <ø> (ø)
pennylane/tape/tapes/tape.py 99.20% <ø> (+0.08%) ⬆️
pennylane/tape/tapes/jacobian_tape.py 98.97% <98.97%> (ø)
pennylane/tape/__init__.py 100.00% <100.00%> (ø)
pennylane/tape/measure.py 96.87% <100.00%> (ø)
pennylane/tape/operation.py 98.33% <100.00%> (ø)
pennylane/tape/qnode.py 98.75% <100.00%> (ø)
... and 4 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 29be042...d0c72a2. Read the comment docs.

Copy link
Member

@josh146 josh146 left a comment

Choose a reason for hiding this comment

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

💯

To fix the failing Sphinx CI, you'll need to update the

:meth:`~.jacobian`

to be

:meth:`~.JacobianTape.jacobian`

in the QuantumTape.trainable_params docstring

pennylane/tape/interfaces/autograd.py Show resolved Hide resolved
pennylane/tape/tapes/jacobian_tape.py Outdated Show resolved Hide resolved
pennylane/tape/tapes/jacobian_tape.py Show resolved Hide resolved
pennylane/tape/tapes/reversible.py Outdated Show resolved Hide resolved
pennylane/tape/tapes/tape.py Show resolved Hide resolved
pennylane/tape/tapes/tape.py Show resolved Hide resolved
pennylane/tape/tapes/jacobian_tape.py Show resolved Hide resolved
@co9olguy
Copy link
Member

co9olguy commented Oct 5, 2020

Did not review the PR, but if @josh146 approves, go for it!

@co9olguy co9olguy removed their request for review October 5, 2020 20:05
@mariaschuld mariaschuld merged commit 278122b into master Oct 6, 2020
@mariaschuld mariaschuld deleted the make_baseqnode_class branch October 6, 2020 06:00
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