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

Add adjoint method to Python frontend #137

Merged
merged 24 commits into from
Aug 27, 2021
Merged

Add adjoint method to Python frontend #137

merged 24 commits into from
Aug 27, 2021

Conversation

trbromley
Copy link
Contributor

No description provided.

@github-actions
Copy link
Contributor

Hello. You may have forgotten to update the changelog!
Please edit .github/CHANGELOG.md with:

  • A one-to-two sentence description of the change. You may include a small working example for new features.
  • A link back to this PR.
  • Your name (or GitHub username) in the contributors section.

@github-actions
Copy link
Contributor

github-actions bot commented Aug 19, 2021

Test Report (C++) on Ubuntu

    1 files  ±0      1 suites  ±0   0s ⏱️ ±0s
182 tests ±0  131 ✔️ ±0  0 💤 ±0    51 ❌ ±0 
767 runs  ±0  648 ✔️ ±0  0 💤 ±0  119 ❌ ±0 

For more details on these failures, see this check.

Results for commit 5f0e331. ± Comparison against base commit f154807.

♻️ This comment has been updated with latest results.

@codecov
Copy link

codecov bot commented Aug 19, 2021

Codecov Report

❗ No coverage uploaded for pull request base (7072_adj_diff@f154807). Click here to learn what that means.
The diff coverage is n/a.

❗ Current head de9c325 differs from pull request most recent head 5f0e331. Consider uploading reports for the commit 5f0e331 to get more accurate results
Impacted file tree graph

@@               Coverage Diff                @@
##             7072_adj_diff     #137   +/-   ##
================================================
  Coverage                 ?   92.15%           
================================================
  Files                    ?        4           
  Lines                    ?      153           
  Branches                 ?        0           
================================================
  Hits                     ?      141           
  Misses                   ?       12           
  Partials                 ?        0           

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 f154807...5f0e331. Read the comment docs.

ops_serialized = _serialize_ops(tape, self.wire_map)

