-
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.
Merge pull request #27 from Qulacs-Osaka/26-add-ugate
26 add ugate
- Loading branch information
Showing
11 changed files
with
178 additions
and
4 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
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,17 @@ | ||
#include "gate_quantum_matrix.hpp" | ||
|
||
#include "update_ops.hpp" | ||
|
||
namespace qulacs { | ||
void U1::update_quantum_state(StateVector& state_vector) const { | ||
u_gate(this->_target, this->_matrix, state_vector); | ||
} | ||
|
||
void U2::update_quantum_state(StateVector& state_vector) const { | ||
u_gate(this->_target, this->_matrix, state_vector); | ||
} | ||
|
||
void U3::update_quantum_state(StateVector& state_vector) const { | ||
u_gate(this->_target, this->_matrix, state_vector); | ||
} | ||
} // 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,45 @@ | ||
#pragma once | ||
|
||
#include <vector> | ||
|
||
#include "constant.hpp" | ||
#include "gate.hpp" | ||
#include "update_ops.hpp" | ||
|
||
namespace qulacs { | ||
class U1 : public QuantumGate { | ||
UINT _target; | ||
double _lambda; | ||
std::array<Complex, 4> _matrix; | ||
|
||
public: | ||
U1(UINT target, UINT lambda) : _target(target), _lambda(lambda) { | ||
_matrix = get_IBMQ_matrix(0, 0, lambda); | ||
}; | ||
void update_quantum_state(StateVector& state_vector) const override; | ||
}; | ||
class U2 : public QuantumGate { | ||
UINT _target; | ||
double _lambda, _phi; | ||
std::array<Complex, 4> _matrix; | ||
|
||
public: | ||
U2(UINT target, UINT phi, UINT lambda) : _target(target), _phi(phi), _lambda(lambda) { | ||
_matrix = get_IBMQ_matrix(PI / 2.0, phi, lambda); | ||
}; | ||
void update_quantum_state(StateVector& state_vector) const override; | ||
}; | ||
|
||
class U3 : public QuantumGate { | ||
UINT _target; | ||
double _theta, _lambda, _phi; | ||
std::array<Complex, 4> _matrix; | ||
|
||
public: | ||
U3(UINT target, UINT theta, UINT phi, UINT lambda) | ||
: _target(target), _theta(theta), _phi(phi), _lambda(lambda) { | ||
_matrix = get_IBMQ_matrix(theta, phi, lambda); | ||
}; | ||
void update_quantum_state(StateVector& state_vector) const override; | ||
}; | ||
} // 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,27 @@ | ||
#include <Kokkos_Core.hpp> | ||
#include <Kokkos_StdAlgorithms.hpp> | ||
|
||
#include "../types.hpp" | ||
#include "update_ops.hpp" | ||
|
||
namespace qulacs { | ||
void single_qubit_dense_matrix_gate(UINT target_qubit_index, | ||
std::array<Complex, 4> matrix, | ||
StateVector& state) { | ||
const UINT mask = 1ULL << target_qubit_index; | ||
const UINT mask_low = mask - 1; | ||
const UINT mask_high = ~mask_low; | ||
auto amplitudes = state.amplitudes_raw(); | ||
Kokkos::parallel_for( | ||
state.dim() - 1, 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]; | ||
Complex val1 = amplitudes[basis_1]; | ||
Complex res0 = matrix[0] * val0 + matrix[1] * val1; | ||
Complex res1 = matrix[2] * val0 + matrix[3] * val1; | ||
amplitudes[basis_0] = res0; | ||
amplitudes[basis_1] = res1; | ||
}); | ||
} | ||
} // 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,26 @@ | ||
#include <Kokkos_Core.hpp> | ||
#include <Kokkos_StdAlgorithms.hpp> | ||
|
||
#include "../types.hpp" | ||
#include "constant.hpp" | ||
#include "update_ops.hpp" | ||
|
||
namespace qulacs { | ||
std::array<Complex, 4> get_IBMQ_matrix(double theta, double phi, double lambda) { | ||
std::array<Complex, 4> matrix; | ||
Complex im = Complex(0, 1); | ||
Complex exp_val1 = std::exp(im * phi); | ||
Complex exp_val2 = std::exp(im * lambda); | ||
Complex cos_val = std::cos(theta / 2.); | ||
Complex sin_val = std::sin(theta / 2.); | ||
matrix[0] = cos_val; | ||
matrix[1] = -exp_val2 * sin_val; | ||
matrix[2] = exp_val1 * sin_val; | ||
matrix[3] = exp_val1 * exp_val2 * cos_val; | ||
return matrix; | ||
} | ||
|
||
void u_gate(UINT target_qubit_index, std::array<Complex, 4> matrix, StateVector& state) { | ||
single_qubit_dense_matrix_gate(target_qubit_index, matrix, state); | ||
} | ||
} // 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