Skip to content

Commit

Permalink
Linted files.
Browse files Browse the repository at this point in the history
Signed-off-by: kvmto <[email protected]>
  • Loading branch information
kvmto committed Jan 30, 2025
1 parent b763bd1 commit 8cec893
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 34 deletions.
35 changes: 15 additions & 20 deletions libs/solvers/lib/operators/operator_pools/uccsd_operator_pool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,10 @@ uccsd::generate(const heterogeneous_map &config) const {
for (std::size_t i = p + 1; i < q; i++)
o *= cudaq::spin::z(i);

cudaq::spin_op t = cudaq::spin::y(p) * o * cudaq::spin::x(q) - cudaq::spin::x(p) * o * cudaq::spin::y(q);
ops.emplace_back(cudaq::spin::y(p) * o * cudaq::spin::x(q) - cudaq::spin::x(p) * o * cudaq::spin::y(q));
cudaq::spin_op t = cudaq::spin::y(p) * o * cudaq::spin::x(q) -
cudaq::spin::x(p) * o * cudaq::spin::y(q);
ops.emplace_back(cudaq::spin::y(p) * o * cudaq::spin::x(q) -
cudaq::spin::x(p) * o * cudaq::spin::y(q));
};

auto addDoublesExcitation = [numQubits](std::vector<cudaq::spin_op> &ops,
Expand Down Expand Up @@ -78,31 +80,24 @@ uccsd::generate(const heterogeneous_map &config) const {

for (std::size_t i = a_virt + 1; i < b_virt; i++)
parity_b *= cudaq::spin::z(i);
auto op_term_temp = cudaq::spin::x(i_occ) * parity_a * cudaq::spin::x(j_occ) *
cudaq::spin::x(a_virt) * parity_b *
cudaq::spin::y(b_virt);

auto op_term_temp = cudaq::spin::x(i_occ) * parity_a *
cudaq::spin::x(j_occ) * cudaq::spin::x(a_virt) *
parity_b * cudaq::spin::y(b_virt);
op_term_temp += cudaq::spin::x(i_occ) * parity_a * cudaq::spin::x(j_occ) *
cudaq::spin::y(a_virt) * parity_b *
cudaq::spin::x(b_virt);
cudaq::spin::y(a_virt) * parity_b * cudaq::spin::x(b_virt);
op_term_temp += cudaq::spin::x(i_occ) * parity_a * cudaq::spin::y(j_occ) *
cudaq::spin::y(a_virt) * parity_b *
cudaq::spin::y(b_virt);
cudaq::spin::y(a_virt) * parity_b * cudaq::spin::y(b_virt);
op_term_temp += cudaq::spin::y(i_occ) * parity_a * cudaq::spin::x(j_occ) *
cudaq::spin::y(a_virt) * parity_b *
cudaq::spin::y(b_virt);
cudaq::spin::y(a_virt) * parity_b * cudaq::spin::y(b_virt);
op_term_temp -= cudaq::spin::x(i_occ) * parity_a * cudaq::spin::y(j_occ) *
cudaq::spin::x(a_virt) * parity_b *
cudaq::spin::x(b_virt);
cudaq::spin::x(a_virt) * parity_b * cudaq::spin::x(b_virt);
op_term_temp -= cudaq::spin::y(i_occ) * parity_a * cudaq::spin::x(j_occ) *
cudaq::spin::x(a_virt) * parity_b *
cudaq::spin::x(b_virt);
cudaq::spin::x(a_virt) * parity_b * cudaq::spin::x(b_virt);
op_term_temp -= cudaq::spin::y(i_occ) * parity_a * cudaq::spin::y(j_occ) *
cudaq::spin::x(a_virt) * parity_b *
cudaq::spin::y(b_virt);
cudaq::spin::x(a_virt) * parity_b * cudaq::spin::y(b_virt);
op_term_temp -= cudaq::spin::y(i_occ) * parity_a * cudaq::spin::y(j_occ) *
cudaq::spin::y(a_virt) * parity_b *
cudaq::spin::x(b_virt);
cudaq::spin::y(a_virt) * parity_b * cudaq::spin::x(b_virt);
ops.emplace_back(op_term_temp);
};

Expand Down
27 changes: 13 additions & 14 deletions libs/solvers/unittests/test_operator_pools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ TEST(UCCSDTest, GenerateWithDefaultConfig) {

auto operators = pool->generate(config);
ASSERT_FALSE(operators.empty());
EXPECT_EQ(operators.size(), 2 + 1);
EXPECT_EQ(operators.size(), 2 + 1);

for (const auto &op : operators) {
EXPECT_EQ(op.num_qubits(), 4);
Expand Down Expand Up @@ -51,16 +51,15 @@ TEST(UCCSDTest, GenerateWithCustomCoefficients) {
std::vector<std::complex<double>> temp_coeffs;
for (size_t i = 0; i < operators.size(); ++i) {
EXPECT_EQ(operators[i].num_qubits(), 4);

operators[i].for_each_term([&](const auto &term) {
temp_coeffs.push_back(term.get_coefficient());
});
temp_coeffs.push_back(term.get_coefficient());
});
}

for (size_t j = 0; j < temp_coeffs.size(); ++j)
EXPECT_DOUBLE_EQ(1.0, std::abs(temp_coeffs[j].real()));
//EXPECT_DOUBLE_EQ(1.0, operators[i].get_coefficient().real());

// EXPECT_DOUBLE_EQ(1.0, operators[i].get_coefficient().real());
}

TEST(UCCSDTest, GenerateWithOddElectrons) {
Expand Down Expand Up @@ -116,21 +115,21 @@ TEST(UccsdOperatorPoolTest, GeneratesCorrectOperators) {
}

// Assert
std::vector<std::string> expected_terms = {"XZYI", "YZXI", "IXZY", "IYZX",
"YYYX", "YXXX", "XXYX","YYXY",
"XYYY", "XXXY","YXYY", "XYXX"};
std::vector<std::string> expected_terms = {"XZYI", "YZXI", "IXZY", "IYZX",
"YYYX", "YXXX", "XXYX", "YYXY",
"XYYY", "XXXY", "YXYY", "XYXX"};

std::vector<std::string> expected_operators = {"XZYIYZXI","IXZYIYZX", "XXXYXXYXXYXXXYYYYXXXYXYYYYXYYYYX"};
std::vector<std::string> expected_operators = {
"XZYIYZXI", "IXZYIYZX", "XXXYXXYXXYXXXYYYYXXXYXYYYYXYYYYX"};

ASSERT_EQ(terms_strings.size(), expected_terms.size())
<< "Number of generated operators does not match expected count";

for (size_t i = 0; i < expected_terms.size(); ++i) {
EXPECT_EQ(terms_strings[i], expected_terms[i])
<< "Mismatch at index " << i;
EXPECT_EQ(terms_strings[i], expected_terms[i]) << "Mismatch at index " << i;
}

for(size_t i = 0; i < expected_operators.size(); ++i) {
for (size_t i = 0; i < expected_operators.size(); ++i) {
EXPECT_EQ(operator_strings[i], expected_operators[i])
<< "Mismatch operators at index " << i;
}
Expand Down

0 comments on commit 8cec893

Please sign in to comment.