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

Refactor the testing infrastructure for templated StateVector implementation #115

Merged
merged 26 commits into from
Jul 26, 2021

Conversation

mlxd
Copy link
Member

@mlxd mlxd commented Jul 22, 2021

Context: With the refactor of the StateVector implementation in PR #113 the existing test-suite and tooling required an overhaul. This PR replaces the previous C++ test suite using googletest, with a more maintainable version written using Catch2. These new tests leverage CMake, and will auto-install the Catch2 library and make it available at build-time.

Description of the Change: The files located at pennylane_lightning/src/tests have been largely replaced by a Catch2 implementation, which tests the newly refactored StateVector class and all contained operations. Explicit tests are added for each supported gate-type, and test with both complex<float> and complex<double> statevector backend data.

Benefits: This allows for a more streamlined testing process, and more easily extensible with additional modules that may be added to the package later. Reporting via CI is also provided. The testing will also be more thorough than the previous googletest version.

Possible Drawbacks: The testing file is large, and may incur more overhead than previous testing.

Related GitHub Issues: #113

@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 Jul 22, 2021

Test Report (C++) on Ubuntu

    1 files      1 suites   0s ⏱️
114 tests 114 ✔️ 0 💤 0 ❌
366 runs  366 ✔️ 0 💤 0 ❌

Results for commit 8e8b8fe.

♻️ This comment has been updated with latest results.

@mlxd mlxd changed the base branch from master to 7067-templated-float July 22, 2021 16:50
@mlxd
Copy link
Member Author

mlxd commented Jul 23, 2021

Note: this branch is a fork of branch associated with PR #113 and should be viewed also to accompany this review,. This PR will merge into branch 7067-templated-float and will be merged in here before any merge with master. Failing CI tests are also fixable with PR #116

@mlxd mlxd marked this pull request as ready for review July 23, 2021 10:31
@codecov
Copy link

codecov bot commented Jul 23, 2021

Codecov Report

Merging #115 (8e8b8fe) into master (515166e) will not change coverage.
The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master     #115   +/-   ##
=======================================
  Coverage   98.14%   98.14%           
=======================================
  Files           3        3           
  Lines          54       54           
=======================================
  Hits           53       53           
  Misses          1        1           
Impacted Files Coverage Δ
pennylane_lightning/lightning_qubit.py 97.95% <100.00%> (ø)

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 515166e...8e8b8fe. Read the comment docs.

@mlxd mlxd marked this pull request as draft July 23, 2021 11:40
@mlxd mlxd marked this pull request as ready for review July 23, 2021 13:23
@trbromley
Copy link
Contributor

[ch7076]

@mlxd mlxd changed the base branch from 7067-templated-float to master July 26, 2021 08:53
@mlxd mlxd changed the base branch from master to 7067-templated-float July 26, 2021 08:55
@mlxd mlxd merged commit f91f763 into 7067-templated-float Jul 26, 2021
@mlxd mlxd deleted the 7076-test-refactor branch July 26, 2021 09:11
mlxd added a commit that referenced this pull request Jul 28, 2021
* Initial reformat and templating of gate tests

* Redefine gate mappings with templates

* Record given state

* Move all gate classes to become StateVector methods

* Fix compile errors for SV

* Refactor gates implementation

* Enable vector param methods

* Enable label to gatename map

* Support dispatch directly from StateVector class

* Add apply methods to SV class

* Add log2 utility function

* Remove old file arch

* Ensure bindings build support for float and double sizes complex data

* Remove outdated tests for deleted modules

* Remove old definition headers

* Tidy dispatch map

* Replace header with correct type

* Ensure cpp17 is now used

* Remove unneeded files in compilation

* Ensure apply args are given in correct order

* Allow make test to be run from working dir without cleaning

* Fix cpp formatting

* Remove old code and fix codefactor complaints

* Add cast to enable wheel build on MacOS

* Enable MSVC intrinsics if using Windows

* Ensure C++17 as a requirement

* Fix compile-time ifdef

* Replace intrinsic with BSR

* Avoid intrinsics for portability

* Rename log2 function

* Add support for 64bit and 128 complex numbers from C++ backend

* Update bindings to allow class instantiation and method use

* Enable support for different precision parameters passed to backend

* Fix log2 change

* Fix binding names

* Remove io from statevector

* Refix the log2 -- replace with instrinsics later

* Update format and remove ununsed warnings

