-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
204 additions
and
20 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#include "gate_pauli.hpp" | ||
|
||
#include "../operator/pauli_operator.hpp" | ||
#include "update_ops.hpp" | ||
|
||
namespace qulacs { | ||
namespace internal { | ||
|
||
void PauliGateImpl::update_quantum_state(StateVector& state_vector) const { | ||
pauli_gate(this->_pauli, state_vector); | ||
} | ||
|
||
void PauliRotationGateImpl::update_quantum_state(StateVector& state_vector) const { | ||
pauli_rotation_gate(this->_pauli, this->_angle, state_vector); | ||
} | ||
|
||
} // namespace internal | ||
} // namespace qulacs |
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,55 @@ | ||
#pragma once | ||
|
||
#include <vector> | ||
|
||
#include "../operator/pauli_operator.hpp" | ||
#include "gate.hpp" | ||
|
||
namespace qulacs { | ||
namespace internal { | ||
class PauliGateImpl : public GateBase { | ||
PauliOperator* _pauli; | ||
std::vector<UINT> _target_index_list, _pauli_id_list; | ||
|
||
public: | ||
PauliGateImpl(PauliOperator* pauli) { | ||
_pauli = pauli; | ||
_target_index_list = _pauli->get_target_qubit_list(); | ||
_pauli_id_list = _pauli->get_pauli_id_list(); | ||
}; | ||
|
||
std::vector<UINT> get_target_qubit_list() const override { return _target_index_list; } | ||
std::vector<UINT> get_control_qubit_list() const override { return {}; } | ||
|
||
Gate copy() const override { return std::make_shared<PauliGateImpl>(*this); } | ||
Gate get_inverse() const override { return std::make_shared<PauliGateImpl>(*this); } | ||
|
||
void update_quantum_state(StateVector& state_vector) const override; | ||
}; | ||
|
||
class PauliRotationGateImpl : public GateBase { | ||
PauliOperator* _pauli; | ||
double _angle; | ||
std::vector<UINT> _target_index_list, _pauli_id_list; | ||
|
||
public: | ||
PauliRotationGateImpl(PauliOperator* pauli, double angle) { | ||
_pauli = pauli; | ||
_angle = angle; | ||
_target_index_list = _pauli->get_target_qubit_list(); | ||
_pauli_id_list = _pauli->get_pauli_id_list(); | ||
}; | ||
|
||
std::vector<UINT> get_target_qubit_list() const override { return _target_index_list; } | ||
std::vector<UINT> get_control_qubit_list() const override { return {}; } | ||
|
||
Gate copy() const override { return std::make_shared<PauliRotationGateImpl>(*this); } | ||
Gate get_inverse() const override { return std::make_shared<PauliRotationGateImpl>(*this); } | ||
|
||
void update_quantum_state(StateVector& state_vector) const override; | ||
}; | ||
} // namespace internal | ||
|
||
using PauliGate = internal::GatePtr<internal::PauliGateImpl>; | ||
using PauliRotationGate = internal::GatePtr<internal::PauliRotationGateImpl>; | ||
} // namespace qulacs |
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,63 @@ | ||
#include <Kokkos_Core.hpp> | ||
#include <Kokkos_StdAlgorithms.hpp> | ||
|
||
#include "../constant.hpp" | ||
#include "../operator/pauli_operator.hpp" | ||
#include "../types.hpp" | ||
#include "update_ops.hpp" | ||
|
||
namespace qulacs { | ||
void pauli_gate(PauliOperator* pauli, StateVector& state) { pauli->apply_to_state(state); } | ||
|
||
void pauli_rotation_gate(PauliOperator* pauli, double angle, StateVector& state) { | ||
auto [bit_flip_mask_vector, phase_flip_mask_vector] = pauli->get_XZ_mask_representation(); | ||
UINT bit_flip_mask = bit_flip_mask_vector.data_raw()[0]; | ||
UINT phase_flip_mask = phase_flip_mask_vector.data_raw()[0]; | ||
UINT global_phase_90_rot_count = std::popcount(bit_flip_mask & phase_flip_mask); | ||
const double cosval = cos(angle / 2); | ||
const double sinval = sin(angle / 2); | ||
const Complex coef = pauli->get_coef(); | ||
const auto& amplitudes = state.amplitudes_raw(); | ||
if (bit_flip_mask == 0) { | ||
Kokkos::parallel_for( | ||
state.dim(), KOKKOS_LAMBDA(const UINT& state_idx) { | ||
if (Kokkos::popcount(state_idx & phase_flip_mask) & 1) { | ||
amplitudes[state_idx] *= cosval - Complex(0, 1) * sinval; | ||
} else { | ||
amplitudes[state_idx] *= cosval + Complex(0, 1) * sinval; | ||
} | ||
amplitudes[state_idx] *= coef; | ||
}); | ||
return; | ||
} else { | ||
const UINT mask = 1 << bit_flip_mask_vector.msb(); | ||
const UINT mask_low = mask - 1; | ||
const UINT mask_high = ~mask_low; | ||
Kokkos::parallel_for( | ||
state.dim(), KOKKOS_LAMBDA(const UINT& state_idx) { | ||
UINT basis_0 = (state_idx & mask_low) + ((state_idx & mask_high) << 1); | ||
UINT basis_1 = basis_0 ^ bit_flip_mask; | ||
|
||
int bit_parity_0 = Kokkos::popcount(basis_0 & phase_flip_mask) % 2; | ||
int bit_parity_1 = Kokkos::popcount(basis_1 & phase_flip_mask) % 2; | ||
|
||
// fetch values | ||
Complex cval_0 = amplitudes[basis_0]; | ||
Complex cval_1 = amplitudes[basis_1]; | ||
|
||
// set values | ||
amplitudes[basis_0] = | ||
cosval * cval_0 + | ||
Complex(0, 1) * sinval * cval_1 * | ||
(PHASE_M90ROT()).val[(global_phase_90_rot_count + bit_parity_0 * 2) % 4]; | ||
amplitudes[basis_1] = | ||
cosval * cval_1 + | ||
Complex(0, 1) * sinval * cval_0 * | ||
(PHASE_M90ROT()).val[(global_phase_90_rot_count + bit_parity_1 * 2) % 4]; | ||
amplitudes[basis_0] *= coef; | ||
amplitudes[basis_1] *= coef; | ||
}); | ||
} | ||
} | ||
|
||
} // namespace qulacs |
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 was deleted.
Oops, something went wrong.
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