Skip to content

Commit

Permalink
more testing at matrix level for product operators. only file left no…
Browse files Browse the repository at this point in the history
…w is operator sum

Signed-off-by: A.M. Santana <[email protected]>
  • Loading branch information
anthony-santana committed Jan 9, 2025
1 parent 008cf5b commit 560c8b6
Show file tree
Hide file tree
Showing 5 changed files with 695 additions and 262 deletions.
14 changes: 14 additions & 0 deletions unittests/dynamics/elementary_ops_arithmetic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,10 @@ TEST(ExpressionTester, checkPreBuiltElementaryOpsScalars) {
ASSERT_TRUE(product.term_count() == 2);
ASSERT_TRUE(reverse.term_count() == 2);

std::vector<int> want_degrees = {0};
ASSERT_TRUE(product.degrees() == want_degrees);
ASSERT_TRUE(reverse.degrees() == want_degrees);

/// Check the matrices.
/// FIXME: Comment me back in when `to_matrix` is implemented.

Expand Down Expand Up @@ -266,6 +270,10 @@ TEST(ExpressionTester, checkPreBuiltElementaryOpsScalars) {
ASSERT_TRUE(product.term_count() == 2);
ASSERT_TRUE(reverse.term_count() == 2);

std::vector<int> want_degrees = {0};
ASSERT_TRUE(product.degrees() == want_degrees);
ASSERT_TRUE(reverse.degrees() == want_degrees);

/// Check the matrices.
/// FIXME: Comment me back in when `to_matrix` is implemented.

Expand Down Expand Up @@ -378,6 +386,9 @@ TEST(ExpressionTester, checkPreBuiltElementaryOpsSelf) {
auto product = self * other;
ASSERT_TRUE(product.term_count() == 2);

std::vector<int> want_degrees = {0};
ASSERT_TRUE(product.degrees() == want_degrees);

/// Check the matrices.
/// FIXME: Comment me back in when `to_matrix` is implemented.

Expand All @@ -396,6 +407,9 @@ TEST(ExpressionTester, checkPreBuiltElementaryOpsSelf) {
auto product = self * other;
ASSERT_TRUE(product.term_count() == 2);

std::vector<int> want_degrees = {0, 1};
ASSERT_TRUE(product.degrees() == want_degrees);

/// Check the matrices.
/// FIXME: Comment me back in when `to_matrix` is implemented.

Expand Down
1 change: 0 additions & 1 deletion unittests/dynamics/elementary_ops_simple.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
#include "cudaq/operators.h"
#include <gtest/gtest.h>


namespace utils {
void checkEqual(cudaq::matrix_2 a, cudaq::matrix_2 b) {
ASSERT_EQ(a.get_rank(), b.get_rank());
Expand Down
127 changes: 0 additions & 127 deletions unittests/dynamics/operator_sum.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,133 +100,6 @@ cudaq::matrix_2 parity_matrix(std::size_t size) {

} // namespace utils_2

// TEST(ExpressionTester, checkProductOperatorSimple) {
// std::vector<int> levels = {2, 3, 4};

// // std::set<int> uniqueDegrees;
// // std::copy(this->degrees.begin(), this->degrees.end(),
// // std::inserter(uniqueDegrees, uniqueDegrees.begin()));
// // std::copy(other.degrees.begin(), other.degrees.end(),
// // std::inserter(uniqueDegrees, uniqueDegrees.begin()));

// // Arithmetic only between elementary operators with
// // same number of levels.
// {
// // Same degrees of freedom.
// {
// for (auto level_count : levels) {
// auto op0 = cudaq::elementary_operator::annihilate(0);
// auto op1 = cudaq::elementary_operator::create(0);

// cudaq::product_operator got = op0 * op1;
// auto got_matrix = got.to_matrix({{0, level_count}}, {});

// auto matrix0 = _annihilate_matrix(level_count);
// auto matrix1 = _create_matrix(level_count);
// auto want_matrix = matrix0 * matrix1;

// // ASSERT_TRUE(want_matrix == got_matrix);
// }
// }

// // // Different degrees of freedom.
// // {
// // for (auto level_count : levels) {
// // auto op0 = cudaq::elementary_operator::annihilate(0);
// // auto op1 = cudaq::elementary_operator::create(1);

// // cudaq::product_operator got = op0 * op1;
// // auto got_matrix =
// // got.to_matrix({{0, level_count}, {1, level_count}}, {});

// // cudaq::product_operator got_reverse = op1 * op0;
// // auto got_matrix_reverse =
// // got_reverse.to_matrix({{0, level_count}, {1, level_count}},
// {});

// // auto identity = _id_matrix(level_count);
// // auto matrix0 = _annihilate_matrix(level_count);
// // auto matrix1 = _create_matrix(level_count);

// // auto fullHilbert0 = identity.kronecker(matrix0);
// // auto fullHilbert1 = matrix1.kronecker(identity);
// // auto want_matrix = fullHilbert0 * fullHilbert1;
// // auto want_matrix_reverse = fullHilbert1 * fullHilbert0;

// // // ASSERT_TRUE(want_matrix == got_matrix);
// // // ASSERT_TRUE(want_matrix_reverse == got_matrix_reverse);
// // }
// // }

// // // Different degrees of freedom, non-consecutive.
// // {
// // for (auto level_count : levels) {
// // auto op0 = cudaq::elementary_operator::annihilate(0);
// // auto op1 = cudaq::elementary_operator::create(2);

// // // cudaq::product_operator got = op0 * op1;
// // // auto got_matrix =
// got.to_matrix({{0,level_count},{2,level_count}},
// // // {});
// // }
// // }

// // // Different degrees of freedom, non-consecutive but all dimensions
// // // provided.
// // {
// // for (auto level_count : levels) {
// // auto op0 = cudaq::elementary_operator::annihilate(0);
// // auto op1 = cudaq::elementary_operator::create(2);

// // // cudaq::product_operator got = op0 * op1;
// // // auto got_matrix =
// // //
// got.to_matrix({{0,level_count},{1,level_count},{2,level_count}},
// // {});
// // }
// // }
// }
// }

// TEST(ExpressionTester, checkProductOperatorSimple) {

// std::complex<double> value_0 = 0.1 + 0.1;
// std::complex<double> value_1 = 0.1 + 1.0;
// std::complex<double> value_2 = 2.0 + 0.1;
// std::complex<double> value_3 = 2.0 + 1.0;

// auto local_variable = true;
// auto function = [&](std::map<std::string, std::complex<double>> parameters)
// {
// if (!local_variable)
// throw std::runtime_error("Local variable not detected.");
// return parameters["value"];
// };

// // Scalar Ops against Elementary Ops
// {
// // Identity against constant.
// {
// auto id_op = cudaq::elementary_operator::identity(0);
// auto scalar_op = cudaq::scalar_operator(value_0);

// // auto multiplication = scalar_op * id_op;
// // auto addition = scalar_op + id_op;
// // auto subtraction = scalar_op - id_op;
// }

// // Identity against constant from lambda.
// {
// auto id_op = cudaq::elementary_operator::identity(0);
// auto scalar_op = cudaq::scalar_operator(function);

// // auto multiplication = scalar_op * id_op;
// // auto addition = scalar_op + id_op;
// // auto subtraction = scalar_op - id_op;
// }
// }
// }

TEST(ExpressionTester, checkOperatorSumAgainstScalarOperator) {

// `operator_sum * scalar_operator` and `scalar_operator * operator_sum`
Expand Down
Loading

0 comments on commit 560c8b6

Please sign in to comment.