* Refactor the testing infrastructure for templated StateVector implementation (#115)

* Add preliminary catch2 support

* Move private methods to public for testing

* Overload applyOperations for param and non param calls

* Add testing support for X,Y,Z,H gates

* Add S, T gate tests

* Add support for RX,RY,RZ gate tests

* Add PhaseShift gate tests

* Add Rot tests

* Add CNOT tests

* Add support for CSWAP, Toffoli, CZ, CRot tests

* Update testing CI

* Fix CodeFactor complaints

* Update CI image before running tests

* Favour use of reverse iterator over counter in for loops

* Fix contructor tests

* Fix formatting

* Fix narrowing complaints

* Fix MSVC math errors

* Run black

* Remove unneeded ops for real*complex products

* Fix test builder

* Ensure cmake has a version to avoid warnings

* Fix formatting of SV

* Fix test reporting

* Remove whitespace for CF complaints

* Apply static analyser fixes

* Add imaginary utils

* Refactor gate implementation and utility definitions

* Fix RY gate defn

* Add compile-time complex multiplication functions

* Use gate definition functions in tests and add constexpr where applicable

* Remove outdated test utilities and tests

* Update changelog

* Port ControlledPhaseShift to new simulator structure

* Add ControlledPhaseShift method to bindings

* Ensure tests are run using cmake

* Rename label CPhaseShift to ControlledPhasedShift
mlxd added a commit that referenced this pull request Aug 9, 2021
…ector from Python (#121)

* Initial reformat and templated of gate tests

* Redefine gate mappings with templates

* Record given state

* Move all gate classes to become StateVector methods

* Fix compile errors for SV

* Refactor gates implementation

* Enable vector param methods

* Enable label to gatename map

* Support dispatch directly from StateVector class

* Add apply methods to SV class

* Add log2 utility function

* Remove old file arch

* Ensure bindings build support for float and double sizes complex data

* Remove outdated tests for deleted modules

* Remove old definition headers

* Tidy dispatch map

* Replace header with correct type

* Ensure cpp17 is now used

* Remove unneeded files in compilation

* Ensure apply args are given in correct order

* Allow make test to be run from working dir without cleaning

* Fix cpp formatting

* Remove old code and fix codefactor complaints

* Add cast to enable wheel build on MacOS

* Enable MSVC intrinsics if using Windows

* Ensure C++17 as a requirement

* Fix compile-time ifdef

* Replace intrinsic with BSR

* Avoid intrinsics for portability

* Rename log2 function

* Add support for 64bit and 128 complex numbers from C++ backend

* Update bindings to allow class instantiation and method use

* Enable support for different precision parameters passed to backend

* Fix log2 change

* Fix binding names

* Remove io from statevector

* Refix the log2 -- replace with instrinsics later

* Update format and remove ununsed warnings

* Refactor the testing infrastructure for templated StateVector implementation (#115)

* Add preliminary catch2 support

* Move private methods to public for testing

* Overload applyOperations for param and non param calls

* Add testing support for X,Y,Z,H gates

* Add S, T gate tests

* Add support for RX,RY,RZ gate tests

* Add PhaseShift gate tests

* Add Rot tests

* Add CNOT tests

* Add support for CSWAP, Toffoli, CZ, CRot tests

* Update testing CI

* Fix CodeFactor complaints

* Update CI image before running tests

* Favour use of reverse iterator over counter in for loops

* Fix contructor tests

* Fix formatting

* Fix narrowing complaints

* Fix MSVC math errors

* Run black

* Remove unneeded ops for real*complex products

* Fix test builder

* Ensure cmake has a version to avoid warnings

* Fix formatting of SV

* Fix test reporting

* Remove whitespace for CF complaints

* Apply static analyser fixes

* Add imaginary utils

* Refactor gate implementation and utility definitions

* Fix RY gate defn

* Add compile-time complex multiplication functions

* Use gate definition functions in tests and add constexpr where applicable

* Remove outdated test utilities and tests

* Update changelog

* Begin support additions fotr arbitrary unitary application

* Enable subproject test builds

* Enable standalone CPP library header

* Update sizing checks for arbitrary unitary application

* Add additional utility functions

* Add tests for arbitrary unitary application

* Add tests for utils and helper functions

* Add testing and safety checks for utilities

* Remove LAPACK from build system

* Add placeholder functions for gate multiplication

* Format TestHelpers

* Format utility tests

* Add unitary apply to bindings

* Remove unneeded functions

* Relabel matrix applicator methods

* Appease the codefactor

* Split tests into param and nonparam

* Add support for numpy 2D array gate data without copies

* Appease codefactor

* Offload dim check to util function

* Add docstring for utility functions

* Codefactor fixes
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