Skip to content

Commit

Permalink
add gate_pauli, update_ops_dense_matrix, update_ops_pauli
Browse files Browse the repository at this point in the history
  • Loading branch information
Glacialte committed Dec 26, 2023
1 parent 2052510 commit a68af27
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 20 deletions.
6 changes: 4 additions & 2 deletions qulacs/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@ target_sources(qulacs PRIVATE
gate/gate_npair_qubit.cpp
gate/gate_one_control_one_target.cpp
gate/gate_one_qubit.cpp
gate/gate_pauli.cpp
gate/gate_quantum_matrix.cpp
gate/gate_two_qubit.cpp
gate/update_ops_matrix_dense_single.cpp
gate/update_ops_dense_matrix.cpp
gate/update_ops_npair_qubit.cpp
gate/update_ops_one_qubit.cpp
gate/update_ops_one_control_one_target.cpp
gate/update_ops_one_qubit.cpp
gate/update_ops_pauli.cpp
gate/update_ops_quantum_matrix.cpp
gate/update_ops_two_qubit.cpp
state/state_vector.cpp
Expand Down
13 changes: 13 additions & 0 deletions qulacs/gate/gate_pauli.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#include "gate_pauli.hpp"

#include "update_ops.hpp"

namespace qulacs {
void Pauli::update_quantum_state(StateVector& state_vector) const {
pauli_gate(this->target_qubit_index_list, this->pauli_id_list, state_vector);
}
void PauliRotation::update_quantum_state(StateVector& state_vector) const {
pauli_rotation_gate(
this->target_qubit_index_list, this->pauli_id_list, this->angle, state_vector);
}
} // namespace qulacs
28 changes: 28 additions & 0 deletions qulacs/gate/gate_pauli.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#pragma once

#include <vector>

#include "gate.hpp"

namespace qulacs {
class Pauli : public QuantumGate {
std::vector<UINT> target_qubit_index_list;
std::vector<UINT> pauli_id_list;

public:
Pauli(std::vector<UINT> target_list, std::vector<UINT> pauli_list)
: target_qubit_index_list(target_list), pauli_id_list(pauli_list) {}
void update_quantum_state(StateVector& state_vector) const override;
};

class PauliRotation : public QuantumGate {
std::vector<UINT> target_qubit_index_list;
std::vector<UINT> pauli_id_list;
double angle;

public:
PauliRotation(std::vector<UINT> target_list, std::vector<UINT> pauli_list, double angle)
: target_qubit_index_list(target_list), pauli_id_list(pauli_list), angle(angle) {}
void update_quantum_state(StateVector& state_vector) const override;
};
} // namespace qulacs
9 changes: 9 additions & 0 deletions qulacs/gate/update_ops.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,13 @@ void fusedswap_gate(UINT target_qubit_index_0,
UINT target_qubit_index_1,
UINT block_size,
StateVector& state);

void pauli_gate(std::vector<UINT> target_qubit_index_list,
std::vector<UINT> pauli_id_index,
StateVector& state);

void pauli_rotation_gate(std::vector<UINT> target_qubit_index_list,
std::vector<UINT> pauli_id_index,
double angle,
StateVector& state);
} // namespace qulacs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ void single_qubit_dense_matrix_gate(UINT target_qubit_index,
const UINT mask_high = ~mask_low;
auto amplitudes = state.amplitudes_raw();
Kokkos::parallel_for(
state.dim() - 1, KOKKOS_LAMBDA(const UINT it) {
state.dim() / 2, KOKKOS_LAMBDA(const UINT it) {
UINT basis_0 = (it & mask_low) + ((it & mask_high) << 1);
UINT basis_1 = basis_0 + mask;
Complex val0 = amplitudes[basis_0];
Expand Down
17 changes: 0 additions & 17 deletions qulacs/gate/update_ops_one_qubit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,23 +89,6 @@ void tdag_gate(UINT target_qubit_index, StateVector& state) {
single_qubit_phase_gate(target_qubit_index, Complex(1.0 / M_SQRT2, -1.0 / M_SQRT2), state);
}

void single_qubit_dense_matrix_gate(UINT target_qubit_index,
const std::array<Complex, 4> matrix,
StateVector& state) {
const UINT n_qubits = state.n_qubits();
const UINT low_mask = (1ULL << target_qubit_index) - 1;
const UINT high_mask = ~low_mask;
auto amplitudes = state.amplitudes_raw();
Kokkos::parallel_for(
1ULL << (n_qubits - 1), KOKKOS_LAMBDA(const UINT& it) {
UINT i = (it & high_mask) << 1 | (it & low_mask);
Complex cval_0 = amplitudes[i];
Complex cval_1 = amplitudes[i | (1ULL << target_qubit_index)];
amplitudes[i] = matrix[0] * cval_0 + matrix[1] * cval_1;
amplitudes[i | (1ULL << target_qubit_index)] = matrix[2] * cval_0 + matrix[3] * cval_1;
});
}

void sqrtx_gate(UINT target_qubit_index, StateVector& state) {
single_qubit_dense_matrix_gate(target_qubit_index, SQRT_X_GATE_MATRIX, state);
}
Expand Down
13 changes: 13 additions & 0 deletions qulacs/gate/update_ops_pauli.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#include <Kokkos_Core.hpp>
#include <Kokkos_StdAlgorithms.hpp>

#include "../types.hpp"
#include "update_ops.hpp"

namespace qulacs {
void pauli_gate(std::vector<UINT> target_qubit_index_list,
std::vector<UINT> pauli_id_list,
StateVector& state) {
//
}
} // namespace qulacs

0 comments on commit a68af27

Please sign in to comment.