-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support to apply unitary and non-unitary gates directly to StateV…
…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
- Loading branch information
Showing
9 changed files
with
990 additions
and
421 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
#include <complex> | ||
#include <vector> | ||
|
||
/** | ||
* @brief Utility function to compare complex statevector data. | ||
* | ||
* @tparam Data_t Floating point data-type. | ||
* @param data1 StateVector data 1. | ||
* @param data2 StateVector data 2. | ||
* @return true Data are approximately equal. | ||
* @return false Data are not approximately equal. | ||
*/ | ||
template <class Data_t> | ||
inline bool isApproxEqual( | ||
const std::vector<Data_t> &data1, const std::vector<Data_t> &data2, | ||
const typename Data_t::value_type eps = | ||
std::numeric_limits<typename Data_t::value_type>::epsilon() * 100) { | ||
if (data1.size() != data2.size()) | ||
return false; | ||
|
||
for (size_t i = 0; i < data1.size(); i++) { | ||
if (data1[i].real() != Approx(data2[i].real()).epsilon(eps) || | ||
data1[i].imag() != Approx(data2[i].imag()).epsilon(eps)) { | ||
return false; | ||
} | ||
} | ||
return true; | ||
} | ||
|
||
/** | ||
* @brief Utility function to compare complex statevector data. | ||
* | ||
* @tparam Data_t Floating point data-type. | ||
* @param data1 StateVector data 1. | ||
* @param data2 StateVector data 2. | ||
* @return true Data are approximately equal. | ||
* @return false Data are not approximately equal. | ||
*/ | ||
template <class Data_t> | ||
inline bool | ||
isApproxEqual(const Data_t &data1, const Data_t &data2, | ||
const typename Data_t::value_type eps = | ||
std::numeric_limits<typename Data_t::value_type>::epsilon() * | ||
100) { | ||
if (data1.real() != Approx(data2.real()).epsilon(eps) || | ||
data1.imag() != Approx(data2.imag()).epsilon(eps)) { | ||
return false; | ||
} | ||
return true; | ||
} | ||
|
||
/** | ||
* @brief Multiplies every value in a dataset by a given complex scalar value. | ||
* | ||
* @tparam Data_t Precision of complex data type. Supports float and double | ||
* data. | ||
* @param data Data to be scaled. | ||
* @param scalar Scalar value. | ||
*/ | ||
template <class Data_t> | ||
void scaleVector(std::vector<std::complex<Data_t>> &data, | ||
std::complex<Data_t> scalar) { | ||
std::transform( | ||
data.begin(), data.end(), data.begin(), | ||
[scalar](const std::complex<Data_t> &c) { return c * scalar; }); | ||
} |
Oops, something went wrong.