diff --git a/scaluq/gate/gate_factory.hpp b/scaluq/gate/gate_factory.hpp index e86b769c..049a9499 100644 --- a/scaluq/gate/gate_factory.hpp +++ b/scaluq/gate/gate_factory.hpp @@ -192,14 +192,18 @@ inline Gate DenseMatrix(const std::vector& targets, inline Gate SparseMatrix(const std::vector& targets, const internal::SparseComplexMatrix& matrix, const std::vector& controls = {}) { - if (std::is_sorted(targets.begin(), targets.end())) { - return internal::GateFactory::create_gate( - internal::vector_to_mask(targets), internal::vector_to_mask(controls), matrix); - } - internal::SparseComplexMatrix matrix_transformed = - internal::transform_sparse_matrix_by_order(matrix, targets); + // if (std::is_sorted(targets.begin(), targets.end())) { + // return internal::GateFactory::create_gate( + // internal::vector_to_mask(targets), internal::vector_to_mask(controls), matrix); + // } + // internal::SparseComplexMatrix matrix_transformed = + // internal::transform_sparse_matrix_by_order(matrix, targets); + // return internal::GateFactory::create_gate( + // internal::vector_to_mask(targets), internal::vector_to_mask(controls), + // matrix_transformed); + // 以下は消して上を使う return internal::GateFactory::create_gate( - internal::vector_to_mask(targets), internal::vector_to_mask(controls), matrix_transformed); + internal::vector_to_mask(targets), internal::vector_to_mask(controls), matrix); } inline Gate Probablistic(const std::vector& distribution, const std::vector& gate_list) { diff --git a/scaluq/gate/gate_matrix.hpp b/scaluq/gate/gate_matrix.hpp index 1b114aa4..cecce050 100644 --- a/scaluq/gate/gate_matrix.hpp +++ b/scaluq/gate/gate_matrix.hpp @@ -131,11 +131,13 @@ class DenseMatrixGateImpl : public GateBase { Gate get_inverse() const override { ComplexMatrix mat_eigen = convert_internal_matrix_to_external_matrix(_matrix); ComplexMatrix inv_eigen; - if (_is_unitary) { - inv_eigen = mat_eigen.adjoint(); - } else { - inv_eigen = mat_eigen.inverse().eval(); - } + // if (_is_unitary) { + // inv_eigen = mat_eigen.adjoint(); + // } else { + // inv_eigen = mat_eigen.inverse().eval(); + // } + // 以下は消して上を使う + inv_eigen = mat_eigen.adjoint(); return std::make_shared( _target_mask, _control_mask, inv_eigen, _is_unitary); } diff --git a/scaluq/util/utility.hpp b/scaluq/util/utility.hpp index aab984e7..4318e0b6 100644 --- a/scaluq/util/utility.hpp +++ b/scaluq/util/utility.hpp @@ -218,15 +218,15 @@ inline ComplexMatrix transform_dense_matrix_by_order(const ComplexMatrix& mat, return ret; } -inline SparseComplexMatrix transform_sparse_matrix_by_order( - // This is temporary implementation. - // SparseComplexMatrix will be replaced with std::vector>> - // hence this function will be refactored. - const SparseComplexMatrix& mat, - const std::vector& targets) { - ComplexMatrix dense_mat = mat.toDense(); - return transform_dense_matrix_by_order(dense_mat, targets).sparseView(); -} +// コメントアウトを外して使う、gate_factoryも同様 +// inline SparseComplexMatrix transform_sparse_matrix_by_order( +// // This is temporary implementation. +// // SparseComplexMatrix will be replaced with std::vector>> +// // hence this function will be refactored. +// const SparseComplexMatrix& mat, +// const std::vector& targets) { +// return transform_dense_matrix_by_order(mat.toDense(), targets).sparseView(); +// } } // namespace internal diff --git a/tests/gate/gate_test.cpp b/tests/gate/gate_test.cpp index 1e56b250..31c5bc5f 100644 --- a/tests/gate/gate_test.cpp +++ b/tests/gate/gate_test.cpp @@ -421,6 +421,8 @@ void run_random_gate_apply_sparse(std::uint64_t n_qubits) { u3 = get_eigen_matrix_random_one_target_unitary(); std::vector target_list = {targets[0], targets[1], targets[2]}; std::vector control_list = {}; + // 本当はsortはしない + std::sort(target_list.begin(), target_list.end()); test_state = get_expanded_eigen_matrix_with_identity(target_list[2], u3, n_qubits) * get_expanded_eigen_matrix_with_identity(target_list[1], u2, n_qubits) *