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

(LK-C-2) Add controlled named 2/4-qubit gate (e.g. NCIsingXX) support to Lightning Kokkos #953

Merged
merged 61 commits into from
Nov 12, 2024
Merged
Show file tree
Hide file tree
Changes from 56 commits
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
4b9062e
initial commit
josephleekl Oct 18, 2024
ba70971
initial commit
josephleekl Oct 18, 2024
6ac216a
support controlled 1 qubit gate
josephleekl Oct 18, 2024
bea8bf7
add controlled globalphase test
josephleekl Oct 18, 2024
38c48b9
fix controlled globalphase return
josephleekl Oct 18, 2024
968b86e
format
josephleekl Oct 18, 2024
8c97d82
format
josephleekl Oct 18, 2024
09b07d5
format
josephleekl Oct 19, 2024
a7106b7
add globalphase python test
josephleekl Oct 19, 2024
34e6400
apply controlled only for 1 qubit gate
josephleekl Oct 21, 2024
b1263fa
format
josephleekl Oct 21, 2024
1245270
trigger CI
josephleekl Oct 21, 2024
7ebee0f
fix parity_2_offset to kokkos_inline_function
josephleekl Oct 21, 2024
cec599b
separate generate/control bit patterns
josephleekl Oct 22, 2024
a01b38a
format
josephleekl Oct 22, 2024
8dec286
initial commit
josephleekl Oct 18, 2024
17ef49b
support 2/3/4 qubit control gates
josephleekl Oct 19, 2024
e3911c3
update statevectorkokkos error
josephleekl Oct 19, 2024
a136669
update statevectorkokkos error
josephleekl Oct 19, 2024
bead29b
test control=wire exception
josephleekl Oct 19, 2024
aa944b0
remove controlled toffoli matrix test
josephleekl Oct 19, 2024
b98a2a1
fix disable control qubitunitary/blockencode
josephleekl Oct 21, 2024
bde08d0
format
josephleekl Oct 21, 2024
35b048a
fix disable multiRZ
josephleekl Oct 21, 2024
993a6f1
separate generate/controlbitpatterns
josephleekl Oct 22, 2024
3fb1ec0
add fail matrix test
josephleekl Oct 23, 2024
92f8939
clean up
josephleekl Oct 23, 2024
29d7136
update test
josephleekl Oct 23, 2024
0a4b71d
edit state_vector.py
josephleekl Oct 23, 2024
2a2c4f9
recover c-globalphase + check target_wire=1
josephleekl Oct 23, 2024
e4e534f
format
josephleekl Oct 23, 2024
d0e75e3
accept list of controlled op
josephleekl Oct 24, 2024
193338c
add control H/T/S/phaseshift test
josephleekl Oct 24, 2024
3367a4b
update globalphase impl
josephleekl Oct 24, 2024
79d5c01
update ali comments
josephleekl Oct 30, 2024
3a99c5a
update comments
josephleekl Oct 31, 2024
4dd344e
update comments
josephleekl Oct 31, 2024
465c46c
update to std::ranges::views
josephleekl Oct 31, 2024
bb46635
revert std::view change
josephleekl Oct 31, 2024
e148462
add tests with 2 control wires
josephleekl Nov 1, 2024
c79d411
format
josephleekl Nov 1, 2024
6c08fbd
fix maybe_unused attribute from lambda to func body
josephleekl Nov 1, 2024
ecd8677
update lightning_kokkos.toml
josephleekl Nov 1, 2024
a250a76
format
josephleekl Nov 1, 2024
0e160bd
update basicgatefunctors
josephleekl Nov 6, 2024
9502b78
update lambda capture by value
josephleekl Nov 7, 2024
498802e
implement comments
josephleekl Nov 7, 2024
3d1e859
make format
josephleekl Nov 8, 2024
a69a4b5
merge with lk-control-base
josephleekl Nov 8, 2024
f25011b
merge with lk-control-1Q
josephleekl Nov 8, 2024
cc45e61
fix merge issues
josephleekl Nov 8, 2024
fedd270
format
josephleekl Nov 8, 2024
10a18bb
update gate functors and toml
josephleekl Nov 8, 2024
82b0b85
add tests
josephleekl Nov 8, 2024
240500e
Merge branch 'lk-control-base' into lk-control-gate-23Q
josephleekl Nov 9, 2024
020c215
fix merge squash
josephleekl Nov 9, 2024
b33d680
update alfredo comments
josephleekl Nov 11, 2024
b2e278c
update ali comment test instance
josephleekl Nov 12, 2024
9d93fe4
add qml.ctrl test comment
josephleekl Nov 12, 2024
d59df2f
update shuli/ali comments
josephleekl Nov 12, 2024
3f1d800
add util:: namespace
josephleekl Nov 12, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pennylane_lightning/core/_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@
Version number (major.minor.patch[-label])
"""

__version__ = "0.40.0-dev6"
__version__ = "0.40.0-dev4"

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -1083,6 +1083,102 @@ TEMPLATE_TEST_CASE("StateVectorKokkos::applyOperation non-param "
}
}

TEMPLATE_TEST_CASE("StateVectorKokkos::applyOperation non-param "
"two-qubit with controls",
"[StateVectorKokkos_NonParam]", float, double) {
using StateVectorT = StateVectorKokkos<TestType>;

const TestType EP = 1e-4;
const std::size_t num_qubits = 4;
const bool inverse = GENERATE(true, false);
const std::size_t control = GENERATE(0, 1, 2, 3);
const std::size_t wire0 = GENERATE(0, 1, 2, 3);
const std::size_t wire1 = GENERATE(0, 1, 2, 3);

auto ini_st = createNonTrivialState<StateVectorT>(num_qubits);

SECTION("N-controlled SWAP") {
if (control != wire0 && control != wire1 && wire0 != wire1) {

StateVectorT kokkos_sv0{ini_st.data(), ini_st.size()};
StateVectorT kokkos_sv1{ini_st.data(), ini_st.size()};
kokkos_sv0.applyOperation("CSWAP", {control, wire0, wire1},
inverse);
auto matrix = getSWAP<Kokkos::complex, TestType>();
kokkos_sv1.applyOperation("SWAP", std::vector<std::size_t>{control},
std::vector<bool>{true},
std::vector<std::size_t>{wire0, wire1},
inverse);
auto result_sv0 = kokkos_sv0.getDataVector();
auto result_sv1 = kokkos_sv1.getDataVector();
for (std::size_t j = 0; j < exp2(num_qubits); j++) {
CHECK(real(result_sv0[j]) ==
Approx(real(result_sv1[j])).margin(EP));
CHECK(imag(result_sv0[j]) ==
Approx(imag(result_sv1[j])).margin(EP));
}
}
}
}

TEMPLATE_TEST_CASE("StateVectorKokkos::applyOperation non-param "
"two-qubit with multiple-controls",
"[StateVectorKokkos_NonParam]", float, double) {
SECTION("2-controlled SWAP") {
using ComplexT = StateVectorKokkos<TestType>::ComplexT;
const std::size_t num_qubits = 4;

std::vector<ComplexT> ini_st{ComplexT{0.33377149, 0.2511291},
ComplexT{0.33013572, -0.14778699},
ComplexT{0.17288832, -0.041744},
ComplexT{0.11004883, -0.15105962},
ComplexT{0.17120967, 0.04376507},
ComplexT{0.33010645, 0.20088901},
ComplexT{-0.12770624, -0.17329647},
ComplexT{-0.34301996, 0.11944278},
ComplexT{0.0195779, -0.03687076},
ComplexT{0.34155068, 0.07464519},
ComplexT{0.00730597, 0.03670807},
ComplexT{0.08876188, -0.18019018},
ComplexT{-0.04946055, -0.10383813},
ComplexT{0.0715367, 0.04895361},
ComplexT{-0.12377521, -0.04781011},
ComplexT{-0.14509767, 0.2102171}};

std::vector<ComplexT> expected{ComplexT{0.33377149, 0.2511291},
ComplexT{0.33013572, -0.14778699},
ComplexT{0.17288832, -0.041744},
ComplexT{0.11004883, -0.15105962},
ComplexT{0.17120967, 0.04376507},
ComplexT{0.33010645, 0.20088901},
ComplexT{-0.12770624, -0.17329647},
ComplexT{-0.34301996, 0.11944278},
ComplexT{0.0195779, -0.03687076},
ComplexT{-0.04946055, -0.10383813},
ComplexT{0.00730597, 0.03670807},
ComplexT{0.08876188, -0.18019018},
ComplexT{0.34155068, 0.07464519},
ComplexT{0.0715367, 0.04895361},
ComplexT{-0.12377521, -0.04781011},
ComplexT{-0.14509767, 0.2102171}};

SECTION("Apply using dispatcher") {
StateVectorKokkos<TestType> kokkos_sv{num_qubits};
std::vector<ComplexT> result_sv(kokkos_sv.getLength(), {0, 0});

kokkos_sv.HostToDevice(ini_st.data(), ini_st.size());
kokkos_sv.applyOperation("SWAP", {0, 2}, {true, false}, {1, 3},
false);
kokkos_sv.DeviceToHost(result_sv.data(), result_sv.size());

for (std::size_t j = 0; j < exp2(num_qubits); j++) {
CHECK(imag(expected[j]) == Approx(imag(result_sv[j])));
CHECK(real(expected[j]) == Approx(real(result_sv[j])));
}
}
}
}

TEMPLATE_TEST_CASE("StateVectorKokkos::SetStateVector",
"[StateVectorKokkos_Nonparam]", float, double) {
using PrecisionT = TestType;
Expand Down
Loading
Loading