jac = adj.adjoint_jacobian(
*obs_serialized, *ops_serialized, tape.trainable_params, tape.num_params
Copy link
Member

Choose a reason for hiding this comment

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

This is still up for debate, but I think we can pass in the tuples directly to CPP, without incurring the expansion overhead.

Suggested change
*obs_serialized, *ops_serialized, tape.trainable_params, tape.num_params
obs_serialized, ops_serialized, tape.trainable_params, tape.num_params

and I can unpack them in CPP. I have already made some helper struct to simplify data passing around here, so this might just be tidier. I'll let you know once I have it bound up.

@mlxd mlxd marked this pull request as ready for review August 27, 2021 07:59
@mlxd
Copy link
Member

mlxd commented Aug 27, 2021

Thanks Tom! Looks good to merge into the C++ branch. I'll tidy up the testing once there.

@mlxd mlxd merged commit 75530bd into 7072_adj_diff Aug 27, 2021
@mlxd mlxd deleted the adj_method_python branch August 27, 2021 08:00
mlxd added a commit that referenced this pull request Sep 13, 2021
* Add inner product routine with STL and BLAS options

* Add prelim adj diff implementation

* Refactor build-system structure to enable better extensibility

* Add explicit build support for algorithms

* Clean Util cmake

* Add explicit overload resolution to innerProd

* Add build support for AdjointDiff

* Update testing for new utils

* Ensure formatting is run in nested dirs

* Add cout functionality for StateVector

* Add dot for conjugated and non conjugated data

* Begin dev of adjoint diff tests

* Add additional tests to util suite

* Attempt debugging of multi-obs issues

* Ensure FPIC on for generated .a libs

* Fix native flag in CMake

* Ensure propagation of flags to lower dirs

* Update build flags

* Add additional testing

* Update tests

* Encapsulate ops and obs data for Python serialization

* Restructure the obs and ops data for adjoint calcs

* Lint and add defines

* Fix testing binary location

* Attempt to appease codefactor

* Fix memory alignment errors on output for adj

* Fix broken tests due to MVP

* Add adjoint method to Python frontend (#137)

* Add observable serialization

* Add to lightning

* Update

* Add operation serialization

* add framework

* Apply black

* Add tests for obs_has_kernel

* Add tests for _serialize_obs

* Add wires

* Add

* Rename to _obs_has_kernel_

* Add tests

* Adapt tests to lightning

* Update obs

* Update serialization

* Potential facepalm moment

* Revert "Potential facepalm moment"

This reverts commit 4230615.

* Revert "Update serialization"

This reverts commit 38352c2.

* Revert "Update obs"

This reverts commit ee7a377.

* Update

* Update

* Add support for statevector with own managed memory

* Add param gateset tests for SVM

* Fixed memory access issues with memory managed statevector

* Fix C++ adjoint calls

* Update parallelisation using OpenMP

* Update Python and run black

* Fix serialisation for tensor expvals

* Ensure statevector is linear 1D array before offloading to C++

* Add repr bindings for improved debugging

* Enable OpenMP for observables

* Ensure OpenMP is optional requirement

* Fix vector stream formatting

* Move and format bindings

* Aim to appease codefactor

* Offload StateVectorManaged to separate file

* Readd missing file

* Avoid loading cmath before math defines for Windows

* Add defines to compiler rather than source

* Add guards for C++ binding utility modules import

* Add comments to AdjointDiff to silence codefactor

* Add ostream for statevectors

* Add ostream for vector and sets

* Improve performance of Adj method

* Ensure set passed to C++ layer

* Simplify call structure

* Tidy loop structure

* Update Obs class for float and complex data

* Track updated Obs structure

* Add variant support for observables from Python

* Allow support for "Hermitian" observables

* Add support for mixing of observable types

* Fix serialization tests for adjoint method (#141)

* Update tests

* Add problematic statements

* Fix tests

* Fix type hinting

* Make function as expected

* Add quick return for no jacobian

* Move position

* Add raise for non supported ops

* Ensure jacobian shape formatted as expected

* Return jacobian directly as numpy array

* Ensure correct return type of jacobian

* Ensure param number tracking is correct for adjjac

* Fix CRY gate index

* All tests passing

* Calculate parametric ops when creating opsdata object

* Apply formatting

* Ensure MacOS wheel builder uses a more modern compiler toolchain

* Fix mac wheel builder

Co-authored-by: Lee J. O'Riordan <loriordan@gmail.com>

* Fix compilation

* Add new integration test for adjoint jacobian (#142)

* Add test for dev pl

* Add test

* Move to original tests

* Add additional ops creation method

* Fix QFT errors

* Reformat

* Revert "Fix QFT errors"

This reverts commit f62a763.

* Preclude certain gates

* Update test

* Add double comments

* Update test

* Add tests for standard and custom wire labels

* Remove print

* Extend tests for RX,RY

* Prevent trainable params from going negative

* Ensure correct coef applied when using generator

* Update Ops repr

* Reenable tests

* Update CI for non compiled builds

* Add exception for Projector observable

* Add Hermitian in tensor product

* Ensure data is passed as complex128 to cpp

* Run black

* Ensure serialisation of numpy data is cast correctly

* Remove redundant methods

* Add support to get obs data

* Fix serialize test array structures

* Add hermitian checks

* Ensure testing complete for current requirements

* Reformat bindings

* Skip test for Hermitian on default

* Ensure bin available passed as class param

* Skip for non binary tests

Co-authored-by: Lee J. O'Riordan <loriordan@gmail.com>

* Update pennylane_lightning/src/algorithms/AdjointDiff.hpp

Co-authored-by: Tom Bromley <49409390+trbromley@users.noreply.github.com>

* Update pennylane_lightning/src/simulator/StateVectorManaged.hpp

Co-authored-by: Tom Bromley <49409390+trbromley@users.noreply.github.com>

* Update pennylane_lightning/src/util/Error.hpp

Co-authored-by: Tom Bromley <49409390+trbromley@users.noreply.github.com>

* Update pennylane_lightning/src/algorithms/AdjointDiff.hpp

Co-authored-by: Tom Bromley <49409390+trbromley@users.noreply.github.com>

* Update pennylane_lightning/src/algorithms/AdjointDiff.hpp

Co-authored-by: Tom Bromley <49409390+trbromley@users.noreply.github.com>

* Fix typos and remove comments

* Update changelog

* Fix codecov reduction

* Trigger build

* CodeCov fix

Co-authored-by: Tom Bromley <49409390+trbromley@users.noreply.github.com>
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.

2 participants