Skip to content

Commit

Permalink
kokkos::numbers
Browse files Browse the repository at this point in the history
  • Loading branch information
gandalfr-KY committed Oct 22, 2024
1 parent b9ef075 commit 66e3efa
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 14 deletions.
16 changes: 8 additions & 8 deletions scaluq/gate/gate_standard.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ class YGateImpl : public GateBase<Fp> {
}
internal::ComplexMatrix<Fp> get_matrix() const override {
internal::ComplexMatrix<Fp> mat(2, 2);
mat << 0, Complex<Fp>(0, -1), Complex<Fp>(0, 1), 0;
mat << 0, StdComplex<Fp>(0, -1), StdComplex<Fp>(0, 1), 0;
return mat;
}

Expand Down Expand Up @@ -166,7 +166,7 @@ class HGateImpl : public GateBase<Fp> {
internal::ComplexMatrix<Fp> get_matrix() const override {
internal::ComplexMatrix<Fp> mat(2, 2);
mat << 1, 1, 1, -1;
mat /= std::sqrt(2);
mat /= (Fp)Kokkos::numbers::sqrt2;
return mat;
}

Expand Down Expand Up @@ -210,7 +210,7 @@ class SGateImpl : public GateBase<Fp> {
}
internal::ComplexMatrix<Fp> get_matrix() const override {
internal::ComplexMatrix<Fp> mat(2, 2);
mat << 1, 0, 0, 1i;
mat << 1, 0, 0, StdComplex<Fp>(0, 1);
return mat;
}

Expand All @@ -237,7 +237,7 @@ class SdagGateImpl : public GateBase<Fp> {
}
internal::ComplexMatrix<Fp> get_matrix() const override {
internal::ComplexMatrix<Fp> mat(2, 2);
mat << 1, 0, 0, -1i;
mat << 1, 0, 0, StdComplex<Fp>(0, -1);
return mat;
}

Expand All @@ -264,7 +264,7 @@ class TGateImpl : public GateBase<Fp> {
}
internal::ComplexMatrix<Fp> get_matrix() const override {
internal::ComplexMatrix<Fp> mat(2, 2);
mat << 1, 0, 0, (1. + 1i) / std::sqrt(2);
mat << 1, 0, 0, StdComplex<Fp>(1, 1) / (Fp)Kokkos::numbers::sqrt2;
return mat;
}

Expand All @@ -291,7 +291,7 @@ class TdagGateImpl : public GateBase<Fp> {
}
internal::ComplexMatrix<Fp> get_matrix() const override {
internal::ComplexMatrix<Fp> mat(2, 2);
mat << 1, 0, 0, (1. - 1.i) / std::sqrt(2);
mat << 1, 0, 0, StdComplex<Fp>(1, -1) / (Fp)Kokkos::numbers::sqrt2;
return mat;
}

Expand Down Expand Up @@ -489,8 +489,8 @@ class RXGateImpl : public RotationGateBase<Fp> {
}
internal::ComplexMatrix<Fp> get_matrix() const override {
internal::ComplexMatrix<Fp> mat(2, 2);
mat << std::cos(this->_angle / 2), Complex<Fp>(0, -std::sin(this->_angle / 2)),
Complex<Fp>(0, std::sin(this->_angle / 2)), std::cos(this->_angle / 2);
mat << std::cos(this->_angle / 2), StdComplex<Fp>(0, -std::sin(this->_angle / 2)),
StdComplex<Fp>(0, std::sin(this->_angle / 2)), std::cos(this->_angle / 2);
return mat;
}

Expand Down
7 changes: 4 additions & 3 deletions scaluq/gate/param_gate_standard.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ class ParamRXGateImpl : public ParamGateBase<Fp> {
internal::ComplexMatrix<Fp> get_matrix(Fp param) const override {
Fp angle = this->_pcoef * param;
internal::ComplexMatrix<Fp> mat(2, 2);
mat << std::cos(angle / 2), -1i * std::sin(angle / 2), -1i * std::sin(angle / 2),
std::cos(angle / 2);
mat << std::cos(angle / 2), StdComplex<Fp>(0, -std::sin(angle / 2)),
StdComplex<Fp>(0, -std::sin(angle / 2)), std::cos(angle / 2);
return mat;
}

Expand Down Expand Up @@ -79,7 +79,8 @@ class ParamRZGateImpl : public ParamGateBase<Fp> {
internal::ComplexMatrix<Fp> get_matrix(Fp param) const override {
Fp angle = param * this->_pcoef;
internal::ComplexMatrix<Fp> mat(2, 2);
mat << std::exp(-0.5i * angle), 0, 0, std::exp(0.5i * angle);
mat << std::exp(StdComplex<Fp>(0, -angle / 2)), 0, 0,
std::exp(StdComplex<Fp>(0, angle / 2));
return mat;
}

Expand Down
1 change: 0 additions & 1 deletion scaluq/types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ template <std::floating_point Fp>
using StdComplex = std::complex<Fp>;
template <std::floating_point Fp>
using Complex = Kokkos::complex<Fp>;
using namespace std::complex_literals;

namespace internal {
template <typename DummyType>
Expand Down
2 changes: 2 additions & 0 deletions tests/test_environment.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

#include <Kokkos_Core.hpp>

using namespace std::complex_literals;

namespace scaluq {
class TestEnvironment : public testing::Environment {
void SetUp() override { Kokkos::initialize(); }
Expand Down
4 changes: 2 additions & 2 deletions tests/util/util.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

#include <Eigen/Core>
#include <complex>
using namespace std::complex_literals;

#include <types.hpp>
#include <util/random.hpp>
#include <util/utility.hpp>

using namespace scaluq;
using namespace std::complex_literals;

template <std::floating_point Fp>
inline bool same_state(const StateVector<Fp>& s1,
Expand Down

0 comments on commit 66e3efa

Please sign in to comment.