forked from mindspore-Ecosystem/mindspore
!25479 delete mindquantum c++ simulator
Merge pull request !25479 from donghufeng/master
This commit is contained in:
commit
8758830723
|
@ -1,25 +0,0 @@
|
|||
set(projectq_CXXFLAGS "-fopenmp -O2 -ffast-mast -mavx -DINTRIN")
|
||||
set(projectq_CFLAGS "-fopenmp -O2 -ffast-mast -mavx -DINTRIN")
|
||||
|
||||
if(ENABLE_GITEE)
|
||||
set(REQ_URL "https://gitee.com/mirrors/ProjectQ/repository/archive/v0.5.1.tar.gz")
|
||||
set(MD5 "3756657d9acd712d0457c3fff13bab0a")
|
||||
else()
|
||||
set(REQ_URL "https://github.com/ProjectQ-Framework/ProjectQ/archive/v0.5.1.tar.gz ")
|
||||
set(MD5 "13430199c253284df8b3d840f11d3560")
|
||||
endif()
|
||||
|
||||
if(ENABLE_CPU AND ${CMAKE_SYSTEM_NAME} MATCHES "Linux"
|
||||
AND ${CMAKE_HOST_SYSTEM_PROCESSOR} MATCHES "x86_64")
|
||||
message("Include projectq simulator")
|
||||
mindspore_add_pkg(projectq
|
||||
VER 0.5.1
|
||||
HEAD_ONLY ./
|
||||
URL ${REQ_URL}
|
||||
MD5 ${MD5}
|
||||
PATCHES ${CMAKE_SOURCE_DIR}/third_party/patch/projectq/projectq.patch001
|
||||
)
|
||||
include_directories(${projectq_INC})
|
||||
else()
|
||||
message("Quantum simulation only support x86_64 linux platform.")
|
||||
endif()
|
|
@ -46,12 +46,6 @@ if(ENABLE_CPU)
|
|||
include(${CMAKE_SOURCE_DIR}/cmake/external_libs/mkl_dnn.cmake)
|
||||
endif()
|
||||
|
||||
if(ENABLE_CPU AND ${CMAKE_SYSTEM_NAME} MATCHES "Linux"
|
||||
AND ${CMAKE_HOST_SYSTEM_PROCESSOR} MATCHES "x86_64")
|
||||
message("Include projectq")
|
||||
include(${CMAKE_SOURCE_DIR}/cmake/external_libs/projectq.cmake)
|
||||
endif()
|
||||
|
||||
if(ENABLE_GPU)
|
||||
if(ENABLE_MPI)
|
||||
include(${CMAKE_SOURCE_DIR}/cmake/external_libs/nccl.cmake)
|
||||
|
|
|
@ -28,7 +28,6 @@ if(ENABLE_CPU)
|
|||
"cpu/mkldnn/*.cc"
|
||||
"cpu/fl/*.cc"
|
||||
"cpu/ps/*.cc"
|
||||
"cpu/quantum/*.cc"
|
||||
"cpu/pyfunc/*.cc"
|
||||
"cpu/rl/*.cc"
|
||||
"cpu/custom/*.cc"
|
||||
|
@ -40,26 +39,6 @@ if(ENABLE_CPU)
|
|||
list(REMOVE_ITEM CPU_SRC_LIST "cpu/embedding_look_up_comm_grad_cpu_kernel.cc")
|
||||
endif()
|
||||
|
||||
file(GLOB_RECURSE QUANTUM_SRC_LIST RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}
|
||||
"cpu/quantum/*.cc"
|
||||
)
|
||||
|
||||
foreach(qcc ${QUANTUM_SRC_LIST})
|
||||
list(REMOVE_ITEM CPU_SRC_LIST ${qcc})
|
||||
endforeach()
|
||||
|
||||
if(${CMAKE_SYSTEM_NAME} MATCHES "Linux"
|
||||
AND ${CMAKE_HOST_SYSTEM_PROCESSOR} MATCHES "x86_64")
|
||||
message("compiled quantum kernel_compiler")
|
||||
set_property(SOURCE ${QUANTUM_SRC_LIST} PROPERTY COMPILE_DEFINITIONS
|
||||
SUBMODULE_ID=mindspore::SubModuleId::SM_MINDQUANTUM)
|
||||
set_property(SOURCE ${QUANTUM_SRC_LIST} PROPERTY COMPILE_DEFINITIONS INTRIN)
|
||||
set_property(SOURCE ${QUANTUM_SRC_LIST} PROPERTY COMPILE_OPTIONS -fopenmp -mavx -ffast-math)
|
||||
else()
|
||||
message("not compiled quantum kernel_compiler")
|
||||
set(QUANTUM_SRC_LIST "")
|
||||
endif()
|
||||
|
||||
if(PLATFORM_ARM64)
|
||||
add_compile_definitions(ENABLE_ARM)
|
||||
endif()
|
||||
|
@ -142,4 +121,4 @@ endif()
|
|||
set_property(SOURCE ${KERNEL_SRC_LIST} ${CPU_SRC_LIST} ${GPU_SRC_LIST} ${D_SRC_LIST} ${AKG_SRC_LIST}
|
||||
PROPERTY COMPILE_DEFINITIONS SUBMODULE_ID=mindspore::SubModuleId::SM_KERNEL)
|
||||
add_library(_mindspore_backend_kernel_compiler_obj OBJECT ${KERNEL_SRC_LIST} ${CPU_SRC_LIST}
|
||||
${GPU_SRC_LIST} ${D_SRC_LIST} ${AKG_SRC_LIST} ${QUANTUM_SRC_LIST})
|
||||
${GPU_SRC_LIST} ${D_SRC_LIST} ${AKG_SRC_LIST})
|
||||
|
|
|
@ -1,94 +0,0 @@
|
|||
/**
|
||||
* Copyright 2021 Huawei Technologies Co., Ltd
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include "backend/kernel_compiler/cpu/quantum/evolution_cpu_kernel.h"
|
||||
|
||||
#include <memory>
|
||||
#include <algorithm>
|
||||
#include "utils/ms_utils.h"
|
||||
#include "runtime/device/cpu/cpu_device_address.h"
|
||||
|
||||
namespace mindspore {
|
||||
namespace kernel {
|
||||
void EvolutionCPUKernel::InitPQCStructure(const CNodePtr &kernel_node) {
|
||||
n_qubits_ = AnfAlgo::GetNodeAttr<int64_t>(kernel_node, mindquantum::kNQubits);
|
||||
param_names_ = AnfAlgo::GetNodeAttr<mindquantum::transformer::NamesType>(kernel_node, mindquantum::kParamNames);
|
||||
gate_names_ = AnfAlgo::GetNodeAttr<mindquantum::transformer::NamesType>(kernel_node, mindquantum::kGateNames);
|
||||
gate_matrix_ =
|
||||
AnfAlgo::GetNodeAttr<mindquantum::transformer::ComplexMatrixsType>(kernel_node, mindquantum::kGateMatrix);
|
||||
gate_obj_qubits_ = AnfAlgo::GetNodeAttr<mindquantum::transformer::Indexess>(kernel_node, mindquantum::kGateObjQubits);
|
||||
gate_ctrl_qubits_ =
|
||||
AnfAlgo::GetNodeAttr<mindquantum::transformer::Indexess>(kernel_node, mindquantum::kGateCtrlQubits);
|
||||
gate_params_names_ =
|
||||
AnfAlgo::GetNodeAttr<mindquantum::transformer::ParasNameType>(kernel_node, mindquantum::kGateParamsNames);
|
||||
gate_coeff_ = AnfAlgo::GetNodeAttr<mindquantum::transformer::CoeffsType>(kernel_node, mindquantum::kGateCoeff);
|
||||
gate_requires_grad_ =
|
||||
AnfAlgo::GetNodeAttr<mindquantum::transformer::RequiresType>(kernel_node, mindquantum::kGateRequiresGrad);
|
||||
hams_pauli_coeff_ =
|
||||
AnfAlgo::GetNodeAttr<mindquantum::transformer::PaulisCoeffsType>(kernel_node, mindquantum::kHamsPauliCoeff);
|
||||
hams_pauli_word_ =
|
||||
AnfAlgo::GetNodeAttr<mindquantum::transformer::PaulisWordsType>(kernel_node, mindquantum::kHamsPauliWord);
|
||||
hams_pauli_qubit_ =
|
||||
AnfAlgo::GetNodeAttr<mindquantum::transformer::PaulisQubitsType>(kernel_node, mindquantum::kHamsPauliQubit);
|
||||
}
|
||||
|
||||
void EvolutionCPUKernel::InitKernel(const CNodePtr &kernel_node) {
|
||||
MS_EXCEPTION_IF_NULL(kernel_node);
|
||||
std::vector<size_t> param_shape = AnfAlgo::GetInputDeviceShape(kernel_node, 0);
|
||||
std::vector<size_t> result_shape = AnfAlgo::GetOutputDeviceShape(kernel_node, 0);
|
||||
if (param_shape.size() != 1 || result_shape.size() != 2) {
|
||||
MS_LOG(EXCEPTION) << "evolution invalid input size";
|
||||
}
|
||||
state_len_ = result_shape[0];
|
||||
InitPQCStructure(kernel_node);
|
||||
auto circs = mindquantum::transformer::CircuitTransfor(gate_names_, gate_matrix_, gate_obj_qubits_, gate_ctrl_qubits_,
|
||||
gate_params_names_, gate_coeff_, gate_requires_grad_);
|
||||
circ_ = circs[0];
|
||||
hams_ = mindquantum::transformer::HamiltoniansTransfor(hams_pauli_coeff_, hams_pauli_word_, hams_pauli_qubit_);
|
||||
if (hams_.size() > 1) {
|
||||
MS_LOG(EXCEPTION) << "evolution only work for single hamiltonian or no hamiltonian.";
|
||||
}
|
||||
}
|
||||
|
||||
bool EvolutionCPUKernel::Launch(const std::vector<kernel::AddressPtr> &inputs, const std::vector<kernel::AddressPtr> &,
|
||||
const std::vector<kernel::AddressPtr> &outputs) {
|
||||
if (inputs.size() != 1 || outputs.size() != 1) {
|
||||
MS_LOG(EXCEPTION) << "evolution error input output size!";
|
||||
}
|
||||
auto param_data = reinterpret_cast<float *>(inputs[0]->addr);
|
||||
auto output = reinterpret_cast<float *>(outputs[0]->addr);
|
||||
MS_EXCEPTION_IF_NULL(param_data);
|
||||
MS_EXCEPTION_IF_NULL(output);
|
||||
auto sim = mindquantum::PQCSimulator(1, n_qubits_);
|
||||
mindquantum::ParameterResolver pr;
|
||||
for (size_t i = 0; i < param_names_.size(); i++) {
|
||||
pr.SetData(param_names_.at(i), param_data[i]);
|
||||
}
|
||||
sim.Evolution(circ_, pr);
|
||||
if (hams_.size() == 1) {
|
||||
sim.ApplyHamiltonian(hams_[0]);
|
||||
}
|
||||
if (state_len_ != (1UL << n_qubits_)) {
|
||||
MS_LOG(EXCEPTION) << "simulation error number of quantum qubit!";
|
||||
}
|
||||
auto size = state_len_ * 2;
|
||||
#pragma omp parallel for schedule(static)
|
||||
for (size_t i = 0; i < size; i++) {
|
||||
output[i] = sim.vec_[i];
|
||||
}
|
||||
return true;
|
||||
}
|
||||
} // namespace kernel
|
||||
} // namespace mindspore
|
|
@ -1,67 +0,0 @@
|
|||
/**
|
||||
* Copyright 2021 Huawei Technologies Co., Ltd
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#ifndef MINDSPORE_CCSRC_BACKEND_KERNEL_COMPILER_CPU_EVOLUTION_CPU_KERNEL_H_
|
||||
#define MINDSPORE_CCSRC_BACKEND_KERNEL_COMPILER_CPU_EVOLUTION_CPU_KERNEL_H_
|
||||
|
||||
#include <vector>
|
||||
#include "backend/kernel_compiler/cpu/cpu_kernel.h"
|
||||
#include "backend/kernel_compiler/cpu/cpu_kernel_factory.h"
|
||||
#include "backend/kernel_compiler/cpu/quantum/quantum_simulator/pqc_simulator.h"
|
||||
#include "backend/kernel_compiler/cpu/quantum/quantum_simulator/transformer.h"
|
||||
#include "backend/kernel_compiler/cpu/quantum/quantum_simulator/circuit.h"
|
||||
#include "backend/kernel_compiler/cpu/quantum/quantum_simulator/parameter_resolver.h"
|
||||
|
||||
namespace mindspore {
|
||||
namespace kernel {
|
||||
class EvolutionCPUKernel : public CPUKernel {
|
||||
public:
|
||||
EvolutionCPUKernel() = default;
|
||||
~EvolutionCPUKernel() override = default;
|
||||
|
||||
void InitKernel(const CNodePtr &kernel_node) override;
|
||||
|
||||
bool Launch(const std::vector<AddressPtr> &inputs, const std::vector<AddressPtr> &workspace,
|
||||
const std::vector<AddressPtr> &outputs) override;
|
||||
|
||||
void InitPQCStructure(const CNodePtr &kernel_node);
|
||||
|
||||
private:
|
||||
int64_t n_qubits_;
|
||||
size_t state_len_;
|
||||
mindquantum::BasicCircuit circ_;
|
||||
mindquantum::transformer::Hamiltonians hams_;
|
||||
mindquantum::transformer::NamesType param_names_;
|
||||
|
||||
// quantum circuit
|
||||
mindquantum::transformer::NamesType gate_names_;
|
||||
mindquantum::transformer::ComplexMatrixsType gate_matrix_;
|
||||
mindquantum::transformer::Indexess gate_obj_qubits_;
|
||||
mindquantum::transformer::Indexess gate_ctrl_qubits_;
|
||||
mindquantum::transformer::ParasNameType gate_params_names_;
|
||||
mindquantum::transformer::CoeffsType gate_coeff_;
|
||||
mindquantum::transformer::RequiresType gate_requires_grad_;
|
||||
|
||||
// hamiltonian
|
||||
mindquantum::transformer::PaulisCoeffsType hams_pauli_coeff_;
|
||||
mindquantum::transformer::PaulisWordsType hams_pauli_word_;
|
||||
mindquantum::transformer::PaulisQubitsType hams_pauli_qubit_;
|
||||
};
|
||||
|
||||
MS_REG_CPU_KERNEL(Evolution, KernelAttr().AddInputAttr(kNumberTypeFloat32).AddOutputAttr(kNumberTypeFloat32),
|
||||
EvolutionCPUKernel);
|
||||
} // namespace kernel
|
||||
} // namespace mindspore
|
||||
#endif // MINDSPORE_CCSRC_BACKEND_KERNEL_COMPILER_CPU_EVOLUTION_CPU_KERNEL_H_
|
|
@ -1,264 +0,0 @@
|
|||
/**
|
||||
* Copyright 2021 Huawei Technologies Co., Ltd
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include "backend/kernel_compiler/cpu/quantum/pqc_cpu_kernel.h"
|
||||
|
||||
#include <omp.h>
|
||||
#include <utility>
|
||||
#include <thread>
|
||||
#include <memory>
|
||||
#include <algorithm>
|
||||
#include "utils/ms_utils.h"
|
||||
#include "runtime/device/cpu/cpu_device_address.h"
|
||||
#include "common/thread_pool.h"
|
||||
|
||||
namespace mindspore {
|
||||
namespace kernel {
|
||||
namespace {
|
||||
struct ComputeParam {
|
||||
float *encoder_data_cp{nullptr};
|
||||
float *ansatz_data_cp{nullptr};
|
||||
float *output_cp{nullptr};
|
||||
float *gradient_encoder_cp{nullptr};
|
||||
float *gradient_ansatz_cp{nullptr};
|
||||
mindquantum::BasicCircuit *circ_cp;
|
||||
mindquantum::BasicCircuit *herm_circ_cp;
|
||||
mindquantum::transformer::Hamiltonians *hams_cp;
|
||||
mindquantum::transformer::Projectors *projectors_cp;
|
||||
mindquantum::transformer::NamesType *encoder_params_names_cp;
|
||||
mindquantum::transformer::NamesType *ansatz_params_names_cp;
|
||||
std::vector<std::vector<std::shared_ptr<mindquantum::PQCSimulator>>> *tmp_sims_cp;
|
||||
bool dummy_circuit_cp{false};
|
||||
bool is_projector_cp{false};
|
||||
size_t result_len_cp{0};
|
||||
size_t encoder_g_len_cp{0};
|
||||
size_t ansatz_g_len_cp{0};
|
||||
};
|
||||
|
||||
void ComputerForwardBackward(const std::shared_ptr<ComputeParam> &input_params, size_t start, size_t end, size_t id) {
|
||||
MS_EXCEPTION_IF_NULL(input_params);
|
||||
MS_EXCEPTION_IF_NULL(input_params->encoder_data_cp);
|
||||
MS_EXCEPTION_IF_NULL(input_params->ansatz_data_cp);
|
||||
MS_EXCEPTION_IF_NULL(input_params->output_cp);
|
||||
MS_EXCEPTION_IF_NULL(input_params->gradient_encoder_cp);
|
||||
MS_EXCEPTION_IF_NULL(input_params->gradient_ansatz_cp);
|
||||
auto encoder_data = input_params->encoder_data_cp;
|
||||
auto ansatz_data = input_params->ansatz_data_cp;
|
||||
auto output = input_params->output_cp;
|
||||
auto gradient_encoder = input_params->gradient_encoder_cp;
|
||||
auto gradient_ansatz = input_params->gradient_ansatz_cp;
|
||||
auto circ = input_params->circ_cp;
|
||||
auto herm_circ = input_params->herm_circ_cp;
|
||||
auto hams = input_params->hams_cp;
|
||||
auto projectors = input_params->projectors_cp;
|
||||
auto is_projector = input_params->is_projector_cp;
|
||||
auto encoder_params_names = input_params->encoder_params_names_cp;
|
||||
auto ansatz_params_names = input_params->ansatz_params_names_cp;
|
||||
auto tmp_sims = input_params->tmp_sims_cp;
|
||||
auto dummy_circuit = input_params->dummy_circuit_cp;
|
||||
auto result_len = input_params->result_len_cp;
|
||||
auto encoder_g_len = input_params->encoder_g_len_cp;
|
||||
auto ansatz_g_len = input_params->ansatz_g_len_cp;
|
||||
MS_EXCEPTION_IF_NULL(hams);
|
||||
MS_EXCEPTION_IF_NULL(encoder_params_names);
|
||||
MS_EXCEPTION_IF_NULL(ansatz_params_names);
|
||||
MS_EXCEPTION_IF_NULL(tmp_sims);
|
||||
auto mea_size = hams->size();
|
||||
if (is_projector) {
|
||||
mea_size = projectors->size();
|
||||
}
|
||||
if (end * mea_size > result_len || end * encoder_params_names->size() * mea_size > encoder_g_len ||
|
||||
end * ansatz_params_names->size() * mea_size > ansatz_g_len) {
|
||||
MS_LOG(EXCEPTION) << "pqc error input size!";
|
||||
}
|
||||
mindquantum::ParameterResolver pr;
|
||||
for (size_t i = 0; i < ansatz_params_names->size(); i++) {
|
||||
pr.SetData(ansatz_params_names->at(i), ansatz_data[i]);
|
||||
}
|
||||
for (size_t n = start; n < end; ++n) {
|
||||
for (size_t i = 0; i < encoder_params_names->size(); i++) {
|
||||
pr.SetData(encoder_params_names->at(i), encoder_data[n * encoder_params_names->size() + i]);
|
||||
}
|
||||
auto sim = tmp_sims->at(id)[3];
|
||||
sim->SetZeroState();
|
||||
sim->Evolution(*circ, pr);
|
||||
auto calc_gradient_param = std::make_shared<mindquantum::CalcGradientParam>();
|
||||
calc_gradient_param->circuit_cp = circ;
|
||||
calc_gradient_param->circuit_hermitian_cp = herm_circ;
|
||||
calc_gradient_param->hamiltonians_cp = hams;
|
||||
calc_gradient_param->projectors_cp = projectors;
|
||||
calc_gradient_param->is_projector_cp = is_projector;
|
||||
calc_gradient_param->paras_cp = ≺
|
||||
calc_gradient_param->encoder_params_names_cp = encoder_params_names;
|
||||
calc_gradient_param->ansatz_params_names_cp = ansatz_params_names;
|
||||
calc_gradient_param->dummy_circuit_cp = dummy_circuit;
|
||||
|
||||
auto e0_grad1_grad_2 =
|
||||
sim->CalcGradient(calc_gradient_param, *tmp_sims->at(id)[0], *tmp_sims->at(id)[1], *tmp_sims->at(id)[2]);
|
||||
auto energy = e0_grad1_grad_2[0];
|
||||
auto grad_encoder = e0_grad1_grad_2[1];
|
||||
auto grad_ansatz = e0_grad1_grad_2[2];
|
||||
if (energy.size() != mea_size || grad_encoder.size() != encoder_params_names->size() * mea_size ||
|
||||
grad_ansatz.size() != ansatz_params_names->size() * mea_size) {
|
||||
MS_LOG(EXCEPTION) << "pqc error evolution or batch size!";
|
||||
}
|
||||
for (size_t poi = 0; poi < mea_size; poi++) {
|
||||
output[n * mea_size + poi] = energy[poi];
|
||||
}
|
||||
for (size_t poi = 0; poi < encoder_params_names->size() * mea_size; poi++) {
|
||||
gradient_encoder[n * mea_size * encoder_params_names->size() + poi] = grad_encoder[poi];
|
||||
}
|
||||
for (size_t poi = 0; poi < ansatz_params_names->size() * mea_size; poi++) {
|
||||
gradient_ansatz[n * mea_size * ansatz_params_names->size() + poi] = grad_ansatz[poi];
|
||||
}
|
||||
}
|
||||
}
|
||||
} // namespace
|
||||
|
||||
void PQCCPUKernel::InitPQCStructure(const CNodePtr &kernel_node) {
|
||||
n_threads_user_ = AnfAlgo::GetNodeAttr<int64_t>(kernel_node, mindquantum::kNThreads);
|
||||
n_qubits_ = AnfAlgo::GetNodeAttr<int64_t>(kernel_node, mindquantum::kNQubits);
|
||||
encoder_params_names_ =
|
||||
AnfAlgo::GetNodeAttr<mindquantum::transformer::NamesType>(kernel_node, mindquantum::kEncoderParamsNames);
|
||||
ansatz_params_names_ =
|
||||
AnfAlgo::GetNodeAttr<mindquantum::transformer::NamesType>(kernel_node, mindquantum::kAnsatzParamsNames);
|
||||
gate_names_ = AnfAlgo::GetNodeAttr<mindquantum::transformer::NamesType>(kernel_node, mindquantum::kGateNames);
|
||||
gate_matrix_ =
|
||||
AnfAlgo::GetNodeAttr<mindquantum::transformer::ComplexMatrixsType>(kernel_node, mindquantum::kGateMatrix);
|
||||
gate_obj_qubits_ = AnfAlgo::GetNodeAttr<mindquantum::transformer::Indexess>(kernel_node, mindquantum::kGateObjQubits);
|
||||
gate_ctrl_qubits_ =
|
||||
AnfAlgo::GetNodeAttr<mindquantum::transformer::Indexess>(kernel_node, mindquantum::kGateCtrlQubits);
|
||||
gate_params_names_ =
|
||||
AnfAlgo::GetNodeAttr<mindquantum::transformer::ParasNameType>(kernel_node, mindquantum::kGateParamsNames);
|
||||
gate_coeff_ = AnfAlgo::GetNodeAttr<mindquantum::transformer::CoeffsType>(kernel_node, mindquantum::kGateCoeff);
|
||||
gate_requires_grad_ =
|
||||
AnfAlgo::GetNodeAttr<mindquantum::transformer::RequiresType>(kernel_node, mindquantum::kGateRequiresGrad);
|
||||
hams_pauli_coeff_ =
|
||||
AnfAlgo::GetNodeAttr<mindquantum::transformer::PaulisCoeffsType>(kernel_node, mindquantum::kHamsPauliCoeff);
|
||||
hams_pauli_word_ =
|
||||
AnfAlgo::GetNodeAttr<mindquantum::transformer::PaulisWordsType>(kernel_node, mindquantum::kHamsPauliWord);
|
||||
hams_pauli_qubit_ =
|
||||
AnfAlgo::GetNodeAttr<mindquantum::transformer::PaulisQubitsType>(kernel_node, mindquantum::kHamsPauliQubit);
|
||||
projector_strs_ = AnfAlgo::GetNodeAttr<mindquantum::transformer::NamesType>(kernel_node, mindquantum::kProjectors);
|
||||
is_projector_ = AnfAlgo::GetNodeAttr<bool>(kernel_node, mindquantum::kIsProjector);
|
||||
}
|
||||
|
||||
void PQCCPUKernel::InitKernel(const CNodePtr &kernel_node) {
|
||||
MS_EXCEPTION_IF_NULL(kernel_node);
|
||||
std::vector<size_t> encoder_shape = AnfAlgo::GetInputDeviceShape(kernel_node, 0);
|
||||
std::vector<size_t> ansatz_shape = AnfAlgo::GetInputDeviceShape(kernel_node, 1);
|
||||
std::vector<size_t> result_shape = AnfAlgo::GetOutputDeviceShape(kernel_node, 0);
|
||||
std::vector<size_t> encoder_g_shape = AnfAlgo::GetOutputDeviceShape(kernel_node, 1);
|
||||
std::vector<size_t> ansatz_g_shape = AnfAlgo::GetOutputDeviceShape(kernel_node, 2);
|
||||
|
||||
if (encoder_shape.size() != 2 || ansatz_shape.size() != 1 || result_shape.size() != 2 ||
|
||||
encoder_g_shape.size() != 3 || ansatz_g_shape.size() != 3) {
|
||||
MS_LOG(EXCEPTION) << "pqc invalid input size";
|
||||
}
|
||||
result_len_ = result_shape[0] * result_shape[1];
|
||||
encoder_g_len_ = encoder_g_shape[0] * encoder_g_shape[1] * encoder_g_shape[2];
|
||||
ansatz_g_len_ = ansatz_g_shape[0] * ansatz_g_shape[1] * ansatz_g_shape[2];
|
||||
|
||||
n_samples_ = static_cast<unsigned>(encoder_shape[0]);
|
||||
InitPQCStructure(kernel_node);
|
||||
|
||||
dummy_circuit_ = !std::any_of(gate_requires_grad_.begin(), gate_requires_grad_.end(),
|
||||
[](const mindquantum::transformer::RequireType &rr) {
|
||||
return std::any_of(rr.begin(), rr.end(), [](const bool &r) { return r; });
|
||||
});
|
||||
|
||||
auto circs = mindquantum::transformer::CircuitTransfor(gate_names_, gate_matrix_, gate_obj_qubits_, gate_ctrl_qubits_,
|
||||
gate_params_names_, gate_coeff_, gate_requires_grad_);
|
||||
circ_ = circs[0];
|
||||
herm_circ_ = circs[1];
|
||||
|
||||
hams_ = mindquantum::transformer::HamiltoniansTransfor(hams_pauli_coeff_, hams_pauli_word_, hams_pauli_qubit_);
|
||||
projectors_ = mindquantum::transformer::ProjectorsTransfor(projector_strs_);
|
||||
|
||||
n_threads_user_ = std::min(n_threads_user_, common::ThreadPool::GetInstance().GetSyncRunThreadNum());
|
||||
if (n_samples_ < n_threads_user_) {
|
||||
n_threads_user_ = n_samples_;
|
||||
}
|
||||
}
|
||||
|
||||
bool PQCCPUKernel::Launch(const std::vector<kernel::AddressPtr> &inputs, const std::vector<kernel::AddressPtr> &,
|
||||
const std::vector<kernel::AddressPtr> &outputs) {
|
||||
if (inputs.size() != 2 || outputs.size() != 3) {
|
||||
MS_LOG(EXCEPTION) << "pqc error input output size!";
|
||||
}
|
||||
auto encoder_data = reinterpret_cast<float *>(inputs[0]->addr);
|
||||
auto ansatz_data = reinterpret_cast<float *>(inputs[1]->addr);
|
||||
auto output = reinterpret_cast<float *>(outputs[0]->addr);
|
||||
auto gradient_encoder = reinterpret_cast<float *>(outputs[1]->addr);
|
||||
auto gradient_ansatz = reinterpret_cast<float *>(outputs[2]->addr);
|
||||
MS_EXCEPTION_IF_NULL(encoder_data);
|
||||
MS_EXCEPTION_IF_NULL(ansatz_data);
|
||||
MS_EXCEPTION_IF_NULL(output);
|
||||
MS_EXCEPTION_IF_NULL(gradient_encoder);
|
||||
MS_EXCEPTION_IF_NULL(gradient_ansatz);
|
||||
|
||||
std::vector<std::vector<std::shared_ptr<mindquantum::PQCSimulator>>> tmp_sims(
|
||||
n_threads_user_, std::vector<std::shared_ptr<mindquantum::PQCSimulator>>(4, nullptr));
|
||||
#pragma omp parallel for collapse(2) schedule(static)
|
||||
for (size_t i = 0; i < n_threads_user_; i++) {
|
||||
for (size_t j = 0; j < 4; j++) {
|
||||
auto tmp = std::make_shared<mindquantum::PQCSimulator>(1, n_qubits_);
|
||||
tmp_sims[i][j] = tmp;
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<common::Task> tasks;
|
||||
std::vector<std::shared_ptr<ComputeParam>> thread_params;
|
||||
tasks.reserve(n_threads_user_);
|
||||
|
||||
size_t end = 0;
|
||||
size_t offset = n_samples_ / n_threads_user_;
|
||||
size_t left = n_samples_ % n_threads_user_;
|
||||
for (size_t i = 0; i < n_threads_user_; ++i) {
|
||||
auto params = std::make_shared<ComputeParam>();
|
||||
params->encoder_data_cp = encoder_data;
|
||||
params->ansatz_data_cp = ansatz_data;
|
||||
params->output_cp = output;
|
||||
params->gradient_encoder_cp = gradient_encoder;
|
||||
params->gradient_ansatz_cp = gradient_ansatz;
|
||||
params->circ_cp = &circ_;
|
||||
params->herm_circ_cp = &herm_circ_;
|
||||
params->hams_cp = &hams_;
|
||||
params->projectors_cp = &projectors_;
|
||||
params->is_projector_cp = is_projector_;
|
||||
params->encoder_params_names_cp = &encoder_params_names_;
|
||||
params->ansatz_params_names_cp = &ansatz_params_names_;
|
||||
params->tmp_sims_cp = &tmp_sims;
|
||||
params->dummy_circuit_cp = dummy_circuit_;
|
||||
params->result_len_cp = result_len_;
|
||||
params->encoder_g_len_cp = encoder_g_len_;
|
||||
params->ansatz_g_len_cp = ansatz_g_len_;
|
||||
size_t start = end;
|
||||
end = start + offset;
|
||||
if (i < left) {
|
||||
end += 1;
|
||||
}
|
||||
auto task = [¶ms, start, end, i]() {
|
||||
ComputerForwardBackward(params, start, end, i);
|
||||
return common::SUCCESS;
|
||||
};
|
||||
(void)tasks.emplace_back(task);
|
||||
(void)thread_params.emplace_back(params);
|
||||
}
|
||||
(void)common::ThreadPool::GetInstance().SyncRun(tasks);
|
||||
return true;
|
||||
}
|
||||
} // namespace kernel
|
||||
} // namespace mindspore
|
|
@ -1,91 +0,0 @@
|
|||
/**
|
||||
* Copyright 2021 Huawei Technologies Co., Ltd
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#ifndef MINDSPORE_CCSRC_BACKEND_KERNEL_COMPILER_CPU_PQC_CPU_KERNEL_H_
|
||||
#define MINDSPORE_CCSRC_BACKEND_KERNEL_COMPILER_CPU_PQC_CPU_KERNEL_H_
|
||||
|
||||
#include <vector>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include "backend/kernel_compiler/cpu/cpu_kernel.h"
|
||||
#include "backend/kernel_compiler/cpu/cpu_kernel_factory.h"
|
||||
#include "backend/kernel_compiler/cpu/quantum/quantum_simulator/pqc_simulator.h"
|
||||
#include "backend/kernel_compiler/cpu/quantum/quantum_simulator/transformer.h"
|
||||
#include "backend/kernel_compiler/cpu/quantum/quantum_simulator/circuit.h"
|
||||
#include "backend/kernel_compiler/cpu/quantum/quantum_simulator/parameter_resolver.h"
|
||||
|
||||
namespace mindspore {
|
||||
namespace kernel {
|
||||
class PQCCPUKernel : public CPUKernel {
|
||||
public:
|
||||
PQCCPUKernel() = default;
|
||||
~PQCCPUKernel() override = default;
|
||||
|
||||
void InitKernel(const CNodePtr &kernel_node) override;
|
||||
|
||||
bool Launch(const std::vector<AddressPtr> &inputs, const std::vector<AddressPtr> &workspace,
|
||||
const std::vector<AddressPtr> &outputs) override;
|
||||
|
||||
void InitPQCStructure(const CNodePtr &kernel_node);
|
||||
|
||||
private:
|
||||
size_t n_samples_;
|
||||
size_t n_threads_user_;
|
||||
bool dummy_circuit_;
|
||||
size_t result_len_;
|
||||
size_t encoder_g_len_;
|
||||
size_t ansatz_g_len_;
|
||||
|
||||
int64_t n_qubits_;
|
||||
mindquantum::BasicCircuit circ_;
|
||||
mindquantum::BasicCircuit herm_circ_;
|
||||
mindquantum::transformer::Hamiltonians hams_;
|
||||
mindquantum::transformer::Projectors projectors_;
|
||||
|
||||
// parameters
|
||||
mindquantum::transformer::NamesType encoder_params_names_;
|
||||
mindquantum::transformer::NamesType ansatz_params_names_;
|
||||
|
||||
// quantum circuit
|
||||
mindquantum::transformer::NamesType gate_names_;
|
||||
mindquantum::transformer::ComplexMatrixsType gate_matrix_;
|
||||
mindquantum::transformer::Indexess gate_obj_qubits_;
|
||||
mindquantum::transformer::Indexess gate_ctrl_qubits_;
|
||||
mindquantum::transformer::ParasNameType gate_params_names_;
|
||||
mindquantum::transformer::CoeffsType gate_coeff_;
|
||||
mindquantum::transformer::RequiresType gate_requires_grad_;
|
||||
|
||||
// hamiltonian
|
||||
mindquantum::transformer::PaulisCoeffsType hams_pauli_coeff_;
|
||||
mindquantum::transformer::PaulisWordsType hams_pauli_word_;
|
||||
mindquantum::transformer::PaulisQubitsType hams_pauli_qubit_;
|
||||
|
||||
// subspace measurement ops
|
||||
mindquantum::transformer::NamesType projector_strs_;
|
||||
bool is_projector_;
|
||||
};
|
||||
|
||||
MS_REG_CPU_KERNEL(PQC,
|
||||
KernelAttr()
|
||||
.AddInputAttr(kNumberTypeFloat32)
|
||||
.AddInputAttr(kNumberTypeFloat32)
|
||||
.AddOutputAttr(kNumberTypeFloat32)
|
||||
.AddOutputAttr(kNumberTypeFloat32)
|
||||
.AddOutputAttr(kNumberTypeFloat32),
|
||||
PQCCPUKernel);
|
||||
} // namespace kernel
|
||||
} // namespace mindspore
|
||||
|
||||
#endif // MINDSPORE_CCSRC_BACKEND_KERNEL_COMPILER_CPU_PQC_CPU_KERNEL_H_
|
|
@ -1,10 +0,0 @@
|
|||
if(ENABLE_CPU AND ${CMAKE_SYSTEM_NAME} MATCHES "Linux"
|
||||
AND ${CMAKE_HOST_SYSTEM_PROCESSOR} MATCHES "x86_64")
|
||||
message("compiled quantum simulator")
|
||||
file(GLOB_RECURSE _MINDQUANTUM_SRC_LIST RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "*.cc")
|
||||
set_property(SOURCE ${_MINDQUANTUM_SRC_LIST} PROPERTY COMPILE_DEFINITIONS
|
||||
SUBMODULE_ID=mindspore::SubModuleId::SM_MINDQUANTUM)
|
||||
add_library(_mindspore_mindquantum_obj OBJECT ${_MINDQUANTUM_SRC_LIST})
|
||||
target_compile_options(_mindspore_mindquantum_obj PRIVATE -fopenmp -mavx -ffast-math)
|
||||
target_compile_definitions(_mindspore_mindquantum_obj PRIVATE INTRIN)
|
||||
endif()
|
|
@ -1,59 +0,0 @@
|
|||
/**
|
||||
* Copyright 2021 Huawei Technologies Co., Ltd
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "backend/kernel_compiler/cpu/quantum/quantum_simulator/circuit.h"
|
||||
|
||||
namespace mindspore {
|
||||
namespace mindquantum {
|
||||
BasicCircuit::BasicCircuit() : gate_blocks_({}) {}
|
||||
|
||||
void BasicCircuit::AppendBlock() { gate_blocks_.push_back({}); }
|
||||
|
||||
void BasicCircuit::AppendNoneParameterGate(const std::string &name, Matrix m, Indexes obj_qubits, Indexes ctrl_qubits) {
|
||||
auto npg = std::make_shared<NoneParameterGate>(name, m, obj_qubits, ctrl_qubits);
|
||||
gate_blocks_.back().push_back(npg);
|
||||
}
|
||||
|
||||
void BasicCircuit::AppendParameterGate(const std::string &name, Indexes obj_qubits, Indexes ctrl_qubits,
|
||||
const ParameterResolver ¶s) {
|
||||
if (name == "RX") {
|
||||
auto pg_rx = std::make_shared<RXGate>(obj_qubits, ctrl_qubits, paras);
|
||||
gate_blocks_.back().push_back(pg_rx);
|
||||
} else if (name == "RY") {
|
||||
auto pg_ry = std::make_shared<RYGate>(obj_qubits, ctrl_qubits, paras);
|
||||
gate_blocks_.back().push_back(pg_ry);
|
||||
} else if (name == "RZ") {
|
||||
auto pg_rz = std::make_shared<RZGate>(obj_qubits, ctrl_qubits, paras);
|
||||
gate_blocks_.back().push_back(pg_rz);
|
||||
} else if (name == "XX") {
|
||||
auto pg_xx = std::make_shared<XXGate>(obj_qubits, ctrl_qubits, paras);
|
||||
gate_blocks_.back().push_back(pg_xx);
|
||||
} else if (name == "YY") {
|
||||
auto pg_yy = std::make_shared<YYGate>(obj_qubits, ctrl_qubits, paras);
|
||||
gate_blocks_.back().push_back(pg_yy);
|
||||
} else if (name == "ZZ") {
|
||||
auto pg_zz = std::make_shared<ZZGate>(obj_qubits, ctrl_qubits, paras);
|
||||
gate_blocks_.back().push_back(pg_zz);
|
||||
} else if (name == "PS") {
|
||||
auto pg_ps = std::make_shared<PhaseShiftGate>(obj_qubits, ctrl_qubits, paras);
|
||||
gate_blocks_.back().push_back(pg_ps);
|
||||
} else {
|
||||
}
|
||||
}
|
||||
|
||||
const GateBlocks &BasicCircuit::GetGateBlocks() const { return gate_blocks_; }
|
||||
} // namespace mindquantum
|
||||
} // namespace mindspore
|
|
@ -1,45 +0,0 @@
|
|||
/**
|
||||
* Copyright 2021 Huawei Technologies Co., Ltd
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef MINDQUANTUM_ENGINE_CCIRCUIT_H_
|
||||
#define MINDQUANTUM_ENGINE_CCIRCUIT_H_
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <memory>
|
||||
#include "backend/kernel_compiler/cpu/quantum/quantum_simulator/gates/non_parameter_gate.h"
|
||||
#include "backend/kernel_compiler/cpu/quantum/quantum_simulator/gates/gates.h"
|
||||
#include "backend/kernel_compiler/cpu/quantum/quantum_simulator/utils.h"
|
||||
|
||||
namespace mindspore {
|
||||
namespace mindquantum {
|
||||
using GateBlock = std::vector<std::shared_ptr<BasicGate>>;
|
||||
using GateBlocks = std::vector<GateBlock>;
|
||||
|
||||
class BasicCircuit {
|
||||
private:
|
||||
GateBlocks gate_blocks_;
|
||||
|
||||
public:
|
||||
BasicCircuit();
|
||||
void AppendBlock();
|
||||
void AppendNoneParameterGate(const std::string &, Matrix, Indexes, Indexes);
|
||||
void AppendParameterGate(const std::string &, Indexes, Indexes, const ParameterResolver &);
|
||||
const GateBlocks &GetGateBlocks() const;
|
||||
~BasicCircuit() {}
|
||||
};
|
||||
} // namespace mindquantum
|
||||
} // namespace mindspore
|
||||
#endif // MINDQUANTUM_ENGINE_CCIRCUIT_H_
|
|
@ -1,46 +0,0 @@
|
|||
/**
|
||||
* Copyright 2021 Huawei Technologies Co., Ltd
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include "backend/kernel_compiler/cpu/quantum/quantum_simulator/gates/basic_gates.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace mindspore {
|
||||
namespace mindquantum {
|
||||
BasicGate::BasicGate(const std::string &name, bool is_parameter, const Indexes &obj_qubits, const Indexes &ctrl_qubits,
|
||||
const ParameterResolver ¶s)
|
||||
: name_(name), is_parameter_(is_parameter), obj_qubits_(obj_qubits), ctrl_qubits_(ctrl_qubits), paras_(paras) {}
|
||||
|
||||
Matrix BasicGate::GetMatrix(const ParameterResolver ¶s_out) {
|
||||
Matrix gate_matrix_tmp;
|
||||
return gate_matrix_tmp;
|
||||
}
|
||||
|
||||
Matrix BasicGate::GetDiffMatrix(const ParameterResolver ¶s_out) {
|
||||
Matrix gate_matrix_tmp;
|
||||
return gate_matrix_tmp;
|
||||
}
|
||||
|
||||
Matrix &BasicGate::GetBaseMatrix() { return gate_matrix_base_; }
|
||||
|
||||
const ParameterResolver &BasicGate::GetParameterResolver() const { return paras_; }
|
||||
|
||||
bool BasicGate::IsParameterGate() { return is_parameter_; }
|
||||
|
||||
Indexes BasicGate::GetObjQubits() { return obj_qubits_; }
|
||||
|
||||
Indexes BasicGate::GetCtrlQubits() { return ctrl_qubits_; }
|
||||
} // namespace mindquantum
|
||||
} // namespace mindspore
|
|
@ -1,49 +0,0 @@
|
|||
/**
|
||||
* Copyright 2021 Huawei Technologies Co., Ltd
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef MINDQUANTUM_ENGINE_BASIC_GATES_H_
|
||||
#define MINDQUANTUM_ENGINE_BASIC_GATES_H_
|
||||
#include <string>
|
||||
#include "backend/kernel_compiler/cpu/quantum/quantum_simulator/parameter_resolver.h"
|
||||
#include "backend/kernel_compiler/cpu/quantum/quantum_simulator/utils.h"
|
||||
|
||||
namespace mindspore {
|
||||
namespace mindquantum {
|
||||
class BasicGate {
|
||||
private:
|
||||
std::string name_;
|
||||
bool is_parameter_;
|
||||
Matrix gate_matrix_base_;
|
||||
Indexes obj_qubits_;
|
||||
Indexes ctrl_qubits_;
|
||||
ParameterResolver paras_;
|
||||
|
||||
public:
|
||||
BasicGate();
|
||||
BasicGate(const std::string &, bool, const Indexes &, const Indexes &,
|
||||
const ParameterResolver ¶s = ParameterResolver());
|
||||
virtual Matrix GetMatrix(const ParameterResolver &);
|
||||
virtual Matrix GetDiffMatrix(const ParameterResolver &);
|
||||
virtual Matrix &GetBaseMatrix();
|
||||
const ParameterResolver &GetParameterResolver() const;
|
||||
bool IsParameterGate();
|
||||
Indexes GetObjQubits();
|
||||
Indexes GetCtrlQubits();
|
||||
virtual ~BasicGate() {}
|
||||
};
|
||||
} // namespace mindquantum
|
||||
} // namespace mindspore
|
||||
#endif // MINDQUANTUM_ENGINE_BASIC_GATES_H_
|
|
@ -1,166 +0,0 @@
|
|||
/**
|
||||
* Copyright 2021 Huawei Technologies Co., Ltd
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include "backend/kernel_compiler/cpu/quantum/quantum_simulator/gates/gates.h"
|
||||
|
||||
#include <cmath>
|
||||
|
||||
namespace mindspore {
|
||||
namespace mindquantum {
|
||||
RXGate::RXGate(const Indexes &obj_qubits, const Indexes &ctrl_qubits, const ParameterResolver ¶s)
|
||||
: IntrinsicOneParaGate("RX", obj_qubits, ctrl_qubits, paras) {}
|
||||
|
||||
RXGate::RXGate() : IntrinsicOneParaGate("RX", {}, {}, {}) {}
|
||||
|
||||
Matrix RXGate::GetIntrinsicMatrix(CalcType theta) {
|
||||
Matrix result = {{{cos(theta / 2), 0}, {0, -sin(theta / 2)}}, {{0, -sin(theta / 2)}, {cos(theta / 2), 0}}};
|
||||
return result;
|
||||
}
|
||||
|
||||
Matrix RXGate::GetIntrinsicDiffMatrix(CalcType theta) {
|
||||
Matrix result = {{{-sin(theta / 2) / 2, 0}, {0, -cos(theta / 2) / 2}},
|
||||
{{0, -cos(theta / 2) / 2}, {-sin(theta / 2) / 2, 0}}};
|
||||
return result;
|
||||
}
|
||||
|
||||
RYGate::RYGate(const Indexes &obj_qubits, const Indexes &ctrl_qubits, const ParameterResolver ¶s)
|
||||
: IntrinsicOneParaGate("RY", obj_qubits, ctrl_qubits, paras) {}
|
||||
|
||||
RYGate::RYGate() : IntrinsicOneParaGate("RY", {}, {}, {}) {}
|
||||
|
||||
Matrix RYGate::GetIntrinsicMatrix(CalcType theta) {
|
||||
Matrix result = {{{cos(theta / 2), 0}, {-sin(theta / 2), 0}}, {{sin(theta / 2), 0}, {cos(theta / 2), 0}}};
|
||||
return result;
|
||||
}
|
||||
|
||||
Matrix RYGate::GetIntrinsicDiffMatrix(CalcType theta) {
|
||||
Matrix result = {{{-sin(theta / 2) / 2, 0}, {-cos(theta / 2) / 2, 0}},
|
||||
{{cos(theta / 2) / 2, 0}, {-sin(theta / 2) / 2, 0}}};
|
||||
return result;
|
||||
}
|
||||
|
||||
RZGate::RZGate(const Indexes &obj_qubits, const Indexes &ctrl_qubits, const ParameterResolver ¶s)
|
||||
: IntrinsicOneParaGate("RZ", obj_qubits, ctrl_qubits, paras) {}
|
||||
|
||||
RZGate::RZGate() : IntrinsicOneParaGate("RZ", {}, {}, {}) {}
|
||||
|
||||
Matrix RZGate::GetIntrinsicMatrix(CalcType theta) {
|
||||
Matrix result = {{{cos(theta / 2), -sin(theta / 2)}, {0, 0}}, {{0, 0}, {cos(theta / 2), sin(theta / 2)}}};
|
||||
return result;
|
||||
}
|
||||
|
||||
Matrix RZGate::GetIntrinsicDiffMatrix(CalcType theta) {
|
||||
Matrix result = {{{-sin(theta / 2) / 2, -cos(theta / 2) / 2}, {0, 0}},
|
||||
{{0, 0}, {-sin(theta / 2) / 2, cos(theta / 2) / 2}}};
|
||||
return result;
|
||||
}
|
||||
|
||||
PhaseShiftGate::PhaseShiftGate(const Indexes &obj_qubits, const Indexes &ctrl_qubits, const ParameterResolver ¶s)
|
||||
: IntrinsicOneParaGate("PS", obj_qubits, ctrl_qubits, paras) {}
|
||||
|
||||
PhaseShiftGate::PhaseShiftGate() : IntrinsicOneParaGate("PS", {}, {}, {}) {}
|
||||
|
||||
Matrix PhaseShiftGate::GetIntrinsicMatrix(CalcType theta) {
|
||||
Matrix result = {{{1, 0}, {0, 0}}, {{0, 0}, {cos(theta), sin(theta)}}};
|
||||
return result;
|
||||
}
|
||||
|
||||
Matrix PhaseShiftGate::GetIntrinsicDiffMatrix(CalcType theta) {
|
||||
Matrix result = {{{0, 0}, {0, 0}}, {{0, 0}, {-sin(theta), cos(theta)}}};
|
||||
return result;
|
||||
}
|
||||
|
||||
XXGate::XXGate(const Indexes &obj_qubits, const Indexes &ctrl_qubits, const ParameterResolver ¶s)
|
||||
: IntrinsicOneParaGate("XX", obj_qubits, ctrl_qubits, paras) {}
|
||||
|
||||
XXGate::XXGate() : IntrinsicOneParaGate("XX", {}, {}, {}) {}
|
||||
|
||||
Matrix XXGate::GetIntrinsicMatrix(CalcType theta) {
|
||||
double c = cos(theta);
|
||||
double s = sin(theta);
|
||||
|
||||
Matrix result = {{{c, 0}, {0, 0}, {0, 0}, {0, -s}},
|
||||
{{0, 0}, {c, 0}, {0, -s}, {0, 0}},
|
||||
{{0, 0}, {0, -s}, {c, 0}, {0, 0}},
|
||||
{{0, -s}, {0, 0}, {0, 0}, {c, 0}}};
|
||||
return result;
|
||||
}
|
||||
|
||||
Matrix XXGate::GetIntrinsicDiffMatrix(CalcType theta) {
|
||||
double c = cos(theta);
|
||||
double s = sin(theta);
|
||||
|
||||
Matrix result = {{{-s, 0}, {0, 0}, {0, 0}, {0, -c}},
|
||||
{{0, 0}, {-s, 0}, {0, -c}, {0, 0}},
|
||||
{{0, 0}, {0, -c}, {-s, 0}, {0, 0}},
|
||||
{{0, -c}, {0, 0}, {0, 0}, {-s, 0}}};
|
||||
return result;
|
||||
}
|
||||
|
||||
YYGate::YYGate(const Indexes &obj_qubits, const Indexes &ctrl_qubits, const ParameterResolver ¶s)
|
||||
: IntrinsicOneParaGate("YY", obj_qubits, ctrl_qubits, paras) {}
|
||||
|
||||
YYGate::YYGate() : IntrinsicOneParaGate("YY", {}, {}, {}) {}
|
||||
|
||||
Matrix YYGate::GetIntrinsicMatrix(CalcType theta) {
|
||||
double c = cos(theta);
|
||||
double s = sin(theta);
|
||||
|
||||
Matrix result = {{{c, 0}, {0, 0}, {0, 0}, {0, s}},
|
||||
{{0, 0}, {c, 0}, {0, -s}, {0, 0}},
|
||||
{{0, 0}, {0, -s}, {c, 0}, {0, 0}},
|
||||
{{0, s}, {0, 0}, {0, 0}, {c, 0}}};
|
||||
return result;
|
||||
}
|
||||
|
||||
Matrix YYGate::GetIntrinsicDiffMatrix(CalcType theta) {
|
||||
double c = cos(theta);
|
||||
double s = sin(theta);
|
||||
|
||||
Matrix result = {{{-s, 0}, {0, 0}, {0, 0}, {0, c}},
|
||||
{{0, 0}, {-s, 0}, {0, -c}, {0, 0}},
|
||||
{{0, 0}, {0, -c}, {-s, 0}, {0, 0}},
|
||||
{{0, c}, {0, 0}, {0, 0}, {-s, 0}}};
|
||||
return result;
|
||||
}
|
||||
|
||||
ZZGate::ZZGate(const Indexes &obj_qubits, const Indexes &ctrl_qubits, const ParameterResolver ¶s)
|
||||
: IntrinsicOneParaGate("ZZ", obj_qubits, ctrl_qubits, paras) {}
|
||||
|
||||
ZZGate::ZZGate() : IntrinsicOneParaGate("ZZ", {}, {}, {}) {}
|
||||
|
||||
Matrix ZZGate::GetIntrinsicMatrix(CalcType theta) {
|
||||
double c = cos(theta);
|
||||
double s = sin(theta);
|
||||
|
||||
Matrix result = {{{c, -s}, {0, 0}, {0, 0}, {0, 0}},
|
||||
{{0, 0}, {c, s}, {0, 0}, {0, 0}},
|
||||
{{0, 0}, {0, 0}, {c, s}, {0, 0}},
|
||||
{{0, 0}, {0, 0}, {0, 0}, {c, -s}}};
|
||||
return result;
|
||||
}
|
||||
|
||||
Matrix ZZGate::GetIntrinsicDiffMatrix(CalcType theta) {
|
||||
double c = cos(theta);
|
||||
double s = sin(theta);
|
||||
|
||||
Matrix result = {{{-s, -c}, {0, 0}, {0, 0}, {0, 0}},
|
||||
{{0, 0}, {-s, c}, {0, 0}, {0, 0}},
|
||||
{{0, 0}, {0, 0}, {-s, c}, {0, 0}},
|
||||
{{0, 0}, {0, 0}, {0, 0}, {-s, -c}}};
|
||||
return result;
|
||||
}
|
||||
} // namespace mindquantum
|
||||
} // namespace mindspore
|
|
@ -1,95 +0,0 @@
|
|||
/**
|
||||
* Copyright 2021 Huawei Technologies Co., Ltd
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef MINDQUANTUM_ENGINE_GATES_H_
|
||||
#define MINDQUANTUM_ENGINE_GATES_H_
|
||||
#include "backend/kernel_compiler/cpu/quantum/quantum_simulator/gates/intrinsic_one_para_gate.h"
|
||||
#include "backend/kernel_compiler/cpu/quantum/quantum_simulator/utils.h"
|
||||
|
||||
namespace mindspore {
|
||||
namespace mindquantum {
|
||||
class RXGate : public IntrinsicOneParaGate {
|
||||
Matrix GetIntrinsicMatrix(CalcType) override;
|
||||
Matrix GetIntrinsicDiffMatrix(CalcType) override;
|
||||
|
||||
public:
|
||||
RXGate(const Indexes &, const Indexes &, const ParameterResolver &);
|
||||
RXGate();
|
||||
~RXGate() {}
|
||||
};
|
||||
|
||||
class RYGate : public IntrinsicOneParaGate {
|
||||
Matrix GetIntrinsicMatrix(CalcType) override;
|
||||
Matrix GetIntrinsicDiffMatrix(CalcType) override;
|
||||
|
||||
public:
|
||||
RYGate(const Indexes &, const Indexes &, const ParameterResolver &);
|
||||
RYGate();
|
||||
~RYGate() {}
|
||||
};
|
||||
|
||||
class RZGate : public IntrinsicOneParaGate {
|
||||
Matrix GetIntrinsicMatrix(CalcType) override;
|
||||
Matrix GetIntrinsicDiffMatrix(CalcType) override;
|
||||
|
||||
public:
|
||||
RZGate(const Indexes &, const Indexes &, const ParameterResolver &);
|
||||
RZGate();
|
||||
~RZGate() {}
|
||||
};
|
||||
|
||||
class PhaseShiftGate : public IntrinsicOneParaGate {
|
||||
Matrix GetIntrinsicMatrix(CalcType) override;
|
||||
Matrix GetIntrinsicDiffMatrix(CalcType) override;
|
||||
|
||||
public:
|
||||
PhaseShiftGate(const Indexes &, const Indexes &, const ParameterResolver &);
|
||||
PhaseShiftGate();
|
||||
~PhaseShiftGate() {}
|
||||
};
|
||||
|
||||
class XXGate : public IntrinsicOneParaGate {
|
||||
Matrix GetIntrinsicMatrix(CalcType) override;
|
||||
Matrix GetIntrinsicDiffMatrix(CalcType) override;
|
||||
|
||||
public:
|
||||
XXGate(const Indexes &, const Indexes &, const ParameterResolver &);
|
||||
XXGate();
|
||||
~XXGate() {}
|
||||
};
|
||||
|
||||
class YYGate : public IntrinsicOneParaGate {
|
||||
Matrix GetIntrinsicMatrix(CalcType) override;
|
||||
Matrix GetIntrinsicDiffMatrix(CalcType) override;
|
||||
|
||||
public:
|
||||
YYGate(const Indexes &, const Indexes &, const ParameterResolver &);
|
||||
YYGate();
|
||||
~YYGate() {}
|
||||
};
|
||||
|
||||
class ZZGate : public IntrinsicOneParaGate {
|
||||
Matrix GetIntrinsicMatrix(CalcType) override;
|
||||
Matrix GetIntrinsicDiffMatrix(CalcType) override;
|
||||
|
||||
public:
|
||||
ZZGate(const Indexes &, const Indexes &, const ParameterResolver &);
|
||||
ZZGate();
|
||||
~ZZGate() {}
|
||||
};
|
||||
} // namespace mindquantum
|
||||
} // namespace mindspore
|
||||
#endif // MINDQUANTUM_ENGINE_GATES_H_
|
|
@ -1,53 +0,0 @@
|
|||
/**
|
||||
* Copyright 2021 Huawei Technologies Co., Ltd
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include "backend/kernel_compiler/cpu/quantum/quantum_simulator/gates/intrinsic_one_para_gate.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace mindspore {
|
||||
namespace mindquantum {
|
||||
Matrix IntrinsicOneParaGate::GetIntrinsicMatrix(CalcType theta) {
|
||||
Matrix gate_matrix_tmp;
|
||||
return gate_matrix_tmp;
|
||||
}
|
||||
|
||||
Matrix IntrinsicOneParaGate::GetIntrinsicDiffMatrix(CalcType theta) {
|
||||
Matrix gate_matrix_tmp;
|
||||
return gate_matrix_tmp;
|
||||
}
|
||||
|
||||
IntrinsicOneParaGate::IntrinsicOneParaGate(const std::string &name, const Indexes &obj_qubits,
|
||||
const Indexes &ctrl_qubits, const ParameterResolver ¶s)
|
||||
: ParameterGate(name, obj_qubits, ctrl_qubits, paras) {}
|
||||
|
||||
CalcType IntrinsicOneParaGate::LinearCombination(const ParameterResolver ¶s_in,
|
||||
const ParameterResolver ¶s_out) {
|
||||
CalcType result = 0;
|
||||
auto ¶s_in_data = paras_in.GetData();
|
||||
auto ¶s_out_data = paras_out.GetData();
|
||||
for (ParaType::const_iterator i = paras_in_data.begin(); i != paras_in_data.end(); ++i) {
|
||||
result = result + paras_out_data.at(i->first) * (i->second);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
Matrix IntrinsicOneParaGate::GetMatrix(const ParameterResolver ¶s_out) {
|
||||
return GetIntrinsicMatrix(LinearCombination(GetParameterResolver(), paras_out));
|
||||
}
|
||||
Matrix IntrinsicOneParaGate::GetDiffMatrix(const ParameterResolver ¶s_out) {
|
||||
return GetIntrinsicDiffMatrix(LinearCombination(GetParameterResolver(), paras_out));
|
||||
}
|
||||
} // namespace mindquantum
|
||||
} // namespace mindspore
|
|
@ -1,39 +0,0 @@
|
|||
/**
|
||||
* Copyright 2021 Huawei Technologies Co., Ltd
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef MINDQUANTUM_ENGINE_INTRINSIC_ONE_PARAGATE_H_
|
||||
#define MINDQUANTUM_ENGINE_INTRINSIC_ONE_PARAGATE_H_
|
||||
#include <string>
|
||||
#include "backend/kernel_compiler/cpu/quantum/quantum_simulator/gates/parameter_gate.h"
|
||||
#include "backend/kernel_compiler/cpu/quantum/quantum_simulator/utils.h"
|
||||
|
||||
namespace mindspore {
|
||||
namespace mindquantum {
|
||||
class IntrinsicOneParaGate : public ParameterGate {
|
||||
virtual Matrix GetIntrinsicMatrix(CalcType);
|
||||
virtual Matrix GetIntrinsicDiffMatrix(CalcType);
|
||||
|
||||
public:
|
||||
IntrinsicOneParaGate();
|
||||
IntrinsicOneParaGate(const std::string &, const Indexes &, const Indexes &, const ParameterResolver &);
|
||||
CalcType LinearCombination(const ParameterResolver &, const ParameterResolver &);
|
||||
Matrix GetMatrix(const ParameterResolver &) override;
|
||||
Matrix GetDiffMatrix(const ParameterResolver &) override;
|
||||
virtual ~IntrinsicOneParaGate() {}
|
||||
};
|
||||
} // namespace mindquantum
|
||||
} // namespace mindspore
|
||||
#endif // MINDQUANTUM_ENGINE_INTRINSIC_ONE_PARAGATE_H_
|
|
@ -1,28 +0,0 @@
|
|||
/**
|
||||
* Copyright 2021 Huawei Technologies Co., Ltd
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include "backend/kernel_compiler/cpu/quantum/quantum_simulator/gates/non_parameter_gate.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace mindspore {
|
||||
namespace mindquantum {
|
||||
NoneParameterGate::NoneParameterGate(const std::string &name, const Matrix &gate_matrix, const Indexes &obj_qubits,
|
||||
const Indexes &ctrl_qubits)
|
||||
: BasicGate(name, false, obj_qubits, ctrl_qubits), gate_matrix_(gate_matrix) {}
|
||||
|
||||
Matrix &NoneParameterGate::GetBaseMatrix() { return gate_matrix_; }
|
||||
} // namespace mindquantum
|
||||
} // namespace mindspore
|
|
@ -1,35 +0,0 @@
|
|||
/**
|
||||
* Copyright 2021 Huawei Technologies Co., Ltd
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef MINDQUANTUM_ENGINE_NON_PARAMETER_GATE_H_
|
||||
#define MINDQUANTUM_ENGINE_NON_PARAMETER_GATE_H_
|
||||
#include <string>
|
||||
#include "backend/kernel_compiler/cpu/quantum/quantum_simulator/gates/basic_gates.h"
|
||||
#include "backend/kernel_compiler/cpu/quantum/quantum_simulator/utils.h"
|
||||
|
||||
namespace mindspore {
|
||||
namespace mindquantum {
|
||||
class NoneParameterGate : public BasicGate {
|
||||
private:
|
||||
Matrix gate_matrix_;
|
||||
|
||||
public:
|
||||
NoneParameterGate(const std::string &, const Matrix &, const Indexes &, const Indexes &);
|
||||
Matrix &GetBaseMatrix() override;
|
||||
};
|
||||
} // namespace mindquantum
|
||||
} // namespace mindspore
|
||||
#endif // MINDQUANTUM_ENGINE_NON_PARAMETER_GATE_H_
|
|
@ -1,26 +0,0 @@
|
|||
/**
|
||||
* Copyright 2021 Huawei Technologies Co., Ltd
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include "backend/kernel_compiler/cpu/quantum/quantum_simulator/gates/parameter_gate.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace mindspore {
|
||||
namespace mindquantum {
|
||||
ParameterGate::ParameterGate(const std::string &name, const Indexes &obj_qubits, const Indexes &ctrl_qubits,
|
||||
const ParameterResolver ¶s)
|
||||
: BasicGate(name, true, obj_qubits, ctrl_qubits, paras) {}
|
||||
} // namespace mindquantum
|
||||
} // namespace mindspore
|
|
@ -1,33 +0,0 @@
|
|||
/**
|
||||
* Copyright 2021 Huawei Technologies Co., Ltd
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef MINDQUANTUM_ENGINE_PARAMETER_GATE_H_
|
||||
#define MINDQUANTUM_ENGINE_PARAMETER_GATE_H_
|
||||
#include <string>
|
||||
#include "backend/kernel_compiler/cpu/quantum/quantum_simulator/gates/basic_gates.h"
|
||||
#include "backend/kernel_compiler/cpu/quantum/quantum_simulator/utils.h"
|
||||
|
||||
namespace mindspore {
|
||||
namespace mindquantum {
|
||||
class ParameterGate : public BasicGate {
|
||||
public:
|
||||
ParameterGate();
|
||||
ParameterGate(const std::string &, const Indexes &, const Indexes &, const ParameterResolver &);
|
||||
virtual ~ParameterGate() {}
|
||||
};
|
||||
} // namespace mindquantum
|
||||
} // namespace mindspore
|
||||
#endif // MINDQUANTUM_ENGINE_PARAMETER_GATE_H_
|
|
@ -1,79 +0,0 @@
|
|||
/**
|
||||
* Copyright 2021 Huawei Technologies Co., Ltd
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include "backend/kernel_compiler/cpu/quantum/quantum_simulator/hamiltonian.h"
|
||||
|
||||
#include <utility>
|
||||
namespace mindspore {
|
||||
namespace mindquantum {
|
||||
Hamiltonian::Hamiltonian() {}
|
||||
Hamiltonian::Hamiltonian(const sparse::GoodHamilt &ham, Index n) : ham_(ham), n_qubits_(n) {}
|
||||
|
||||
sparse::DequeSparseHam Hamiltonian::TransHamiltonianPhaseOne(int n_thread1, const sparse::GoodHamilt &ham, Index n) {
|
||||
sparse::DequeSparseHam ham_sparse;
|
||||
ham_sparse.resize(ham.size());
|
||||
int step = 0;
|
||||
#pragma omp parallel for schedule(static) num_threads(n_thread1)
|
||||
for (Index i = 0; i < ham.size(); i++) {
|
||||
auto > = ham.at(i);
|
||||
if (gt.second[0].first.size() == 0) {
|
||||
ham_sparse[i] = sparse::IdentitySparse(n) * gt.first.first * gt.second[0].second;
|
||||
} else {
|
||||
ham_sparse[i] = sparse::GoodTerm2Sparse(gt, n);
|
||||
}
|
||||
if ((++step) % 20 == 0) std::cout << "\r" << step << "\t/" << ham.size() << "\tfinshed" << std::flush;
|
||||
}
|
||||
std::cout << "\ncalculate hamiltonian phase1 finished\n";
|
||||
return ham_sparse;
|
||||
}
|
||||
|
||||
int Hamiltonian::TransHamiltonianPhaseTwo(sparse::DequeSparseHam &ham_sparse, int n_thread2, int n_split) {
|
||||
int n = ham_sparse.size();
|
||||
while (n > 1) {
|
||||
int half = n / 2 + n % 2;
|
||||
std::cout << "n: " << n << "\t, half: " << half << "\n";
|
||||
if (n < n_split) {
|
||||
break;
|
||||
}
|
||||
#pragma omp parallel for schedule(static) num_threads(half)
|
||||
for (int i = half; i < n; i++) {
|
||||
ham_sparse[i - half] += ham_sparse[i];
|
||||
}
|
||||
ham_sparse.erase(ham_sparse.end() - half + n % 2, ham_sparse.end());
|
||||
n = half;
|
||||
}
|
||||
std::cout << "total: " << ham_sparse.size() << " phase2 finished\n";
|
||||
return n;
|
||||
}
|
||||
|
||||
void Hamiltonian::SparseHamiltonian(int n_thread1, int n_thread2, int n_split) {
|
||||
ham_sparse_ = Hamiltonian::TransHamiltonianPhaseOne(n_thread1, ham_, n_qubits_);
|
||||
final_size_ = Hamiltonian::TransHamiltonianPhaseTwo(ham_sparse_, n_thread2, n_split);
|
||||
}
|
||||
|
||||
void Hamiltonian::SetTermsDict(Simulator::TermsDict const &d) {
|
||||
td_ = d;
|
||||
Simulator::ComplexTermsDict().swap(ctd_);
|
||||
for (auto &term : td_) {
|
||||
ComplexType coeff = {term.second, 0};
|
||||
ctd_.push_back(std::make_pair(term.first, coeff));
|
||||
}
|
||||
}
|
||||
|
||||
void Hamiltonian::Sparsed(bool s) { ham_sparsed_ = s; }
|
||||
const Simulator::ComplexTermsDict &Hamiltonian::GetCTD() const { return ctd_; }
|
||||
const Simulator::TermsDict &Hamiltonian::GetTD() const { return td_; }
|
||||
} // namespace mindquantum
|
||||
} // namespace mindspore
|
|
@ -1,50 +0,0 @@
|
|||
/**
|
||||
* Copyright 2021 Huawei Technologies Co., Ltd
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef MINDQUANTUM_ENGINE_CHAMILTONIAN_H_
|
||||
#define MINDQUANTUM_ENGINE_CHAMILTONIAN_H_
|
||||
#include "projectq/backends/_sim/_cppkernels/simulator.hpp"
|
||||
#include "backend/kernel_compiler/cpu/quantum/quantum_simulator/gates/basic_gates.h"
|
||||
#include "backend/kernel_compiler/cpu/quantum/quantum_simulator/sparse.h"
|
||||
#include "backend/kernel_compiler/cpu/quantum/quantum_simulator/utils.h"
|
||||
|
||||
namespace mindspore {
|
||||
namespace mindquantum {
|
||||
class Hamiltonian {
|
||||
private:
|
||||
sparse::GoodHamilt ham_;
|
||||
Index n_qubits_;
|
||||
sparse::DequeSparseHam ham_sparse_;
|
||||
Simulator::TermsDict td_;
|
||||
Simulator::ComplexTermsDict ctd_;
|
||||
int final_size_ = 1;
|
||||
bool ham_sparsed_ = false;
|
||||
|
||||
public:
|
||||
Hamiltonian();
|
||||
Hamiltonian(const sparse::GoodHamilt &, Index);
|
||||
sparse::DequeSparseHam TransHamiltonianPhaseOne(int, const sparse::GoodHamilt &, Index);
|
||||
int TransHamiltonianPhaseTwo(sparse::DequeSparseHam &, int, int);
|
||||
void SparseHamiltonian(int, int, int);
|
||||
void SetTermsDict(Simulator::TermsDict const &);
|
||||
void Sparsed(bool);
|
||||
const Simulator::ComplexTermsDict &GetCTD() const;
|
||||
const Simulator::TermsDict &GetTD() const;
|
||||
~Hamiltonian() {}
|
||||
};
|
||||
} // namespace mindquantum
|
||||
} // namespace mindspore
|
||||
#endif // MINDQUANTUM_ENGINE_CHAMILTONIAN_H_
|
|
@ -1,33 +0,0 @@
|
|||
/**
|
||||
* Copyright 2021 Huawei Technologies Co., Ltd
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "backend/kernel_compiler/cpu/quantum/quantum_simulator/parameter_resolver.h"
|
||||
|
||||
namespace mindspore {
|
||||
namespace mindquantum {
|
||||
ParameterResolver::ParameterResolver() {}
|
||||
|
||||
ParameterResolver::ParameterResolver(const ParaType &data, const ParaSetType &no_grad_parameters,
|
||||
const ParaSetType &requires_grad_parameters)
|
||||
: data_(data), no_grad_parameters_(no_grad_parameters), requires_grad_parameters_(requires_grad_parameters) {}
|
||||
|
||||
const ParaType &ParameterResolver::GetData() const { return data_; }
|
||||
const ParaSetType &ParameterResolver::GetRequiresGradParameters() const { return requires_grad_parameters_; }
|
||||
void ParameterResolver::SetData(const std::string &name, const CalcType &value) { data_[name] = value; }
|
||||
void ParameterResolver::InsertNoGrad(const std::string &name) { no_grad_parameters_.insert(name); }
|
||||
void ParameterResolver::InsertRequiresGrad(const std::string &name) { requires_grad_parameters_.insert(name); }
|
||||
} // namespace mindquantum
|
||||
} // namespace mindspore
|
|
@ -1,44 +0,0 @@
|
|||
/**
|
||||
* Copyright 2021 Huawei Technologies Co., Ltd
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef MINDQUANTUM_ENGINE_PARAMETER_RESOLVER_H_
|
||||
#define MINDQUANTUM_ENGINE_PARAMETER_RESOLVER_H_
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <set>
|
||||
#include "backend/kernel_compiler/cpu/quantum/quantum_simulator/utils.h"
|
||||
|
||||
namespace mindspore {
|
||||
namespace mindquantum {
|
||||
class ParameterResolver {
|
||||
public:
|
||||
ParameterResolver();
|
||||
ParameterResolver(const ParaType &, const ParaSetType &, const ParaSetType &);
|
||||
const ParaType &GetData() const;
|
||||
const ParaSetType &GetRequiresGradParameters() const;
|
||||
void SetData(const std::string &, const CalcType &);
|
||||
void InsertNoGrad(const std::string &);
|
||||
void InsertRequiresGrad(const std::string &);
|
||||
~ParameterResolver() {}
|
||||
|
||||
private:
|
||||
ParaType data_;
|
||||
ParaSetType no_grad_parameters_;
|
||||
ParaSetType requires_grad_parameters_;
|
||||
};
|
||||
} // namespace mindquantum
|
||||
} // namespace mindspore
|
||||
#endif // MINDQUANTUM_ENGINE_PARAMETER_RESOLVER_H_
|
|
@ -1,197 +0,0 @@
|
|||
/**
|
||||
* Copyright 2021 Huawei Technologies Co., Ltd
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include "backend/kernel_compiler/cpu/quantum/quantum_simulator/pqc_simulator.h"
|
||||
|
||||
#include <omp.h>
|
||||
#include <numeric>
|
||||
|
||||
namespace mindspore {
|
||||
namespace mindquantum {
|
||||
PQCSimulator::PQCSimulator() : Simulator(1, 1), n_qubits_(1) {
|
||||
for (Index i = 0; i < n_qubits_; i++) {
|
||||
ordering_.push_back(i);
|
||||
}
|
||||
len_ = (1UL << (n_qubits_ + 1));
|
||||
}
|
||||
|
||||
PQCSimulator::PQCSimulator(Index seed = 1, Index N = 1) : Simulator(seed, N), n_qubits_(N) {
|
||||
for (Index i = 0; i < n_qubits_; i++) {
|
||||
ordering_.push_back(i);
|
||||
}
|
||||
len_ = (1UL << (n_qubits_ + 1));
|
||||
}
|
||||
|
||||
void PQCSimulator::ApplyGate(std::shared_ptr<BasicGate> g, const ParameterResolver ¶s, bool diff) {
|
||||
if (g->IsParameterGate()) {
|
||||
if (diff) {
|
||||
PQCSimulator::apply_controlled_gate(g->GetDiffMatrix(paras), g->GetObjQubits(), g->GetCtrlQubits());
|
||||
} else {
|
||||
PQCSimulator::apply_controlled_gate(g->GetMatrix(paras), g->GetObjQubits(), g->GetCtrlQubits());
|
||||
}
|
||||
} else {
|
||||
PQCSimulator::apply_controlled_gate(g->GetBaseMatrix(), g->GetObjQubits(), g->GetCtrlQubits());
|
||||
}
|
||||
}
|
||||
|
||||
void PQCSimulator::ApplyBlock(const GateBlock &b, const mindquantum::ParameterResolver ¶s) {
|
||||
for (auto &g : b) {
|
||||
PQCSimulator::ApplyGate(g, paras, false);
|
||||
}
|
||||
PQCSimulator::run();
|
||||
}
|
||||
|
||||
void PQCSimulator::ApplyBlocks(const GateBlocks &bs, const ParameterResolver ¶s) {
|
||||
for (auto &b : bs) {
|
||||
PQCSimulator::ApplyBlock(b, paras);
|
||||
}
|
||||
}
|
||||
|
||||
void PQCSimulator::Evolution(BasicCircuit const &circuit, ParameterResolver const ¶s) {
|
||||
PQCSimulator::ApplyBlocks(circuit.GetGateBlocks(), paras);
|
||||
}
|
||||
|
||||
CalcType PQCSimulator::Measure(const Indexes &masks, bool apply) {
|
||||
CalcType out = 0;
|
||||
#pragma omp parallel for reduction(+ : out) schedule(static)
|
||||
for (unsigned i = 0; i < (1UL << n_qubits_); i++) {
|
||||
if (((i & masks[0]) == masks[0]) && ((i | masks[1]) == masks[1])) {
|
||||
out = out + vec_[2 * i] * vec_[2 * i] + vec_[2 * i + 1] * vec_[2 * i + 1];
|
||||
} else if (apply) {
|
||||
vec_[2 * i] = 0;
|
||||
vec_[2 * i + 1] = 0;
|
||||
}
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
std::vector<std::vector<float>> PQCSimulator::CalcGradient(const std::shared_ptr<CalcGradientParam> &input_params,
|
||||
PQCSimulator &s_left, PQCSimulator &s_right,
|
||||
PQCSimulator &s_right_tmp) {
|
||||
// Suppose the simulator already evaluate the circuit.
|
||||
auto circuit = input_params->circuit_cp;
|
||||
auto circuit_hermitian = input_params->circuit_hermitian_cp;
|
||||
auto hamiltonians = input_params->hamiltonians_cp;
|
||||
auto projectors = input_params->projectors_cp;
|
||||
auto is_projector = input_params->is_projector_cp;
|
||||
auto paras = input_params->paras_cp;
|
||||
auto encoder_params_names = input_params->encoder_params_names_cp;
|
||||
auto ansatz_params_names = input_params->ansatz_params_names_cp;
|
||||
auto dummy_circuit_ = input_params->dummy_circuit_cp;
|
||||
auto &circ_gate_blocks = circuit->GetGateBlocks();
|
||||
auto &circ_herm_gate_blocks = circuit_hermitian->GetGateBlocks();
|
||||
std::map<std::string, size_t> poi;
|
||||
for (size_t i = 0; i < encoder_params_names->size(); i++) {
|
||||
poi[encoder_params_names->at(i)] = i;
|
||||
}
|
||||
for (size_t i = 0; i < ansatz_params_names->size(); i++) {
|
||||
poi[ansatz_params_names->at(i)] = i + encoder_params_names->size();
|
||||
}
|
||||
if (circ_gate_blocks.size() == 0 || circ_herm_gate_blocks.size() == 0) {
|
||||
MS_LOG(EXCEPTION) << "Empty quantum circuit!";
|
||||
}
|
||||
unsigned len = circ_gate_blocks.at(0).size();
|
||||
size_t mea_size = 0;
|
||||
if (is_projector) {
|
||||
mea_size = projectors->size();
|
||||
} else {
|
||||
mea_size = hamiltonians->size();
|
||||
}
|
||||
std::vector<float> grad(mea_size * poi.size(), 0);
|
||||
std::vector<float> e0(mea_size, 0);
|
||||
|
||||
// #pragma omp parallel for
|
||||
for (size_t h_index = 0; h_index < mea_size; h_index++) {
|
||||
s_right.set_wavefunction(vec_, ordering_);
|
||||
s_left.set_wavefunction(s_right.vec_, ordering_);
|
||||
if (is_projector) {
|
||||
auto &proj = projectors->at(h_index);
|
||||
e0[h_index] = s_left.Measure(proj.GetMasks(), true);
|
||||
} else {
|
||||
auto &hamiltonian = hamiltonians->at(h_index);
|
||||
s_left.apply_qubit_operator(hamiltonian.GetCTD(), ordering_);
|
||||
e0[h_index] = static_cast<float>(ComplexInnerProduct(vec_, s_left.vec_, len_).real());
|
||||
}
|
||||
if (dummy_circuit_) {
|
||||
continue;
|
||||
}
|
||||
if (len > circ_herm_gate_blocks.at(0).size()) {
|
||||
MS_LOG(EXCEPTION) << "hermitian circuit size error!";
|
||||
}
|
||||
for (unsigned i = 0; i < len; i++) {
|
||||
if ((!circ_herm_gate_blocks.at(0)[i]->IsParameterGate()) ||
|
||||
(circ_herm_gate_blocks.at(0)[i]->GetParameterResolver().GetRequiresGradParameters().size() == 0)) {
|
||||
s_left.ApplyGate(circ_herm_gate_blocks.at(0)[i], *paras, false);
|
||||
s_right.ApplyGate(circ_herm_gate_blocks.at(0)[i], *paras, false);
|
||||
} else {
|
||||
s_right.ApplyGate(circ_herm_gate_blocks.at(0)[i], *paras, false);
|
||||
s_right.run();
|
||||
s_right_tmp.set_wavefunction(s_right.vec_, ordering_);
|
||||
s_right_tmp.ApplyGate(circ_gate_blocks.at(0)[len - 1 - i], *paras, true);
|
||||
s_right_tmp.run();
|
||||
s_left.run();
|
||||
ComplexType gi = 0;
|
||||
if (circ_herm_gate_blocks.at(0)[i]->GetCtrlQubits().size() == 0) {
|
||||
gi = ComplexInnerProduct(s_left.vec_, s_right_tmp.vec_, len_);
|
||||
} else {
|
||||
gi = ComplexInnerProductWithControl(s_left.vec_, s_right_tmp.vec_, len_,
|
||||
GetControlMask(circ_herm_gate_blocks.at(0)[i]->GetCtrlQubits()));
|
||||
}
|
||||
for (auto &it : circ_herm_gate_blocks.at(0)[i]->GetParameterResolver().GetRequiresGradParameters()) {
|
||||
grad[h_index * poi.size() + poi[it]] -= static_cast<float>(
|
||||
2 * circ_herm_gate_blocks.at(0)[i]->GetParameterResolver().GetData().at(it) * std::real(gi));
|
||||
}
|
||||
s_left.ApplyGate(circ_herm_gate_blocks.at(0)[i], *paras, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
std::vector<float> grad1;
|
||||
std::vector<float> grad2;
|
||||
for (size_t i = 0; i < mea_size; i++) {
|
||||
for (size_t j = 0; j < poi.size(); j++) {
|
||||
if (j < encoder_params_names->size()) {
|
||||
grad1.push_back(grad[i * poi.size() + j]);
|
||||
} else {
|
||||
grad2.push_back(grad[i * poi.size() + j]);
|
||||
}
|
||||
}
|
||||
}
|
||||
return {e0, grad1, grad2};
|
||||
}
|
||||
|
||||
void PQCSimulator::SetState(const StateVector &wavefunction) { Simulator::set_wavefunction(wavefunction, ordering_); }
|
||||
|
||||
std::size_t PQCSimulator::GetControlMask(Indexes const &ctrls) {
|
||||
std::size_t ctrlmask =
|
||||
std::accumulate(ctrls.begin(), ctrls.end(), 0, [&](Index a, Index b) { return a | (1UL << ordering_[b]); });
|
||||
return ctrlmask;
|
||||
}
|
||||
|
||||
void PQCSimulator::ApplyHamiltonian(const Hamiltonian &ham) {
|
||||
Simulator::apply_qubit_operator(ham.GetCTD(), ordering_);
|
||||
}
|
||||
|
||||
CalcType PQCSimulator::GetExpectationValue(const Hamiltonian &ham) {
|
||||
return Simulator::get_expectation_value(ham.GetTD(), ordering_);
|
||||
}
|
||||
void PQCSimulator::SetZeroState() {
|
||||
#pragma omp parallel for schedule(static)
|
||||
for (size_t i = 0; i < len_; i++) {
|
||||
vec_[i] = 0;
|
||||
}
|
||||
vec_[0] = 1;
|
||||
}
|
||||
} // namespace mindquantum
|
||||
} // namespace mindspore
|
|
@ -1,70 +0,0 @@
|
|||
/**
|
||||
* Copyright 2021 Huawei Technologies Co., Ltd
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef MINDQUANTUM_ENGINE_PQC_SIMULATOR_H_
|
||||
#define MINDQUANTUM_ENGINE_PQC_SIMULATOR_H_
|
||||
#include <map>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <memory>
|
||||
#include "projectq/backends/_sim/_cppkernels/simulator.hpp"
|
||||
#include "utils/log_adapter.h"
|
||||
#include "backend/kernel_compiler/cpu/quantum/quantum_simulator/gates/basic_gates.h"
|
||||
#include "backend/kernel_compiler/cpu/quantum/quantum_simulator/parameter_resolver.h"
|
||||
#include "backend/kernel_compiler/cpu/quantum/quantum_simulator/circuit.h"
|
||||
#include "backend/kernel_compiler/cpu/quantum/quantum_simulator/hamiltonian.h"
|
||||
#include "backend/kernel_compiler/cpu/quantum/quantum_simulator/utils.h"
|
||||
#include "backend/kernel_compiler/cpu/quantum/quantum_simulator/transformer.h"
|
||||
#include "backend/kernel_compiler/cpu/quantum/quantum_simulator/projector.h"
|
||||
|
||||
namespace mindspore {
|
||||
namespace mindquantum {
|
||||
struct CalcGradientParam {
|
||||
BasicCircuit *circuit_cp;
|
||||
BasicCircuit *circuit_hermitian_cp;
|
||||
transformer::Hamiltonians *hamiltonians_cp;
|
||||
transformer::Projectors *projectors_cp;
|
||||
ParameterResolver *paras_cp;
|
||||
transformer::NamesType *encoder_params_names_cp;
|
||||
transformer::NamesType *ansatz_params_names_cp;
|
||||
bool dummy_circuit_cp{false};
|
||||
bool is_projector_cp{false};
|
||||
};
|
||||
class PQCSimulator : public Simulator {
|
||||
private:
|
||||
Index n_qubits_;
|
||||
Indexes ordering_;
|
||||
Index len_;
|
||||
|
||||
public:
|
||||
PQCSimulator();
|
||||
PQCSimulator(Index seed, Index N);
|
||||
void ApplyGate(std::shared_ptr<BasicGate>, const ParameterResolver &, bool);
|
||||
void ApplyBlock(const GateBlock &, const ParameterResolver &);
|
||||
void ApplyBlocks(const GateBlocks &, const ParameterResolver &);
|
||||
void Evolution(const BasicCircuit &, const ParameterResolver &);
|
||||
CalcType Measure(const Indexes &, bool);
|
||||
void ApplyHamiltonian(const Hamiltonian &);
|
||||
CalcType GetExpectationValue(const Hamiltonian &);
|
||||
std::vector<std::vector<float>> CalcGradient(const std::shared_ptr<CalcGradientParam> &, PQCSimulator &,
|
||||
PQCSimulator &, PQCSimulator &);
|
||||
void SetState(const StateVector &);
|
||||
std::size_t GetControlMask(Indexes const &);
|
||||
void SetZeroState();
|
||||
};
|
||||
} // namespace mindquantum
|
||||
} // namespace mindspore
|
||||
#endif // MINDQUANTUM_ENGINE_PQC_SIMULATOR_H_
|
|
@ -1,41 +0,0 @@
|
|||
/**
|
||||
* Copyright 2021 Huawei Technologies Co., Ltd
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "backend/kernel_compiler/cpu/quantum/quantum_simulator/projector.h"
|
||||
|
||||
namespace mindspore {
|
||||
namespace mindquantum {
|
||||
Projector::Projector() {}
|
||||
Projector::Projector(const NameType &proj_str) : proj_str_(proj_str), n_qubits_(proj_str.length()) {}
|
||||
void Projector::HandleMask() {
|
||||
mask1_ = 0;
|
||||
mask2_ = 0;
|
||||
for (auto i : proj_str_) {
|
||||
if (i == '1') {
|
||||
mask1_ = mask1_ * 2 + 1;
|
||||
} else {
|
||||
mask1_ = mask1_ * 2;
|
||||
}
|
||||
if (i == '0') {
|
||||
mask2_ = mask2_ * 2;
|
||||
} else {
|
||||
mask2_ = mask2_ * 2 + 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
Indexes Projector::GetMasks() { return {mask1_, mask2_}; }
|
||||
} // namespace mindquantum
|
||||
} // namespace mindspore
|
|
@ -1,41 +0,0 @@
|
|||
/**
|
||||
* Copyright 2021 Huawei Technologies Co., Ltd
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef MINDQUANTUM_ENGINE_PROJECTOR_H_
|
||||
#define MINDQUANTUM_ENGINE_PROJECTOR_H_
|
||||
#include <string>
|
||||
#include "backend/kernel_compiler/cpu/quantum/quantum_simulator/utils.h"
|
||||
|
||||
namespace mindspore {
|
||||
namespace mindquantum {
|
||||
using NameType = std::string;
|
||||
class Projector {
|
||||
public:
|
||||
Projector();
|
||||
explicit Projector(const NameType &);
|
||||
void HandleMask();
|
||||
Indexes GetMasks();
|
||||
~Projector() {}
|
||||
|
||||
private:
|
||||
NameType proj_str_;
|
||||
Index n_qubits_;
|
||||
Index mask1_;
|
||||
Index mask2_;
|
||||
};
|
||||
} // namespace mindquantum
|
||||
} // namespace mindspore
|
||||
#endif // MINDQUANTUM_ENGINE_PROJECTOR_H_
|
|
@ -1,123 +0,0 @@
|
|||
/**
|
||||
* Copyright 2021 Huawei Technologies Co., Ltd
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "backend/kernel_compiler/cpu/quantum/quantum_simulator/sparse.h"
|
||||
|
||||
namespace mindspore {
|
||||
namespace mindquantum {
|
||||
namespace sparse {
|
||||
SparseMatrix BasiGateSparse(char g) {
|
||||
SparseMatrix out(2, 2);
|
||||
out.reserve(VectorXi::Constant(2, 2));
|
||||
switch (g) {
|
||||
case 'X':
|
||||
case 'x':
|
||||
out.insert(0, 1) = 1;
|
||||
out.insert(1, 0) = 1;
|
||||
break;
|
||||
|
||||
case 'Y':
|
||||
case 'y':
|
||||
out.insert(0, 1) = {0, -1};
|
||||
out.insert(1, 0) = {0, 1};
|
||||
break;
|
||||
|
||||
case 'Z':
|
||||
case 'z':
|
||||
out.insert(0, 0) = 1;
|
||||
out.insert(1, 1) = -1;
|
||||
break;
|
||||
|
||||
case '0':
|
||||
out.insert(0, 0) = 1;
|
||||
break;
|
||||
|
||||
case '1':
|
||||
out.insert(1, 1) = 1;
|
||||
break;
|
||||
|
||||
default:
|
||||
out.insert(0, 0) = 1;
|
||||
out.insert(1, 1) = 1;
|
||||
break;
|
||||
}
|
||||
|
||||
out.makeCompressed();
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
SparseMatrix IdentitySparse(int n_qubit) {
|
||||
if (n_qubit == 0) {
|
||||
int dim = static_cast<int>(1UL << n_qubit);
|
||||
SparseMatrix out(dim, dim);
|
||||
out.reserve(VectorXi::Constant(dim, dim));
|
||||
for (int i = 0; i < dim; i++) {
|
||||
out.insert(i, i) = 1;
|
||||
}
|
||||
out.makeCompressed();
|
||||
return out;
|
||||
} else {
|
||||
SparseMatrix out = BasiGateSparse('I');
|
||||
for (int i = 1; i < n_qubit; i++) {
|
||||
out = KroneckerProductSparse(out, BasiGateSparse('I')).eval();
|
||||
}
|
||||
return out;
|
||||
}
|
||||
}
|
||||
|
||||
SparseMatrix PauliTerm2Sparse(const PauliTerm &pt, Index _min, Index _max) {
|
||||
int poi;
|
||||
int n = pt.first.size();
|
||||
SparseMatrix out;
|
||||
if (pt.first[0].first == _min) {
|
||||
out = BasiGateSparse(pt.first[0].second) * pt.second;
|
||||
poi = 1;
|
||||
} else {
|
||||
out = BasiGateSparse('I') * pt.second;
|
||||
poi = 0;
|
||||
}
|
||||
|
||||
for (Index i = _min + 1; i <= _max; i++) {
|
||||
if (poi == n) {
|
||||
out = KroneckerProductSparse(IdentitySparse(_max - i + 1), out).eval();
|
||||
break;
|
||||
} else {
|
||||
if (i == pt.first[poi].first) {
|
||||
out = KroneckerProductSparse(BasiGateSparse(pt.first[poi++].second), out).eval();
|
||||
} else {
|
||||
out = KroneckerProductSparse(BasiGateSparse('I'), out).eval();
|
||||
}
|
||||
}
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
SparseMatrix GoodTerm2Sparse(const GoodTerm >, Index n_qubits) {
|
||||
SparseMatrix out = PauliTerm2Sparse(gt.second[0], gt.first.second.first, gt.first.second.second);
|
||||
for (Index i = 1; i < gt.second.size(); i++) {
|
||||
out += PauliTerm2Sparse(gt.second[i], gt.first.second.first, gt.first.second.second);
|
||||
}
|
||||
out.prune({0.0, 0.0});
|
||||
|
||||
out *= gt.first.first;
|
||||
out = KroneckerProductSparse(out, IdentitySparse(gt.first.second.first)).eval();
|
||||
out = KroneckerProductSparse(IdentitySparse(n_qubits - gt.first.second.second - 1), out).eval();
|
||||
return out;
|
||||
}
|
||||
} // namespace sparse
|
||||
} // namespace mindquantum
|
||||
} // namespace mindspore
|
|
@ -1,48 +0,0 @@
|
|||
/**
|
||||
* Copyright 2021 Huawei Technologies Co., Ltd
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef MINDQUANTUM_ENGINE_SPARSE_H_
|
||||
#define MINDQUANTUM_ENGINE_SPARSE_H_
|
||||
#include <Eigen/Dense>
|
||||
#include <Eigen/Sparse>
|
||||
#include <unsupported/Eigen/KroneckerProduct>
|
||||
#include <deque>
|
||||
#include <complex>
|
||||
#include <utility>
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
#include "backend/kernel_compiler/cpu/quantum/quantum_simulator/utils.h"
|
||||
|
||||
namespace mindspore {
|
||||
namespace mindquantum {
|
||||
namespace sparse {
|
||||
using PauliWord = std::pair<Index, char>;
|
||||
using PauliTerm = std::pair<std::vector<PauliWord>, int>;
|
||||
using GoodTerm = std::pair<std::pair<CalcType, std::pair<Index, Index>>, std::vector<PauliTerm>>;
|
||||
using GoodHamilt = std::vector<GoodTerm>;
|
||||
using EigenComplexVector = Eigen::VectorXcd;
|
||||
using Eigen::VectorXi;
|
||||
using SparseMatrix = Eigen::SparseMatrix<ComplexType, Eigen::RowMajor, int64_t>;
|
||||
using DequeSparseHam = std::deque<SparseMatrix>;
|
||||
using KroneckerProductSparse = Eigen::KroneckerProductSparse<SparseMatrix, SparseMatrix>;
|
||||
SparseMatrix BasiGateSparse(char);
|
||||
SparseMatrix IdentitySparse(int);
|
||||
SparseMatrix PauliTerm2Sparse(const PauliTerm &, Index, Index);
|
||||
SparseMatrix GoodTerm2Sparse(const GoodTerm &, Index);
|
||||
} // namespace sparse
|
||||
} // namespace mindquantum
|
||||
} // namespace mindspore
|
||||
#endif // MINDQUANTUM_ENGINE_SPARSE_H_
|
|
@ -1,124 +0,0 @@
|
|||
/**
|
||||
* Copyright 2021 Huawei Technologies Co., Ltd
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include "backend/kernel_compiler/cpu/quantum/quantum_simulator/transformer.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <utility>
|
||||
|
||||
namespace mindspore {
|
||||
namespace mindquantum {
|
||||
namespace transformer {
|
||||
Matrix MatrixConverter(const MatrixType &matrix_real, const MatrixType &matrix_imag, bool hermitian) {
|
||||
Matrix out;
|
||||
for (Index i = 0; i < matrix_real.size(); i++) {
|
||||
out.push_back({});
|
||||
for (Index j = 0; j < matrix_real.size(); j++) {
|
||||
if (hermitian)
|
||||
out.back().push_back({stod(matrix_real[j][i]), -stod(matrix_imag[j][i])});
|
||||
else
|
||||
out.back().push_back({stod(matrix_real[i][j]), stod(matrix_imag[i][j])});
|
||||
}
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
ParameterResolver ParameterResolverConverter(const ParaNameType ¶_name, const CoeffType &coeff,
|
||||
const RequireType &require_grad, bool hermitian) {
|
||||
ParameterResolver pr;
|
||||
for (Index i = 0; i < para_name.size(); i++) {
|
||||
auto name = para_name[i];
|
||||
if (hermitian)
|
||||
pr.SetData(name, -coeff[i]);
|
||||
else
|
||||
pr.SetData(name, coeff[i]);
|
||||
if (require_grad[i])
|
||||
pr.InsertRequiresGrad(name);
|
||||
else
|
||||
pr.InsertNoGrad(name);
|
||||
}
|
||||
return pr;
|
||||
}
|
||||
|
||||
std::vector<BasicCircuit> CircuitTransfor(const NamesType &names, const ComplexMatrixsType &matrixs,
|
||||
const Indexess &objs_qubits, const Indexess &ctrls_qubits,
|
||||
const ParasNameType ¶s_name, const CoeffsType &coeffs,
|
||||
const RequiresType &requires_grad) {
|
||||
BasicCircuit circuit = BasicCircuit();
|
||||
BasicCircuit herm_circuit = BasicCircuit();
|
||||
circuit.AppendBlock();
|
||||
herm_circuit.AppendBlock();
|
||||
for (Index n = 0; n < names.size(); n++) {
|
||||
Indexes obj(objs_qubits[n].size());
|
||||
Indexes ctrl(ctrls_qubits[n].size());
|
||||
std::transform(objs_qubits[n].begin(), objs_qubits[n].end(), obj.begin(),
|
||||
[](const int64_t &i) { return (Index)(i); });
|
||||
std::transform(ctrls_qubits[n].begin(), ctrls_qubits[n].end(), ctrl.begin(),
|
||||
[](const int64_t &i) { return (Index)(i); });
|
||||
if (names[n] == "npg")
|
||||
// non parameterize gate
|
||||
circuit.AppendNoneParameterGate("npg", MatrixConverter(matrixs[n][0], matrixs[n][1], false), obj, ctrl);
|
||||
else
|
||||
circuit.AppendParameterGate(names[n], obj, ctrl,
|
||||
ParameterResolverConverter(paras_name[n], coeffs[n], requires_grad[n], false));
|
||||
}
|
||||
for (Index n = 0; n < names.size(); n++) {
|
||||
Index tail = names.size() - 1 - n;
|
||||
Indexes obj(objs_qubits[tail].size());
|
||||
Indexes ctrl(ctrls_qubits[tail].size());
|
||||
std::transform(objs_qubits[tail].begin(), objs_qubits[tail].end(), obj.begin(),
|
||||
[](const int64_t &i) { return (Index)(i); });
|
||||
std::transform(ctrls_qubits[tail].begin(), ctrls_qubits[tail].end(), ctrl.begin(),
|
||||
[](const int64_t &i) { return (Index)(i); });
|
||||
if (names[tail] == "npg")
|
||||
// non parameterize gate
|
||||
herm_circuit.AppendNoneParameterGate("npg", MatrixConverter(matrixs[tail][0], matrixs[tail][1], true), obj, ctrl);
|
||||
else
|
||||
herm_circuit.AppendParameterGate(
|
||||
names[tail], obj, ctrl, ParameterResolverConverter(paras_name[tail], coeffs[tail], requires_grad[tail], true));
|
||||
}
|
||||
return {circuit, herm_circuit};
|
||||
}
|
||||
|
||||
Hamiltonians HamiltoniansTransfor(const PaulisCoeffsType &paulis_coeffs, const PaulisWordsType &paulis_words,
|
||||
const PaulisQubitsType &paulis_qubits) {
|
||||
Hamiltonians hams;
|
||||
for (Index n = 0; n < paulis_coeffs.size(); n++) {
|
||||
Hamiltonian ham;
|
||||
Simulator::TermsDict td;
|
||||
for (Index i = 0; i < paulis_coeffs[n].size(); i++) {
|
||||
Simulator::Term term;
|
||||
for (Index j = 0; j < paulis_words[n][i].size(); j++)
|
||||
term.push_back(std::make_pair((Index)(paulis_qubits[n][i][j]), paulis_words[n][i][j].at(0)));
|
||||
td.push_back(std::make_pair(term, paulis_coeffs[n][i]));
|
||||
}
|
||||
ham.SetTermsDict(td);
|
||||
hams.push_back(ham);
|
||||
}
|
||||
return hams;
|
||||
}
|
||||
|
||||
Projectors ProjectorsTransfor(const NamesType &proj_strs) {
|
||||
Projectors projs;
|
||||
for (Index n = 0; n < proj_strs.size(); n++) {
|
||||
Projector proj = Projector(proj_strs[n]);
|
||||
proj.HandleMask();
|
||||
projs.push_back(proj);
|
||||
}
|
||||
return projs;
|
||||
}
|
||||
} // namespace transformer
|
||||
} // namespace mindquantum
|
||||
} // namespace mindspore
|
|
@ -1,68 +0,0 @@
|
|||
/**
|
||||
* Copyright 2021 Huawei Technologies Co., Ltd
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef MINDQUANTUM_ENGINE_TRANSFORMER_H_
|
||||
#define MINDQUANTUM_ENGINE_TRANSFORMER_H_
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include "backend/kernel_compiler/cpu/quantum/quantum_simulator/gates/gates.h"
|
||||
#include "backend/kernel_compiler/cpu/quantum/quantum_simulator/circuit.h"
|
||||
#include "backend/kernel_compiler/cpu/quantum/quantum_simulator/utils.h"
|
||||
#include "backend/kernel_compiler/cpu/quantum/quantum_simulator/parameter_resolver.h"
|
||||
#include "backend/kernel_compiler/cpu/quantum/quantum_simulator/hamiltonian.h"
|
||||
#include "backend/kernel_compiler/cpu/quantum/quantum_simulator/projector.h"
|
||||
|
||||
namespace mindspore {
|
||||
namespace mindquantum {
|
||||
namespace transformer {
|
||||
using NameType = std::string;
|
||||
using MatrixColumnType = std::vector<std::string>;
|
||||
using MatrixType = std::vector<MatrixColumnType>;
|
||||
using ComplexMatrixType = std::vector<MatrixType>;
|
||||
using ParaNameType = std::vector<std::string>;
|
||||
using CoeffType = std::vector<float>;
|
||||
using RequireType = std::vector<bool>;
|
||||
using NamesType = std::vector<NameType>;
|
||||
using ComplexMatrixsType = std::vector<ComplexMatrixType>;
|
||||
using ParasNameType = std::vector<ParaNameType>;
|
||||
using CoeffsType = std::vector<CoeffType>;
|
||||
using RequiresType = std::vector<RequireType>;
|
||||
using Indexess = std::vector<std::vector<int64_t>>;
|
||||
using PauliCoeffsType = std::vector<float>;
|
||||
using PaulisCoeffsType = std::vector<PauliCoeffsType>;
|
||||
using PauliWordType = std::vector<std::string>;
|
||||
using PauliWordsType = std::vector<PauliWordType>;
|
||||
using PaulisWordsType = std::vector<PauliWordsType>;
|
||||
using PauliQubitType = std::vector<int64_t>;
|
||||
using PauliQubitsType = std::vector<PauliQubitType>;
|
||||
using PaulisQubitsType = std::vector<PauliQubitsType>;
|
||||
using Hamiltonians = std::vector<Hamiltonian>;
|
||||
using Projectors = std::vector<Projector>;
|
||||
|
||||
Hamiltonians HamiltoniansTransfor(const PaulisCoeffsType &, const PaulisWordsType &, const PaulisQubitsType &);
|
||||
|
||||
std::vector<BasicCircuit> CircuitTransfor(const NamesType &, const ComplexMatrixsType &, const Indexess &,
|
||||
const Indexess &, const ParasNameType &, const CoeffsType &,
|
||||
const RequiresType &);
|
||||
|
||||
Matrix MatrixConverter(const MatrixType &, const MatrixType &, bool);
|
||||
|
||||
ParameterResolver ParameterResolverConverter(const ParaNameType &, const CoeffType &, const RequireType &, bool);
|
||||
Projectors ProjectorsTransfor(const NamesType &);
|
||||
} // namespace transformer
|
||||
} // namespace mindquantum
|
||||
} // namespace mindspore
|
||||
#endif // MINDQUANTUM_ENGINE_TRANSFORMER_H_
|
|
@ -1,51 +0,0 @@
|
|||
/**
|
||||
* Copyright 2021 Huawei Technologies Co., Ltd
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "backend/kernel_compiler/cpu/quantum/quantum_simulator/utils.h"
|
||||
|
||||
namespace mindspore {
|
||||
namespace mindquantum {
|
||||
ComplexType ComplexInnerProduct(const Simulator::StateVector &v1, const Simulator::StateVector &v2, unsigned len) {
|
||||
CalcType real_part = 0;
|
||||
CalcType imag_part = 0;
|
||||
auto size = len / 2;
|
||||
#pragma omp parallel for reduction(+ : real_part, imag_part)
|
||||
for (Index i = 0; i < size; i++) {
|
||||
real_part += v1[2 * i] * v2[2 * i] + v1[2 * i + 1] * v2[2 * i + 1];
|
||||
imag_part += v1[2 * i] * v2[2 * i + 1] - v1[2 * i + 1] * v2[2 * i];
|
||||
}
|
||||
|
||||
ComplexType result = {real_part, imag_part};
|
||||
return result;
|
||||
}
|
||||
|
||||
ComplexType ComplexInnerProductWithControl(const Simulator::StateVector &v1, const Simulator::StateVector &v2,
|
||||
Index len, std::size_t ctrlmask) {
|
||||
CalcType real_part = 0;
|
||||
CalcType imag_part = 0;
|
||||
auto size = len / 2;
|
||||
#pragma omp parallel for reduction(+ : real_part, imag_part)
|
||||
for (std::size_t i = 0; i < size; i++) {
|
||||
if ((i & ctrlmask) == ctrlmask) {
|
||||
real_part += v1[2 * i] * v2[2 * i] + v1[2 * i + 1] * v2[2 * i + 1];
|
||||
imag_part += v1[2 * i] * v2[2 * i + 1] - v1[2 * i + 1] * v2[2 * i];
|
||||
}
|
||||
}
|
||||
ComplexType result = {real_part, imag_part};
|
||||
return result;
|
||||
}
|
||||
} // namespace mindquantum
|
||||
} // namespace mindspore
|
|
@ -1,59 +0,0 @@
|
|||
/**
|
||||
* Copyright 2021 Huawei Technologies Co., Ltd
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef MINDQUANTUM_ENGINE_UTILS_H_
|
||||
#define MINDQUANTUM_ENGINE_UTILS_H_
|
||||
#include <string>
|
||||
#include <complex>
|
||||
#include <vector>
|
||||
#include <map>
|
||||
#include <set>
|
||||
#include "projectq/backends/_sim/_cppkernels/intrin/alignedallocator.hpp"
|
||||
#include "projectq/backends/_sim/_cppkernels/simulator.hpp"
|
||||
|
||||
namespace mindspore {
|
||||
namespace mindquantum {
|
||||
using CalcType = double;
|
||||
using ComplexType = std::complex<CalcType>;
|
||||
using ParaType = std::map<std::string, CalcType>;
|
||||
using ParaSetType = std::set<std::string>;
|
||||
using Matrix = std::vector<std::vector<ComplexType, aligned_allocator<ComplexType, 64>>>;
|
||||
using Index = unsigned;
|
||||
using Indexes = std::vector<Index>;
|
||||
using ParaMapType = std::map<std::string, CalcType>;
|
||||
ComplexType ComplexInnerProduct(const Simulator::StateVector &, const Simulator::StateVector &, Index);
|
||||
ComplexType ComplexInnerProductWithControl(const Simulator::StateVector &, const Simulator::StateVector &, Index,
|
||||
std::size_t);
|
||||
const char kNThreads[] = "n_threads";
|
||||
const char kNQubits[] = "n_qubits";
|
||||
const char kParamNames[] = "param_names";
|
||||
const char kEncoderParamsNames[] = "encoder_params_names";
|
||||
const char kAnsatzParamsNames[] = "ansatz_params_names";
|
||||
const char kGateNames[] = "gate_names";
|
||||
const char kGateMatrix[] = "gate_matrix";
|
||||
const char kGateObjQubits[] = "gate_obj_qubits";
|
||||
const char kGateCtrlQubits[] = "gate_ctrl_qubits";
|
||||
const char kGateParamsNames[] = "gate_params_names";
|
||||
const char kGateCoeff[] = "gate_coeff";
|
||||
const char kGateRequiresGrad[] = "gate_requires_grad";
|
||||
const char kHamsPauliCoeff[] = "hams_pauli_coeff";
|
||||
const char kHamsPauliWord[] = "hams_pauli_word";
|
||||
const char kHamsPauliQubit[] = "hams_pauli_qubit";
|
||||
const char kIsProjector[] = "is_projector";
|
||||
const char kProjectors[] = "projectors";
|
||||
} // namespace mindquantum
|
||||
} // namespace mindspore
|
||||
#endif // MINDQUANTUM_ENGINE_UTILS_H_
|
|
@ -49,7 +49,6 @@ static const std::vector<std::string> sub_module_names = {
|
|||
"LITE", // SM_LITE
|
||||
"ARMOUR", // SM_ARMOUR
|
||||
"HCCL_ADPT", // SM_HCCL_ADPT
|
||||
"MINDQUANTUM", // SM_MINDQUANTUM
|
||||
"RUNTIME_FRAMEWORK", // SM_RUNTIME_FRAMEWORK
|
||||
"GE", // SM_GE
|
||||
};
|
||||
|
|
|
@ -138,7 +138,6 @@ enum SubModuleId : int {
|
|||
SM_LITE, // LITE
|
||||
SM_ARMOUR, // ARMOUR
|
||||
SM_HCCL_ADPT, // Hccl Adapter
|
||||
SM_MINDQUANTUM, // MindQuantum
|
||||
SM_RUNTIME_FRAMEWORK, // Runtime framework
|
||||
SM_GE, // GraphEngine
|
||||
NUM_SUBMODUES // number of submodules
|
||||
|
|
|
@ -16,7 +16,6 @@
|
|||
"""Generate bprop for other ops"""
|
||||
|
||||
from .. import operations as P
|
||||
from .. import composite as C
|
||||
from ..operations import _grad_ops as G
|
||||
from ..operations import _inner_ops as inner
|
||||
from ..composite.multitype_ops.zeros_like_impl import zeros_like
|
||||
|
@ -52,24 +51,6 @@ def get_bprop_iou(self):
|
|||
return bprop
|
||||
|
||||
|
||||
@bprop_getters.register(P.PQC)
|
||||
def bprop_pqc(self):
|
||||
"""Generate bprop for PQC"""
|
||||
|
||||
t = P.Transpose()
|
||||
mul = P.Mul()
|
||||
sum_ = P.ReduceSum()
|
||||
|
||||
def bprop(encoder_data, ansatz_data, out, dout):
|
||||
dx = t(out[1], (2, 0, 1))
|
||||
dx = mul(dout[0], dx)
|
||||
dx = sum_(dx, 2)
|
||||
dx = t(dx, (1, 0))
|
||||
dy = C.tensor_dot(dout[0], out[2], ((0, 1), (0, 1)))
|
||||
return dx, dy
|
||||
return bprop
|
||||
|
||||
|
||||
@bprop_getters.register(inner.SyncBatchNorm)
|
||||
def get_bprop_sync_batch_norm(self):
|
||||
"""Grad definition for `SyncBatchNorm` operation."""
|
||||
|
|
|
@ -1,18 +1,18 @@
|
|||
|
||||
0.1.0 MindSpore*1.5.0:É
|
||||
‹
|
||||
0.1.0 MindSpore*1.5.0.20211027:·
|
||||
‡
|
||||
|
||||
bprop.32:xbprop.32:[CNode]33:1bprop.32:[CNode]33:1"!S-Prim-hyper_map[zeros_like_leaf]:.Default/S-Prim-hyper_map[zeros_like_leaf]-op22
|
||||
‹
|
||||
bprop.12:xbprop.12:[CNode]:1bprop.12:[CNode]:1"!S-Prim-hyper_map[zeros_like_leaf]:.Default/S-Prim-hyper_map[zeros_like_leaf]-op22
|
||||
‡
|
||||
|
||||
bprop.32:ybprop.32:[CNode]34:2bprop.32:[CNode]34:2"!S-Prim-hyper_map[zeros_like_leaf]:.Default/S-Prim-hyper_map[zeros_like_leaf]-op23
|
||||
‰
|
||||
bprop.32:[CNode]33:1
|
||||
bprop.32:[CNode]34:2bprop.32:[CNode]35:3bprop.32:[CNode]35:3"S-Prim-MakeTuple:Default/S-Prim-MakeTuple-op24bprop.32*
|
||||
bprop.12:ybprop.12:[CNode]:2bprop.12:[CNode]:2"!S-Prim-hyper_map[zeros_like_leaf]:.Default/S-Prim-hyper_map[zeros_like_leaf]-op23
|
||||
<EFBFBD>
|
||||
bprop.12:[CNode]:1
|
||||
bprop.12:[CNode]:2bprop.12:[CNode]:3bprop.12:[CNode]:3"S-Prim-MakeTuple:Default/S-Prim-MakeTuple-op24bprop.12*
|
||||
|
||||
bprop.32:x*
|
||||
bprop.12:x*
|
||||
|
||||
bprop.32:y*
|
||||
bprop.32:out*
|
||||
bprop.32:dout2
|
||||
bprop.32:[CNode]35:3:@1c03ee41e2ae73005664666a652e28787ff0c69916d109f77e40345be916e60b
|
||||
bprop.12:y*
|
||||
bprop.12:out*
|
||||
bprop.12:dout2
|
||||
bprop.12:[CNode]:3:@1c03ee41e2ae73005664666a652e28787ff0c69916d109f77e40345be916e60b
|
|
@ -1,12 +1,10 @@
|
|||
|
||||
0.1.0 MindSpore*1.5.0:•
|
||||
Š
|
||||
|
||||
bprop.13:xbprop.13:[CNode]14:1bprop.13:[CNode]14:1"!S-Prim-hyper_map[zeros_like_leaf]:-Default/S-Prim-hyper_map[zeros_like_leaf]-op9
|
||||
s
|
||||
bprop.13:[CNode]14:1bprop.13:[CNode]15:2bprop.13:[CNode]15:2"S-Prim-MakeTuple:Default/S-Prim-MakeTuple-op10bprop.13*
|
||||
|
||||
bprop.13:x*
|
||||
bprop.13:out*
|
||||
bprop.13:dout2
|
||||
bprop.13:[CNode]15:2:@dae47635340bc244097f692e3d086cc9ae28fd823d60946e421051e28dbccdad
|
||||
0.1.0 MindSpore*1.5.0.20211027:þ
|
||||
ƒ
|
||||
bprop.6:xbprop.6:[CNode]:1bprop.6:[CNode]:1"!S-Prim-hyper_map[zeros_like_leaf]:-Default/S-Prim-hyper_map[zeros_like_leaf]-op9
|
||||
j
|
||||
bprop.6:[CNode]:1bprop.6:[CNode]:2bprop.6:[CNode]:2"S-Prim-MakeTuple:Default/S-Prim-MakeTuple-op10bprop.6*
|
||||
bprop.6:x*
|
||||
bprop.6:out*
|
||||
bprop.6:dout2
|
||||
bprop.6:[CNode]:2:@dae47635340bc244097f692e3d086cc9ae28fd823d60946e421051e28dbccdad
|
|
@ -1,12 +1,10 @@
|
|||
|
||||
0.1.0 MindSpore*1.5.0:–
|
||||
‹
|
||||
|
||||
bprop.16:xbprop.16:[CNode]17:1bprop.16:[CNode]17:1"!S-Prim-hyper_map[zeros_like_leaf]:.Default/S-Prim-hyper_map[zeros_like_leaf]-op11
|
||||
s
|
||||
bprop.16:[CNode]17:1bprop.16:[CNode]18:2bprop.16:[CNode]18:2"S-Prim-MakeTuple:Default/S-Prim-MakeTuple-op12bprop.16*
|
||||
|
||||
bprop.16:x*
|
||||
bprop.16:out*
|
||||
bprop.16:dout2
|
||||
bprop.16:[CNode]18:2:@dae47635340bc244097f692e3d086cc9ae28fd823d60946e421051e28dbccdad
|
||||
0.1.0 MindSpore*1.5.0.20211027:ÿ
|
||||
„
|
||||
bprop.7:xbprop.7:[CNode]:1bprop.7:[CNode]:1"!S-Prim-hyper_map[zeros_like_leaf]:.Default/S-Prim-hyper_map[zeros_like_leaf]-op11
|
||||
j
|
||||
bprop.7:[CNode]:1bprop.7:[CNode]:2bprop.7:[CNode]:2"S-Prim-MakeTuple:Default/S-Prim-MakeTuple-op12bprop.7*
|
||||
bprop.7:x*
|
||||
bprop.7:out*
|
||||
bprop.7:dout2
|
||||
bprop.7:[CNode]:2:@dae47635340bc244097f692e3d086cc9ae28fd823d60946e421051e28dbccdad
|
|
@ -1,18 +1,14 @@
|
|||
|
||||
0.1.0 MindSpore*1.5.0:É
|
||||
‹
|
||||
|
||||
bprop.21:xbprop.21:[CNode]22:1bprop.21:[CNode]22:1"!S-Prim-hyper_map[zeros_like_leaf]:.Default/S-Prim-hyper_map[zeros_like_leaf]-op14
|
||||
‹
|
||||
|
||||
bprop.21:ybprop.21:[CNode]23:2bprop.21:[CNode]23:2"!S-Prim-hyper_map[zeros_like_leaf]:.Default/S-Prim-hyper_map[zeros_like_leaf]-op15
|
||||
‰
|
||||
bprop.21:[CNode]22:1
|
||||
bprop.21:[CNode]23:2bprop.21:[CNode]24:3bprop.21:[CNode]24:3"S-Prim-MakeTuple:Default/S-Prim-MakeTuple-op16bprop.21*
|
||||
|
||||
bprop.21:x*
|
||||
|
||||
bprop.21:y*
|
||||
bprop.21:out*
|
||||
bprop.21:dout2
|
||||
bprop.21:[CNode]24:3:@1c03ee41e2ae73005664666a652e28787ff0c69916d109f77e40345be916e60b
|
||||
0.1.0 MindSpore*1.5.0.20211027:¦
|
||||
„
|
||||
bprop.9:xbprop.9:[CNode]:1bprop.9:[CNode]:1"!S-Prim-hyper_map[zeros_like_leaf]:.Default/S-Prim-hyper_map[zeros_like_leaf]-op14
|
||||
„
|
||||
bprop.9:ybprop.9:[CNode]:2bprop.9:[CNode]:2"!S-Prim-hyper_map[zeros_like_leaf]:.Default/S-Prim-hyper_map[zeros_like_leaf]-op15
|
||||
}
|
||||
bprop.9:[CNode]:1
|
||||
bprop.9:[CNode]:2bprop.9:[CNode]:3bprop.9:[CNode]:3"S-Prim-MakeTuple:Default/S-Prim-MakeTuple-op16bprop.9*
|
||||
bprop.9:x*
|
||||
bprop.9:y*
|
||||
bprop.9:out*
|
||||
bprop.9:dout2
|
||||
bprop.9:[CNode]:3:@1c03ee41e2ae73005664666a652e28787ff0c69916d109f77e40345be916e60b
|
|
@ -1,18 +1,18 @@
|
|||
|
||||
0.1.0 MindSpore*1.5.0:É
|
||||
‹
|
||||
0.1.0 MindSpore*1.5.0.20211027:·
|
||||
‡
|
||||
|
||||
bprop.25:xbprop.25:[CNode]26:1bprop.25:[CNode]26:1"!S-Prim-hyper_map[zeros_like_leaf]:.Default/S-Prim-hyper_map[zeros_like_leaf]-op17
|
||||
‹
|
||||
bprop.10:xbprop.10:[CNode]:1bprop.10:[CNode]:1"!S-Prim-hyper_map[zeros_like_leaf]:.Default/S-Prim-hyper_map[zeros_like_leaf]-op17
|
||||
‡
|
||||
|
||||
bprop.25:ybprop.25:[CNode]27:2bprop.25:[CNode]27:2"!S-Prim-hyper_map[zeros_like_leaf]:.Default/S-Prim-hyper_map[zeros_like_leaf]-op18
|
||||
‰
|
||||
bprop.25:[CNode]26:1
|
||||
bprop.25:[CNode]27:2bprop.25:[CNode]28:3bprop.25:[CNode]28:3"S-Prim-MakeTuple:Default/S-Prim-MakeTuple-op19bprop.25*
|
||||
bprop.10:ybprop.10:[CNode]:2bprop.10:[CNode]:2"!S-Prim-hyper_map[zeros_like_leaf]:.Default/S-Prim-hyper_map[zeros_like_leaf]-op18
|
||||
<EFBFBD>
|
||||
bprop.10:[CNode]:1
|
||||
bprop.10:[CNode]:2bprop.10:[CNode]:3bprop.10:[CNode]:3"S-Prim-MakeTuple:Default/S-Prim-MakeTuple-op19bprop.10*
|
||||
|
||||
bprop.25:x*
|
||||
bprop.10:x*
|
||||
|
||||
bprop.25:y*
|
||||
bprop.25:out*
|
||||
bprop.25:dout2
|
||||
bprop.25:[CNode]28:3:@1c03ee41e2ae73005664666a652e28787ff0c69916d109f77e40345be916e60b
|
||||
bprop.10:y*
|
||||
bprop.10:out*
|
||||
bprop.10:dout2
|
||||
bprop.10:[CNode]:3:@1c03ee41e2ae73005664666a652e28787ff0c69916d109f77e40345be916e60b
|
|
@ -1,15 +1,15 @@
|
|||
|
||||
0.1.0 MindSpore*1.5.0:´
|
||||
‹
|
||||
0.1.0 MindSpore*1.5.0.20211027:§
|
||||
‡
|
||||
|
||||
bprop.60:ybprop.60:[CNode]61:1bprop.60:[CNode]61:1"!S-Prim-hyper_map[zeros_like_leaf]:.Default/S-Prim-hyper_map[zeros_like_leaf]-op43
|
||||
‚
|
||||
bprop.60:dout
|
||||
bprop.60:[CNode]61:1bprop.60:[CNode]62:2bprop.60:[CNode]62:2"S-Prim-MakeTuple:Default/S-Prim-MakeTuple-op44bprop.60*
|
||||
bprop.19:ybprop.19:[CNode]:1bprop.19:[CNode]:1"!S-Prim-hyper_map[zeros_like_leaf]:.Default/S-Prim-hyper_map[zeros_like_leaf]-op43
|
||||
|
|
||||
bprop.19:dout
|
||||
bprop.19:[CNode]:1bprop.19:[CNode]:2bprop.19:[CNode]:2"S-Prim-MakeTuple:Default/S-Prim-MakeTuple-op44bprop.19*
|
||||
|
||||
bprop.60:x*
|
||||
bprop.19:x*
|
||||
|
||||
bprop.60:y*
|
||||
bprop.60:out*
|
||||
bprop.60:dout2
|
||||
bprop.60:[CNode]62:2:@ab258748286fc6d783abacce203dfc79d2fc31e23a427ce1f86e08777a687f71
|
||||
bprop.19:y*
|
||||
bprop.19:out*
|
||||
bprop.19:dout2
|
||||
bprop.19:[CNode]:2:@d600ac5742fbd8dc8b4b041517ce58e1beec6270a8d533616d7cfd5b4b178b15
|
|
@ -1,12 +1,12 @@
|
|||
|
||||
0.1.0 MindSpore*1.5.0:–
|
||||
‹
|
||||
0.1.0 MindSpore*1.5.0.20211027:Š
|
||||
‡
|
||||
|
||||
bprop.67:xbprop.67:[CNode]68:1bprop.67:[CNode]68:1"!S-Prim-hyper_map[zeros_like_leaf]:.Default/S-Prim-hyper_map[zeros_like_leaf]-op48
|
||||
s
|
||||
bprop.67:[CNode]68:1bprop.67:[CNode]69:2bprop.67:[CNode]69:2"S-Prim-MakeTuple:Default/S-Prim-MakeTuple-op49bprop.67*
|
||||
bprop.21:xbprop.21:[CNode]:1bprop.21:[CNode]:1"!S-Prim-hyper_map[zeros_like_leaf]:.Default/S-Prim-hyper_map[zeros_like_leaf]-op48
|
||||
m
|
||||
bprop.21:[CNode]:1bprop.21:[CNode]:2bprop.21:[CNode]:2"S-Prim-MakeTuple:Default/S-Prim-MakeTuple-op49bprop.21*
|
||||
|
||||
bprop.67:x*
|
||||
bprop.67:out*
|
||||
bprop.67:dout2
|
||||
bprop.67:[CNode]69:2:@565f906930f68ca2413e9ad958d105e129e717cd183b95d11d65a8b0b030fc0d
|
||||
bprop.21:x*
|
||||
bprop.21:out*
|
||||
bprop.21:dout2
|
||||
bprop.21:[CNode]:2:@565f906930f68ca2413e9ad958d105e129e717cd183b95d11d65a8b0b030fc0d
|
|
@ -1,9 +1,8 @@
|
|||
|
||||
0.1.0 MindSpore*1.5.0:<3A>
|
||||
l
|
||||
bprop.19:doutbprop.19:[CNode]20:1bprop.19:[CNode]20:1"S-Prim-MakeTuple:Default/S-Prim-MakeTuple-op13bprop.19*
|
||||
|
||||
bprop.19:x*
|
||||
bprop.19:out*
|
||||
bprop.19:dout2
|
||||
bprop.19:[CNode]20:1:@13f1e8534ff98b1256889fc50eb483e05dc629e575bb06330ae1f2238e2372e8
|
||||
0.1.0 MindSpore*1.5.0.20211027:ó
|
||||
e
|
||||
bprop.8:doutbprop.8:[CNode]:1bprop.8:[CNode]:1"S-Prim-MakeTuple:Default/S-Prim-MakeTuple-op13bprop.8*
|
||||
bprop.8:x*
|
||||
bprop.8:out*
|
||||
bprop.8:dout2
|
||||
bprop.8:[CNode]:1:@13f1e8534ff98b1256889fc50eb483e05dc629e575bb06330ae1f2238e2372e8
|
|
@ -1,20 +1,24 @@
|
|||
|
||||
0.1.0 MindSpore*1.5.0:·
|
||||
›
|
||||
bprop.110:dout
|
||||
bprop.110:y
|
||||
bprop.110:keep_probbprop.110:[CNode]111:1bprop.110:[CNode]111:1"S-Prim-DropoutDoMask:!Default/S-Prim-DropoutDoMask-op80
|
||||
0.1.0 MindSpore*1.5.0.20211027:ü
|
||||
<EFBFBD>
|
||||
bprop.110:ybprop.110:[CNode]112:2bprop.110:[CNode]112:2"!S-Prim-hyper_map[zeros_like_leaf]:.Default/S-Prim-hyper_map[zeros_like_leaf]-op81
|
||||
˜
|
||||
bprop.110:keep_probbprop.110:[CNode]113:3bprop.110:[CNode]113:3"!S-Prim-hyper_map[zeros_like_leaf]:.Default/S-Prim-hyper_map[zeros_like_leaf]-op82
|
||||
©
|
||||
bprop.110:[CNode]111:1
|
||||
bprop.110:[CNode]112:2
|
||||
bprop.110:[CNode]113:3bprop.110:[CNode]114:4bprop.110:[CNode]114:4"S-Prim-MakeTuple:Default/S-Prim-MakeTuple-op83 bprop.110*
|
||||
bprop.110:x*
|
||||
bprop.110:y*
|
||||
bprop.110:keep_prob*
|
||||
bprop.110:out*
|
||||
bprop.110:dout2
|
||||
bprop.110:[CNode]114:4:@5f6486474eab638624ee1777f9652b2edd3f5f2873c570e2992de1d8b0e87873
|
||||
bprop.32:dout
|
||||
|
||||
bprop.32:y
|
||||
bprop.32:keep_probbprop.32:[CNode]:1bprop.32:[CNode]:1"S-Prim-DropoutDoMask:!Default/S-Prim-DropoutDoMask-op80
|
||||
‡
|
||||
|
||||
bprop.32:ybprop.32:[CNode]:2bprop.32:[CNode]:2"!S-Prim-hyper_map[zeros_like_leaf]:.Default/S-Prim-hyper_map[zeros_like_leaf]-op81
|
||||
<EFBFBD>
|
||||
bprop.32:keep_probbprop.32:[CNode]:3bprop.32:[CNode]:3"!S-Prim-hyper_map[zeros_like_leaf]:.Default/S-Prim-hyper_map[zeros_like_leaf]-op82
|
||||
•
|
||||
bprop.32:[CNode]:1
|
||||
bprop.32:[CNode]:2
|
||||
bprop.32:[CNode]:3bprop.32:[CNode]:4bprop.32:[CNode]:4"S-Prim-MakeTuple:Default/S-Prim-MakeTuple-op83bprop.32*
|
||||
|
||||
bprop.32:x*
|
||||
|
||||
bprop.32:y*
|
||||
bprop.32:keep_prob*
|
||||
bprop.32:out*
|
||||
bprop.32:dout2
|
||||
bprop.32:[CNode]:4:@5f6486474eab638624ee1777f9652b2edd3f5f2873c570e2992de1d8b0e87873
|
|
@ -1,14 +1,14 @@
|
|||
|
||||
0.1.0 MindSpore*1.5.0:á
|
||||
0.1.0 MindSpore*1.5.0.20211027:Ï
|
||||
‹
|
||||
bprop.17:shapebprop.17:[CNode]:1bprop.17:[CNode]:1"!S-Prim-hyper_map[zeros_like_leaf]:.Default/S-Prim-hyper_map[zeros_like_leaf]-op35
|
||||
<EFBFBD>
|
||||
bprop.50:shapebprop.50:[CNode]51:1bprop.50:[CNode]51:1"!S-Prim-hyper_map[zeros_like_leaf]:.Default/S-Prim-hyper_map[zeros_like_leaf]-op35
|
||||
“
|
||||
bprop.50:keep_probbprop.50:[CNode]52:2bprop.50:[CNode]52:2"!S-Prim-hyper_map[zeros_like_leaf]:.Default/S-Prim-hyper_map[zeros_like_leaf]-op36
|
||||
‰
|
||||
bprop.50:[CNode]51:1
|
||||
bprop.50:[CNode]52:2bprop.50:[CNode]53:3bprop.50:[CNode]53:3"S-Prim-MakeTuple:Default/S-Prim-MakeTuple-op37bprop.50*
|
||||
bprop.50:shape*
|
||||
bprop.50:keep_prob*
|
||||
bprop.50:out*
|
||||
bprop.50:dout2
|
||||
bprop.50:[CNode]53:3:@5f6486474eab638624ee1777f9652b2edd3f5f2873c570e2992de1d8b0e87873
|
||||
bprop.17:keep_probbprop.17:[CNode]:2bprop.17:[CNode]:2"!S-Prim-hyper_map[zeros_like_leaf]:.Default/S-Prim-hyper_map[zeros_like_leaf]-op36
|
||||
<EFBFBD>
|
||||
bprop.17:[CNode]:1
|
||||
bprop.17:[CNode]:2bprop.17:[CNode]:3bprop.17:[CNode]:3"S-Prim-MakeTuple:Default/S-Prim-MakeTuple-op37bprop.17*
|
||||
bprop.17:shape*
|
||||
bprop.17:keep_prob*
|
||||
bprop.17:out*
|
||||
bprop.17:dout2
|
||||
bprop.17:[CNode]:3:@5f6486474eab638624ee1777f9652b2edd3f5f2873c570e2992de1d8b0e87873
|
|
@ -1,18 +1,18 @@
|
|||
|
||||
0.1.0 MindSpore*1.5.0:É
|
||||
‹
|
||||
0.1.0 MindSpore*1.5.0.20211027:·
|
||||
‡
|
||||
|
||||
bprop.70:xbprop.70:[CNode]71:1bprop.70:[CNode]71:1"!S-Prim-hyper_map[zeros_like_leaf]:.Default/S-Prim-hyper_map[zeros_like_leaf]-op50
|
||||
‹
|
||||
bprop.22:xbprop.22:[CNode]:1bprop.22:[CNode]:1"!S-Prim-hyper_map[zeros_like_leaf]:.Default/S-Prim-hyper_map[zeros_like_leaf]-op50
|
||||
‡
|
||||
|
||||
bprop.70:ybprop.70:[CNode]72:2bprop.70:[CNode]72:2"!S-Prim-hyper_map[zeros_like_leaf]:.Default/S-Prim-hyper_map[zeros_like_leaf]-op51
|
||||
‰
|
||||
bprop.70:[CNode]71:1
|
||||
bprop.70:[CNode]72:2bprop.70:[CNode]73:3bprop.70:[CNode]73:3"S-Prim-MakeTuple:Default/S-Prim-MakeTuple-op52bprop.70*
|
||||
bprop.22:ybprop.22:[CNode]:2bprop.22:[CNode]:2"!S-Prim-hyper_map[zeros_like_leaf]:.Default/S-Prim-hyper_map[zeros_like_leaf]-op51
|
||||
<EFBFBD>
|
||||
bprop.22:[CNode]:1
|
||||
bprop.22:[CNode]:2bprop.22:[CNode]:3bprop.22:[CNode]:3"S-Prim-MakeTuple:Default/S-Prim-MakeTuple-op52bprop.22*
|
||||
|
||||
bprop.70:x*
|
||||
bprop.22:x*
|
||||
|
||||
bprop.70:y*
|
||||
bprop.70:out*
|
||||
bprop.70:dout2
|
||||
bprop.70:[CNode]73:3:@1c03ee41e2ae73005664666a652e28787ff0c69916d109f77e40345be916e60b
|
||||
bprop.22:y*
|
||||
bprop.22:out*
|
||||
bprop.22:dout2
|
||||
bprop.22:[CNode]:3:@1c03ee41e2ae73005664666a652e28787ff0c69916d109f77e40345be916e60b
|
|
@ -1,18 +1,18 @@
|
|||
|
||||
0.1.0 MindSpore*1.5.0:É
|
||||
‹
|
||||
0.1.0 MindSpore*1.5.0.20211027:·
|
||||
‡
|
||||
|
||||
bprop.82:xbprop.82:[CNode]83:1bprop.82:[CNode]83:1"!S-Prim-hyper_map[zeros_like_leaf]:.Default/S-Prim-hyper_map[zeros_like_leaf]-op59
|
||||
‹
|
||||
bprop.25:xbprop.25:[CNode]:1bprop.25:[CNode]:1"!S-Prim-hyper_map[zeros_like_leaf]:.Default/S-Prim-hyper_map[zeros_like_leaf]-op59
|
||||
‡
|
||||
|
||||
bprop.82:ybprop.82:[CNode]84:2bprop.82:[CNode]84:2"!S-Prim-hyper_map[zeros_like_leaf]:.Default/S-Prim-hyper_map[zeros_like_leaf]-op60
|
||||
‰
|
||||
bprop.82:[CNode]83:1
|
||||
bprop.82:[CNode]84:2bprop.82:[CNode]85:3bprop.82:[CNode]85:3"S-Prim-MakeTuple:Default/S-Prim-MakeTuple-op61bprop.82*
|
||||
bprop.25:ybprop.25:[CNode]:2bprop.25:[CNode]:2"!S-Prim-hyper_map[zeros_like_leaf]:.Default/S-Prim-hyper_map[zeros_like_leaf]-op60
|
||||
<EFBFBD>
|
||||
bprop.25:[CNode]:1
|
||||
bprop.25:[CNode]:2bprop.25:[CNode]:3bprop.25:[CNode]:3"S-Prim-MakeTuple:Default/S-Prim-MakeTuple-op61bprop.25*
|
||||
|
||||
bprop.82:x*
|
||||
bprop.25:x*
|
||||
|
||||
bprop.82:y*
|
||||
bprop.82:out*
|
||||
bprop.82:dout2
|
||||
bprop.82:[CNode]85:3:@1c03ee41e2ae73005664666a652e28787ff0c69916d109f77e40345be916e60b
|
||||
bprop.25:y*
|
||||
bprop.25:out*
|
||||
bprop.25:dout2
|
||||
bprop.25:[CNode]:3:@1c03ee41e2ae73005664666a652e28787ff0c69916d109f77e40345be916e60b
|
|
@ -1,18 +1,18 @@
|
|||
|
||||
0.1.0 MindSpore*1.5.0:É
|
||||
‹
|
||||
0.1.0 MindSpore*1.5.0.20211027:·
|
||||
‡
|
||||
|
||||
bprop.78:xbprop.78:[CNode]79:1bprop.78:[CNode]79:1"!S-Prim-hyper_map[zeros_like_leaf]:.Default/S-Prim-hyper_map[zeros_like_leaf]-op56
|
||||
‹
|
||||
bprop.24:xbprop.24:[CNode]:1bprop.24:[CNode]:1"!S-Prim-hyper_map[zeros_like_leaf]:.Default/S-Prim-hyper_map[zeros_like_leaf]-op56
|
||||
‡
|
||||
|
||||
bprop.78:ybprop.78:[CNode]80:2bprop.78:[CNode]80:2"!S-Prim-hyper_map[zeros_like_leaf]:.Default/S-Prim-hyper_map[zeros_like_leaf]-op57
|
||||
‰
|
||||
bprop.78:[CNode]79:1
|
||||
bprop.78:[CNode]80:2bprop.78:[CNode]81:3bprop.78:[CNode]81:3"S-Prim-MakeTuple:Default/S-Prim-MakeTuple-op58bprop.78*
|
||||
bprop.24:ybprop.24:[CNode]:2bprop.24:[CNode]:2"!S-Prim-hyper_map[zeros_like_leaf]:.Default/S-Prim-hyper_map[zeros_like_leaf]-op57
|
||||
<EFBFBD>
|
||||
bprop.24:[CNode]:1
|
||||
bprop.24:[CNode]:2bprop.24:[CNode]:3bprop.24:[CNode]:3"S-Prim-MakeTuple:Default/S-Prim-MakeTuple-op58bprop.24*
|
||||
|
||||
bprop.78:x*
|
||||
bprop.24:x*
|
||||
|
||||
bprop.78:y*
|
||||
bprop.78:out*
|
||||
bprop.78:dout2
|
||||
bprop.78:[CNode]81:3:@1c03ee41e2ae73005664666a652e28787ff0c69916d109f77e40345be916e60b
|
||||
bprop.24:y*
|
||||
bprop.24:out*
|
||||
bprop.24:dout2
|
||||
bprop.24:[CNode]:3:@1c03ee41e2ae73005664666a652e28787ff0c69916d109f77e40345be916e60b
|
|
@ -1,18 +1,18 @@
|
|||
|
||||
0.1.0 MindSpore*1.5.0:É
|
||||
‹
|
||||
0.1.0 MindSpore*1.5.0.20211027:·
|
||||
‡
|
||||
|
||||
bprop.63:xbprop.63:[CNode]64:1bprop.63:[CNode]64:1"!S-Prim-hyper_map[zeros_like_leaf]:.Default/S-Prim-hyper_map[zeros_like_leaf]-op45
|
||||
‹
|
||||
bprop.20:xbprop.20:[CNode]:1bprop.20:[CNode]:1"!S-Prim-hyper_map[zeros_like_leaf]:.Default/S-Prim-hyper_map[zeros_like_leaf]-op45
|
||||
‡
|
||||
|
||||
bprop.63:ybprop.63:[CNode]65:2bprop.63:[CNode]65:2"!S-Prim-hyper_map[zeros_like_leaf]:.Default/S-Prim-hyper_map[zeros_like_leaf]-op46
|
||||
‰
|
||||
bprop.63:[CNode]64:1
|
||||
bprop.63:[CNode]65:2bprop.63:[CNode]66:3bprop.63:[CNode]66:3"S-Prim-MakeTuple:Default/S-Prim-MakeTuple-op47bprop.63*
|
||||
bprop.20:ybprop.20:[CNode]:2bprop.20:[CNode]:2"!S-Prim-hyper_map[zeros_like_leaf]:.Default/S-Prim-hyper_map[zeros_like_leaf]-op46
|
||||
<EFBFBD>
|
||||
bprop.20:[CNode]:1
|
||||
bprop.20:[CNode]:2bprop.20:[CNode]:3bprop.20:[CNode]:3"S-Prim-MakeTuple:Default/S-Prim-MakeTuple-op47bprop.20*
|
||||
|
||||
bprop.63:x*
|
||||
bprop.20:x*
|
||||
|
||||
bprop.63:y*
|
||||
bprop.63:out*
|
||||
bprop.63:dout2
|
||||
bprop.63:[CNode]66:3:@ab258748286fc6d783abacce203dfc79d2fc31e23a427ce1f86e08777a687f71
|
||||
bprop.20:y*
|
||||
bprop.20:out*
|
||||
bprop.20:dout2
|
||||
bprop.20:[CNode]:3:@d600ac5742fbd8dc8b4b041517ce58e1beec6270a8d533616d7cfd5b4b178b15
|
|
@ -1,8 +1,8 @@
|
|||
|
||||
0.1.0 MindSpore*1.5.0:õ
|
||||
f
|
||||
bprop.2:doutbprop.2:[CNode]3:1bprop.2:[CNode]3:1"S-Prim-MakeTuple:Default/S-Prim-MakeTuple-op2bprop.2*
|
||||
0.1.0 MindSpore*1.5.0.20211027:ò
|
||||
d
|
||||
bprop.2:doutbprop.2:[CNode]:1bprop.2:[CNode]:1"S-Prim-MakeTuple:Default/S-Prim-MakeTuple-op2bprop.2*
|
||||
bprop.2:x*
|
||||
bprop.2:out*
|
||||
bprop.2:dout2
|
||||
bprop.2:[CNode]3:1:@dae47635340bc244097f692e3d086cc9ae28fd823d60946e421051e28dbccdad
|
||||
bprop.2:dout2
|
||||
bprop.2:[CNode]:1:@dae47635340bc244097f692e3d086cc9ae28fd823d60946e421051e28dbccdad
|
|
@ -1,12 +1,12 @@
|
|||
|
||||
0.1.0 MindSpore*1.5.0:–
|
||||
‹
|
||||
0.1.0 MindSpore*1.5.0.20211027:Š
|
||||
‡
|
||||
|
||||
bprop.29:xbprop.29:[CNode]30:1bprop.29:[CNode]30:1"!S-Prim-hyper_map[zeros_like_leaf]:.Default/S-Prim-hyper_map[zeros_like_leaf]-op20
|
||||
s
|
||||
bprop.29:[CNode]30:1bprop.29:[CNode]31:2bprop.29:[CNode]31:2"S-Prim-MakeTuple:Default/S-Prim-MakeTuple-op21bprop.29*
|
||||
bprop.11:xbprop.11:[CNode]:1bprop.11:[CNode]:1"!S-Prim-hyper_map[zeros_like_leaf]:.Default/S-Prim-hyper_map[zeros_like_leaf]-op20
|
||||
m
|
||||
bprop.11:[CNode]:1bprop.11:[CNode]:2bprop.11:[CNode]:2"S-Prim-MakeTuple:Default/S-Prim-MakeTuple-op21bprop.11*
|
||||
|
||||
bprop.29:x*
|
||||
bprop.29:out*
|
||||
bprop.29:dout2
|
||||
bprop.29:[CNode]31:2:@1c03ee41e2ae73005664666a652e28787ff0c69916d109f77e40345be916e60b
|
||||
bprop.11:x*
|
||||
bprop.11:out*
|
||||
bprop.11:dout2
|
||||
bprop.11:[CNode]:2:@1c03ee41e2ae73005664666a652e28787ff0c69916d109f77e40345be916e60b
|
|
@ -1,18 +1,18 @@
|
|||
|
||||
0.1.0 MindSpore*1.5.0:É
|
||||
‹
|
||||
0.1.0 MindSpore*1.5.0.20211027:·
|
||||
‡
|
||||
|
||||
bprop.90:xbprop.90:[CNode]91:1bprop.90:[CNode]91:1"!S-Prim-hyper_map[zeros_like_leaf]:.Default/S-Prim-hyper_map[zeros_like_leaf]-op65
|
||||
‹
|
||||
bprop.27:xbprop.27:[CNode]:1bprop.27:[CNode]:1"!S-Prim-hyper_map[zeros_like_leaf]:.Default/S-Prim-hyper_map[zeros_like_leaf]-op65
|
||||
‡
|
||||
|
||||
bprop.90:ybprop.90:[CNode]92:2bprop.90:[CNode]92:2"!S-Prim-hyper_map[zeros_like_leaf]:.Default/S-Prim-hyper_map[zeros_like_leaf]-op66
|
||||
‰
|
||||
bprop.90:[CNode]91:1
|
||||
bprop.90:[CNode]92:2bprop.90:[CNode]93:3bprop.90:[CNode]93:3"S-Prim-MakeTuple:Default/S-Prim-MakeTuple-op67bprop.90*
|
||||
bprop.27:ybprop.27:[CNode]:2bprop.27:[CNode]:2"!S-Prim-hyper_map[zeros_like_leaf]:.Default/S-Prim-hyper_map[zeros_like_leaf]-op66
|
||||
<EFBFBD>
|
||||
bprop.27:[CNode]:1
|
||||
bprop.27:[CNode]:2bprop.27:[CNode]:3bprop.27:[CNode]:3"S-Prim-MakeTuple:Default/S-Prim-MakeTuple-op67bprop.27*
|
||||
|
||||
bprop.90:x*
|
||||
bprop.27:x*
|
||||
|
||||
bprop.90:y*
|
||||
bprop.90:out*
|
||||
bprop.90:dout2
|
||||
bprop.90:[CNode]93:3:@1c03ee41e2ae73005664666a652e28787ff0c69916d109f77e40345be916e60b
|
||||
bprop.27:y*
|
||||
bprop.27:out*
|
||||
bprop.27:dout2
|
||||
bprop.27:[CNode]:3:@1c03ee41e2ae73005664666a652e28787ff0c69916d109f77e40345be916e60b
|
|
@ -1,18 +1,18 @@
|
|||
|
||||
0.1.0 MindSpore*1.5.0:É
|
||||
‹
|
||||
0.1.0 MindSpore*1.5.0.20211027:·
|
||||
‡
|
||||
|
||||
bprop.86:xbprop.86:[CNode]87:1bprop.86:[CNode]87:1"!S-Prim-hyper_map[zeros_like_leaf]:.Default/S-Prim-hyper_map[zeros_like_leaf]-op62
|
||||
‹
|
||||
bprop.26:xbprop.26:[CNode]:1bprop.26:[CNode]:1"!S-Prim-hyper_map[zeros_like_leaf]:.Default/S-Prim-hyper_map[zeros_like_leaf]-op62
|
||||
‡
|
||||
|
||||
bprop.86:ybprop.86:[CNode]88:2bprop.86:[CNode]88:2"!S-Prim-hyper_map[zeros_like_leaf]:.Default/S-Prim-hyper_map[zeros_like_leaf]-op63
|
||||
‰
|
||||
bprop.86:[CNode]87:1
|
||||
bprop.86:[CNode]88:2bprop.86:[CNode]89:3bprop.86:[CNode]89:3"S-Prim-MakeTuple:Default/S-Prim-MakeTuple-op64bprop.86*
|
||||
bprop.26:ybprop.26:[CNode]:2bprop.26:[CNode]:2"!S-Prim-hyper_map[zeros_like_leaf]:.Default/S-Prim-hyper_map[zeros_like_leaf]-op63
|
||||
<EFBFBD>
|
||||
bprop.26:[CNode]:1
|
||||
bprop.26:[CNode]:2bprop.26:[CNode]:3bprop.26:[CNode]:3"S-Prim-MakeTuple:Default/S-Prim-MakeTuple-op64bprop.26*
|
||||
|
||||
bprop.86:x*
|
||||
bprop.26:x*
|
||||
|
||||
bprop.86:y*
|
||||
bprop.86:out*
|
||||
bprop.86:dout2
|
||||
bprop.86:[CNode]89:3:@1c03ee41e2ae73005664666a652e28787ff0c69916d109f77e40345be916e60b
|
||||
bprop.26:y*
|
||||
bprop.26:out*
|
||||
bprop.26:dout2
|
||||
bprop.26:[CNode]:3:@1c03ee41e2ae73005664666a652e28787ff0c69916d109f77e40345be916e60b
|
|
@ -1,18 +1,18 @@
|
|||
|
||||
0.1.0 MindSpore*1.5.0:<3A>
|
||||
<EFBFBD>
|
||||
bprop.45:startbprop.45:[CNode]46:1bprop.45:[CNode]46:1"!S-Prim-hyper_map[zeros_like_leaf]:.Default/S-Prim-hyper_map[zeros_like_leaf]-op31
|
||||
Ž
|
||||
bprop.45:stopbprop.45:[CNode]47:2bprop.45:[CNode]47:2"!S-Prim-hyper_map[zeros_like_leaf]:.Default/S-Prim-hyper_map[zeros_like_leaf]-op32
|
||||
<EFBFBD>
|
||||
bprop.45:numbprop.45:[CNode]48:3bprop.45:[CNode]48:3"!S-Prim-hyper_map[zeros_like_leaf]:.Default/S-Prim-hyper_map[zeros_like_leaf]-op33
|
||||
Ÿ
|
||||
bprop.45:[CNode]46:1
|
||||
bprop.45:[CNode]47:2
|
||||
bprop.45:[CNode]48:3bprop.45:[CNode]49:4bprop.45:[CNode]49:4"S-Prim-MakeTuple:Default/S-Prim-MakeTuple-op34bprop.45*
|
||||
bprop.45:start*
|
||||
bprop.45:stop*
|
||||
bprop.45:num*
|
||||
bprop.45:out*
|
||||
bprop.45:dout2
|
||||
bprop.45:[CNode]49:4:@1c03ee41e2ae73005664666a652e28787ff0c69916d109f77e40345be916e60b
|
||||
0.1.0 MindSpore*1.5.0.20211027:õ
|
||||
‹
|
||||
bprop.16:startbprop.16:[CNode]:1bprop.16:[CNode]:1"!S-Prim-hyper_map[zeros_like_leaf]:.Default/S-Prim-hyper_map[zeros_like_leaf]-op31
|
||||
Š
|
||||
bprop.16:stopbprop.16:[CNode]:2bprop.16:[CNode]:2"!S-Prim-hyper_map[zeros_like_leaf]:.Default/S-Prim-hyper_map[zeros_like_leaf]-op32
|
||||
‰
|
||||
bprop.16:numbprop.16:[CNode]:3bprop.16:[CNode]:3"!S-Prim-hyper_map[zeros_like_leaf]:.Default/S-Prim-hyper_map[zeros_like_leaf]-op33
|
||||
•
|
||||
bprop.16:[CNode]:1
|
||||
bprop.16:[CNode]:2
|
||||
bprop.16:[CNode]:3bprop.16:[CNode]:4bprop.16:[CNode]:4"S-Prim-MakeTuple:Default/S-Prim-MakeTuple-op34bprop.16*
|
||||
bprop.16:start*
|
||||
bprop.16:stop*
|
||||
bprop.16:num*
|
||||
bprop.16:out*
|
||||
bprop.16:dout2
|
||||
bprop.16:[CNode]:4:@1c03ee41e2ae73005664666a652e28787ff0c69916d109f77e40345be916e60b
|
|
@ -1,18 +1,18 @@
|
|||
|
||||
0.1.0 MindSpore*1.5.0:É
|
||||
‹
|
||||
0.1.0 MindSpore*1.5.0.20211027:·
|
||||
‡
|
||||
|
||||
bprop.94:xbprop.94:[CNode]95:1bprop.94:[CNode]95:1"!S-Prim-hyper_map[zeros_like_leaf]:.Default/S-Prim-hyper_map[zeros_like_leaf]-op68
|
||||
‹
|
||||
bprop.28:xbprop.28:[CNode]:1bprop.28:[CNode]:1"!S-Prim-hyper_map[zeros_like_leaf]:.Default/S-Prim-hyper_map[zeros_like_leaf]-op68
|
||||
‡
|
||||
|
||||
bprop.94:ybprop.94:[CNode]96:2bprop.94:[CNode]96:2"!S-Prim-hyper_map[zeros_like_leaf]:.Default/S-Prim-hyper_map[zeros_like_leaf]-op69
|
||||
‰
|
||||
bprop.94:[CNode]95:1
|
||||
bprop.94:[CNode]96:2bprop.94:[CNode]97:3bprop.94:[CNode]97:3"S-Prim-MakeTuple:Default/S-Prim-MakeTuple-op70bprop.94*
|
||||
bprop.28:ybprop.28:[CNode]:2bprop.28:[CNode]:2"!S-Prim-hyper_map[zeros_like_leaf]:.Default/S-Prim-hyper_map[zeros_like_leaf]-op69
|
||||
<EFBFBD>
|
||||
bprop.28:[CNode]:1
|
||||
bprop.28:[CNode]:2bprop.28:[CNode]:3bprop.28:[CNode]:3"S-Prim-MakeTuple:Default/S-Prim-MakeTuple-op70bprop.28*
|
||||
|
||||
bprop.94:x*
|
||||
bprop.28:x*
|
||||
|
||||
bprop.94:y*
|
||||
bprop.94:out*
|
||||
bprop.94:dout2
|
||||
bprop.94:[CNode]97:3:@1c03ee41e2ae73005664666a652e28787ff0c69916d109f77e40345be916e60b
|
||||
bprop.28:y*
|
||||
bprop.28:out*
|
||||
bprop.28:dout2
|
||||
bprop.28:[CNode]:3:@1c03ee41e2ae73005664666a652e28787ff0c69916d109f77e40345be916e60b
|
|
@ -1,12 +1,12 @@
|
|||
|
||||
0.1.0 MindSpore*1.5.0:–
|
||||
‹
|
||||
0.1.0 MindSpore*1.5.0.20211027:Š
|
||||
‡
|
||||
|
||||
bprop.39:xbprop.39:[CNode]40:1bprop.39:[CNode]40:1"!S-Prim-hyper_map[zeros_like_leaf]:.Default/S-Prim-hyper_map[zeros_like_leaf]-op27
|
||||
s
|
||||
bprop.39:[CNode]40:1bprop.39:[CNode]41:2bprop.39:[CNode]41:2"S-Prim-MakeTuple:Default/S-Prim-MakeTuple-op28bprop.39*
|
||||
bprop.14:xbprop.14:[CNode]:1bprop.14:[CNode]:1"!S-Prim-hyper_map[zeros_like_leaf]:.Default/S-Prim-hyper_map[zeros_like_leaf]-op27
|
||||
m
|
||||
bprop.14:[CNode]:1bprop.14:[CNode]:2bprop.14:[CNode]:2"S-Prim-MakeTuple:Default/S-Prim-MakeTuple-op28bprop.14*
|
||||
|
||||
bprop.39:x*
|
||||
bprop.39:out*
|
||||
bprop.39:dout2
|
||||
bprop.39:[CNode]41:2:@1c03ee41e2ae73005664666a652e28787ff0c69916d109f77e40345be916e60b
|
||||
bprop.14:x*
|
||||
bprop.14:out*
|
||||
bprop.14:dout2
|
||||
bprop.14:[CNode]:2:@1c03ee41e2ae73005664666a652e28787ff0c69916d109f77e40345be916e60b
|
|
@ -1,18 +1,18 @@
|
|||
|
||||
0.1.0 MindSpore*1.5.0:Ï
|
||||
‹
|
||||
0.1.0 MindSpore*1.5.0.20211027:·
|
||||
‡
|
||||
|
||||
bprop.98:xbprop.98:[CNode]99:1bprop.98:[CNode]99:1"!S-Prim-hyper_map[zeros_like_leaf]:.Default/S-Prim-hyper_map[zeros_like_leaf]-op71
|
||||
<EFBFBD>
|
||||
bprop.29:xbprop.29:[CNode]:1bprop.29:[CNode]:1"!S-Prim-hyper_map[zeros_like_leaf]:.Default/S-Prim-hyper_map[zeros_like_leaf]-op71
|
||||
‡
|
||||
|
||||
bprop.98:ybprop.98:[CNode]100:2bprop.98:[CNode]100:2"!S-Prim-hyper_map[zeros_like_leaf]:.Default/S-Prim-hyper_map[zeros_like_leaf]-op72
|
||||
Œ
|
||||
bprop.98:[CNode]99:1
|
||||
bprop.98:[CNode]100:2bprop.98:[CNode]101:3bprop.98:[CNode]101:3"S-Prim-MakeTuple:Default/S-Prim-MakeTuple-op73bprop.98*
|
||||
bprop.29:ybprop.29:[CNode]:2bprop.29:[CNode]:2"!S-Prim-hyper_map[zeros_like_leaf]:.Default/S-Prim-hyper_map[zeros_like_leaf]-op72
|
||||
<EFBFBD>
|
||||
bprop.29:[CNode]:1
|
||||
bprop.29:[CNode]:2bprop.29:[CNode]:3bprop.29:[CNode]:3"S-Prim-MakeTuple:Default/S-Prim-MakeTuple-op73bprop.29*
|
||||
|
||||
bprop.98:x*
|
||||
bprop.29:x*
|
||||
|
||||
bprop.98:y*
|
||||
bprop.98:out*
|
||||
bprop.98:dout2
|
||||
bprop.98:[CNode]101:3:@1c03ee41e2ae73005664666a652e28787ff0c69916d109f77e40345be916e60b
|
||||
bprop.29:y*
|
||||
bprop.29:out*
|
||||
bprop.29:dout2
|
||||
bprop.29:[CNode]:3:@1c03ee41e2ae73005664666a652e28787ff0c69916d109f77e40345be916e60b
|
|
@ -1,18 +1,18 @@
|
|||
|
||||
0.1.0 MindSpore*1.5.0:É
|
||||
‹
|
||||
0.1.0 MindSpore*1.5.0.20211027:·
|
||||
‡
|
||||
|
||||
bprop.74:xbprop.74:[CNode]75:1bprop.74:[CNode]75:1"!S-Prim-hyper_map[zeros_like_leaf]:.Default/S-Prim-hyper_map[zeros_like_leaf]-op53
|
||||
‹
|
||||
bprop.23:xbprop.23:[CNode]:1bprop.23:[CNode]:1"!S-Prim-hyper_map[zeros_like_leaf]:.Default/S-Prim-hyper_map[zeros_like_leaf]-op53
|
||||
‡
|
||||
|
||||
bprop.74:ybprop.74:[CNode]76:2bprop.74:[CNode]76:2"!S-Prim-hyper_map[zeros_like_leaf]:.Default/S-Prim-hyper_map[zeros_like_leaf]-op54
|
||||
‰
|
||||
bprop.74:[CNode]75:1
|
||||
bprop.74:[CNode]76:2bprop.74:[CNode]77:3bprop.74:[CNode]77:3"S-Prim-MakeTuple:Default/S-Prim-MakeTuple-op55bprop.74*
|
||||
bprop.23:ybprop.23:[CNode]:2bprop.23:[CNode]:2"!S-Prim-hyper_map[zeros_like_leaf]:.Default/S-Prim-hyper_map[zeros_like_leaf]-op54
|
||||
<EFBFBD>
|
||||
bprop.23:[CNode]:1
|
||||
bprop.23:[CNode]:2bprop.23:[CNode]:3bprop.23:[CNode]:3"S-Prim-MakeTuple:Default/S-Prim-MakeTuple-op55bprop.23*
|
||||
|
||||
bprop.74:x*
|
||||
bprop.23:x*
|
||||
|
||||
bprop.74:y*
|
||||
bprop.74:out*
|
||||
bprop.74:dout2
|
||||
bprop.74:[CNode]77:3:@1c03ee41e2ae73005664666a652e28787ff0c69916d109f77e40345be916e60b
|
||||
bprop.23:y*
|
||||
bprop.23:out*
|
||||
bprop.23:dout2
|
||||
bprop.23:[CNode]:3:@1c03ee41e2ae73005664666a652e28787ff0c69916d109f77e40345be916e60b
|
|
@ -1,22 +1,22 @@
|
|||
|
||||
0.1.0 MindSpore*1.5.0:ß
|
||||
‘
|
||||
bprop.54:indicesbprop.54:[CNode]55:1bprop.54:[CNode]55:1"!S-Prim-hyper_map[zeros_like_leaf]:.Default/S-Prim-hyper_map[zeros_like_leaf]-op38
|
||||
0.1.0 MindSpore*1.5.0.20211027:Á
|
||||
<EFBFBD>
|
||||
bprop.18:indicesbprop.18:[CNode]:1bprop.18:[CNode]:1"!S-Prim-hyper_map[zeros_like_leaf]:.Default/S-Prim-hyper_map[zeros_like_leaf]-op38
|
||||
‹
|
||||
bprop.18:depthbprop.18:[CNode]:2bprop.18:[CNode]:2"!S-Prim-hyper_map[zeros_like_leaf]:.Default/S-Prim-hyper_map[zeros_like_leaf]-op39
|
||||
Ž
|
||||
bprop.18:on_valuebprop.18:[CNode]:3bprop.18:[CNode]:3"!S-Prim-hyper_map[zeros_like_leaf]:.Default/S-Prim-hyper_map[zeros_like_leaf]-op40
|
||||
<EFBFBD>
|
||||
bprop.54:depthbprop.54:[CNode]56:2bprop.54:[CNode]56:2"!S-Prim-hyper_map[zeros_like_leaf]:.Default/S-Prim-hyper_map[zeros_like_leaf]-op39
|
||||
’
|
||||
bprop.54:on_valuebprop.54:[CNode]57:3bprop.54:[CNode]57:3"!S-Prim-hyper_map[zeros_like_leaf]:.Default/S-Prim-hyper_map[zeros_like_leaf]-op40
|
||||
“
|
||||
bprop.54:off_valuebprop.54:[CNode]58:4bprop.54:[CNode]58:4"!S-Prim-hyper_map[zeros_like_leaf]:.Default/S-Prim-hyper_map[zeros_like_leaf]-op41
|
||||
µ
|
||||
bprop.54:[CNode]55:1
|
||||
bprop.54:[CNode]56:2
|
||||
bprop.54:[CNode]57:3
|
||||
bprop.54:[CNode]58:4bprop.54:[CNode]59:5bprop.54:[CNode]59:5"S-Prim-MakeTuple:Default/S-Prim-MakeTuple-op42bprop.54*
|
||||
bprop.54:indices*
|
||||
bprop.54:depth*
|
||||
bprop.54:on_value*
|
||||
bprop.54:off_value*
|
||||
bprop.54:out*
|
||||
bprop.54:dout2
|
||||
bprop.54:[CNode]59:5:@5f6486474eab638624ee1777f9652b2edd3f5f2873c570e2992de1d8b0e87873
|
||||
bprop.18:off_valuebprop.18:[CNode]:4bprop.18:[CNode]:4"!S-Prim-hyper_map[zeros_like_leaf]:.Default/S-Prim-hyper_map[zeros_like_leaf]-op41
|
||||
©
|
||||
bprop.18:[CNode]:1
|
||||
bprop.18:[CNode]:2
|
||||
bprop.18:[CNode]:3
|
||||
bprop.18:[CNode]:4bprop.18:[CNode]:5bprop.18:[CNode]:5"S-Prim-MakeTuple:Default/S-Prim-MakeTuple-op42bprop.18*
|
||||
bprop.18:indices*
|
||||
bprop.18:depth*
|
||||
bprop.18:on_value*
|
||||
bprop.18:off_value*
|
||||
bprop.18:out*
|
||||
bprop.18:dout2
|
||||
bprop.18:[CNode]:5:@5f6486474eab638624ee1777f9652b2edd3f5f2873c570e2992de1d8b0e87873
|
|
@ -1,10 +1,10 @@
|
|||
|
||||
0.1.0 MindSpore*1.5.0:ƒ
|
||||
…
|
||||
bprop.7:xbprop.7:[CNode]8:1bprop.7:[CNode]8:1"!S-Prim-hyper_map[zeros_like_leaf]:-Default/S-Prim-hyper_map[zeros_like_leaf]-op5
|
||||
l
|
||||
bprop.7:[CNode]8:1bprop.7:[CNode]9:2bprop.7:[CNode]9:2"S-Prim-MakeTuple:Default/S-Prim-MakeTuple-op6bprop.7*
|
||||
bprop.7:x*
|
||||
bprop.7:out*
|
||||
bprop.7:dout2
|
||||
bprop.7:[CNode]9:2:@dae47635340bc244097f692e3d086cc9ae28fd823d60946e421051e28dbccdad
|
||||
0.1.0 MindSpore*1.5.0.20211027:ý
|
||||
ƒ
|
||||
bprop.4:xbprop.4:[CNode]:1bprop.4:[CNode]:1"!S-Prim-hyper_map[zeros_like_leaf]:-Default/S-Prim-hyper_map[zeros_like_leaf]-op5
|
||||
i
|
||||
bprop.4:[CNode]:1bprop.4:[CNode]:2bprop.4:[CNode]:2"S-Prim-MakeTuple:Default/S-Prim-MakeTuple-op6bprop.4*
|
||||
bprop.4:x*
|
||||
bprop.4:out*
|
||||
bprop.4:dout2
|
||||
bprop.4:[CNode]:2:@dae47635340bc244097f692e3d086cc9ae28fd823d60946e421051e28dbccdad
|
|
@ -1,10 +1,10 @@
|
|||
|
||||
0.1.0 MindSpore*1.5.0:ƒ
|
||||
…
|
||||
bprop.4:xbprop.4:[CNode]5:1bprop.4:[CNode]5:1"!S-Prim-hyper_map[zeros_like_leaf]:-Default/S-Prim-hyper_map[zeros_like_leaf]-op3
|
||||
l
|
||||
bprop.4:[CNode]5:1bprop.4:[CNode]6:2bprop.4:[CNode]6:2"S-Prim-MakeTuple:Default/S-Prim-MakeTuple-op4bprop.4*
|
||||
bprop.4:x*
|
||||
bprop.4:out*
|
||||
bprop.4:dout2
|
||||
bprop.4:[CNode]6:2:@dae47635340bc244097f692e3d086cc9ae28fd823d60946e421051e28dbccdad
|
||||
0.1.0 MindSpore*1.5.0.20211027:ý
|
||||
ƒ
|
||||
bprop.3:xbprop.3:[CNode]:1bprop.3:[CNode]:1"!S-Prim-hyper_map[zeros_like_leaf]:-Default/S-Prim-hyper_map[zeros_like_leaf]-op3
|
||||
i
|
||||
bprop.3:[CNode]:1bprop.3:[CNode]:2bprop.3:[CNode]:2"S-Prim-MakeTuple:Default/S-Prim-MakeTuple-op4bprop.3*
|
||||
bprop.3:x*
|
||||
bprop.3:out*
|
||||
bprop.3:dout2
|
||||
bprop.3:[CNode]:2:@dae47635340bc244097f692e3d086cc9ae28fd823d60946e421051e28dbccdad
|
|
@ -1,11 +1,11 @@
|
|||
|
||||
0.1.0 MindSpore*1.5.0:Ü
|
||||
0.1.0 MindSpore*1.5.0.20211027:Ù
|
||||
e
|
||||
bprop.0:dout
|
||||
bprop.0:outbprop.0:dx:1bprop.0:dx:1"S-Prim-ReluGrad:Default/S-Prim-ReluGrad-op0
|
||||
f
|
||||
bprop.0:dx:1bprop.0:[CNode]1:2bprop.0:[CNode]1:2"S-Prim-MakeTuple:Default/S-Prim-MakeTuple-op1bprop.0*
|
||||
bprop.0:x*
|
||||
bprop.0:out*
|
||||
bprop.0:dout2
|
||||
bprop.0:[CNode]1:2:@5f6486474eab638624ee1777f9652b2edd3f5f2873c570e2992de1d8b0e87873
|
||||
bprop.1:dout
|
||||
bprop.1:outbprop.1:dx:1bprop.1:dx:1"S-Prim-ReluGrad:Default/S-Prim-ReluGrad-op0
|
||||
d
|
||||
bprop.1:dx:1bprop.1:[CNode]:2bprop.1:[CNode]:2"S-Prim-MakeTuple:Default/S-Prim-MakeTuple-op1bprop.1*
|
||||
bprop.1:x*
|
||||
bprop.1:out*
|
||||
bprop.1:dout2
|
||||
bprop.1:[CNode]:2:@5f6486474eab638624ee1777f9652b2edd3f5f2873c570e2992de1d8b0e87873
|
|
@ -1,14 +1,16 @@
|
|||
|
||||
0.1.0 MindSpore*1.5.0:è
|
||||
<EFBFBD>
|
||||
bprop.102:xbprop.102:[CNode]103:1bprop.102:[CNode]103:1"!S-Prim-hyper_map[zeros_like_leaf]:.Default/S-Prim-hyper_map[zeros_like_leaf]-op74
|
||||
“
|
||||
bprop.102:axisbprop.102:[CNode]104:2bprop.102:[CNode]104:2"!S-Prim-hyper_map[zeros_like_leaf]:.Default/S-Prim-hyper_map[zeros_like_leaf]-op75
|
||||
‘
|
||||
bprop.102:[CNode]103:1
|
||||
bprop.102:[CNode]104:2bprop.102:[CNode]105:3bprop.102:[CNode]105:3"S-Prim-MakeTuple:Default/S-Prim-MakeTuple-op76 bprop.102*
|
||||
bprop.102:x*
|
||||
bprop.102:axis*
|
||||
bprop.102:out*
|
||||
bprop.102:dout2
|
||||
bprop.102:[CNode]105:3:@1c03ee41e2ae73005664666a652e28787ff0c69916d109f77e40345be916e60b
|
||||
0.1.0 MindSpore*1.5.0.20211027:½
|
||||
‡
|
||||
|
||||
bprop.30:xbprop.30:[CNode]:1bprop.30:[CNode]:1"!S-Prim-hyper_map[zeros_like_leaf]:.Default/S-Prim-hyper_map[zeros_like_leaf]-op74
|
||||
Š
|
||||
bprop.30:axisbprop.30:[CNode]:2bprop.30:[CNode]:2"!S-Prim-hyper_map[zeros_like_leaf]:.Default/S-Prim-hyper_map[zeros_like_leaf]-op75
|
||||
<EFBFBD>
|
||||
bprop.30:[CNode]:1
|
||||
bprop.30:[CNode]:2bprop.30:[CNode]:3bprop.30:[CNode]:3"S-Prim-MakeTuple:Default/S-Prim-MakeTuple-op76bprop.30*
|
||||
|
||||
bprop.30:x*
|
||||
bprop.30:axis*
|
||||
bprop.30:out*
|
||||
bprop.30:dout2
|
||||
bprop.30:[CNode]:3:@1c03ee41e2ae73005664666a652e28787ff0c69916d109f77e40345be916e60b
|
|
@ -1,14 +1,16 @@
|
|||
|
||||
0.1.0 MindSpore*1.5.0:è
|
||||
<EFBFBD>
|
||||
bprop.106:xbprop.106:[CNode]107:1bprop.106:[CNode]107:1"!S-Prim-hyper_map[zeros_like_leaf]:.Default/S-Prim-hyper_map[zeros_like_leaf]-op77
|
||||
“
|
||||
bprop.106:axisbprop.106:[CNode]108:2bprop.106:[CNode]108:2"!S-Prim-hyper_map[zeros_like_leaf]:.Default/S-Prim-hyper_map[zeros_like_leaf]-op78
|
||||
‘
|
||||
bprop.106:[CNode]107:1
|
||||
bprop.106:[CNode]108:2bprop.106:[CNode]109:3bprop.106:[CNode]109:3"S-Prim-MakeTuple:Default/S-Prim-MakeTuple-op79 bprop.106*
|
||||
bprop.106:x*
|
||||
bprop.106:axis*
|
||||
bprop.106:out*
|
||||
bprop.106:dout2
|
||||
bprop.106:[CNode]109:3:@1c03ee41e2ae73005664666a652e28787ff0c69916d109f77e40345be916e60b
|
||||
0.1.0 MindSpore*1.5.0.20211027:½
|
||||
‡
|
||||
|
||||
bprop.31:xbprop.31:[CNode]:1bprop.31:[CNode]:1"!S-Prim-hyper_map[zeros_like_leaf]:.Default/S-Prim-hyper_map[zeros_like_leaf]-op77
|
||||
Š
|
||||
bprop.31:axisbprop.31:[CNode]:2bprop.31:[CNode]:2"!S-Prim-hyper_map[zeros_like_leaf]:.Default/S-Prim-hyper_map[zeros_like_leaf]-op78
|
||||
<EFBFBD>
|
||||
bprop.31:[CNode]:1
|
||||
bprop.31:[CNode]:2bprop.31:[CNode]:3bprop.31:[CNode]:3"S-Prim-MakeTuple:Default/S-Prim-MakeTuple-op79bprop.31*
|
||||
|
||||
bprop.31:x*
|
||||
bprop.31:axis*
|
||||
bprop.31:out*
|
||||
bprop.31:dout2
|
||||
bprop.31:[CNode]:3:@1c03ee41e2ae73005664666a652e28787ff0c69916d109f77e40345be916e60b
|
|
@ -1,12 +1,12 @@
|
|||
|
||||
0.1.0 MindSpore*1.5.0:–
|
||||
‹
|
||||
0.1.0 MindSpore*1.5.0.20211027:Š
|
||||
‡
|
||||
|
||||
bprop.42:xbprop.42:[CNode]43:1bprop.42:[CNode]43:1"!S-Prim-hyper_map[zeros_like_leaf]:.Default/S-Prim-hyper_map[zeros_like_leaf]-op29
|
||||
s
|
||||
bprop.42:[CNode]43:1bprop.42:[CNode]44:2bprop.42:[CNode]44:2"S-Prim-MakeTuple:Default/S-Prim-MakeTuple-op30bprop.42*
|
||||
bprop.15:xbprop.15:[CNode]:1bprop.15:[CNode]:1"!S-Prim-hyper_map[zeros_like_leaf]:.Default/S-Prim-hyper_map[zeros_like_leaf]-op29
|
||||
m
|
||||
bprop.15:[CNode]:1bprop.15:[CNode]:2bprop.15:[CNode]:2"S-Prim-MakeTuple:Default/S-Prim-MakeTuple-op30bprop.15*
|
||||
|
||||
bprop.42:x*
|
||||
bprop.42:out*
|
||||
bprop.42:dout2
|
||||
bprop.42:[CNode]44:2:@1c03ee41e2ae73005664666a652e28787ff0c69916d109f77e40345be916e60b
|
||||
bprop.15:x*
|
||||
bprop.15:out*
|
||||
bprop.15:dout2
|
||||
bprop.15:[CNode]:2:@1c03ee41e2ae73005664666a652e28787ff0c69916d109f77e40345be916e60b
|
|
@ -1,12 +1,12 @@
|
|||
|
||||
0.1.0 MindSpore*1.5.0:–
|
||||
‹
|
||||
0.1.0 MindSpore*1.5.0.20211027:Š
|
||||
‡
|
||||
|
||||
bprop.36:xbprop.36:[CNode]37:1bprop.36:[CNode]37:1"!S-Prim-hyper_map[zeros_like_leaf]:.Default/S-Prim-hyper_map[zeros_like_leaf]-op25
|
||||
s
|
||||
bprop.36:[CNode]37:1bprop.36:[CNode]38:2bprop.36:[CNode]38:2"S-Prim-MakeTuple:Default/S-Prim-MakeTuple-op26bprop.36*
|
||||
bprop.13:xbprop.13:[CNode]:1bprop.13:[CNode]:1"!S-Prim-hyper_map[zeros_like_leaf]:.Default/S-Prim-hyper_map[zeros_like_leaf]-op25
|
||||
m
|
||||
bprop.13:[CNode]:1bprop.13:[CNode]:2bprop.13:[CNode]:2"S-Prim-MakeTuple:Default/S-Prim-MakeTuple-op26bprop.13*
|
||||
|
||||
bprop.36:x*
|
||||
bprop.36:out*
|
||||
bprop.36:dout2
|
||||
bprop.36:[CNode]38:2:@1c03ee41e2ae73005664666a652e28787ff0c69916d109f77e40345be916e60b
|
||||
bprop.13:x*
|
||||
bprop.13:out*
|
||||
bprop.13:dout2
|
||||
bprop.13:[CNode]:2:@1c03ee41e2ae73005664666a652e28787ff0c69916d109f77e40345be916e60b
|
|
@ -1,12 +1,10 @@
|
|||
|
||||
0.1.0 MindSpore*1.5.0:”
|
||||
Š
|
||||
|
||||
bprop.10:xbprop.10:[CNode]11:1bprop.10:[CNode]11:1"!S-Prim-hyper_map[zeros_like_leaf]:-Default/S-Prim-hyper_map[zeros_like_leaf]-op7
|
||||
r
|
||||
bprop.10:[CNode]11:1bprop.10:[CNode]12:2bprop.10:[CNode]12:2"S-Prim-MakeTuple:Default/S-Prim-MakeTuple-op8bprop.10*
|
||||
|
||||
bprop.10:x*
|
||||
bprop.10:out*
|
||||
bprop.10:dout2
|
||||
bprop.10:[CNode]12:2:@dae47635340bc244097f692e3d086cc9ae28fd823d60946e421051e28dbccdad
|
||||
0.1.0 MindSpore*1.5.0.20211027:ý
|
||||
ƒ
|
||||
bprop.5:xbprop.5:[CNode]:1bprop.5:[CNode]:1"!S-Prim-hyper_map[zeros_like_leaf]:-Default/S-Prim-hyper_map[zeros_like_leaf]-op7
|
||||
i
|
||||
bprop.5:[CNode]:1bprop.5:[CNode]:2bprop.5:[CNode]:2"S-Prim-MakeTuple:Default/S-Prim-MakeTuple-op8bprop.5*
|
||||
bprop.5:x*
|
||||
bprop.5:out*
|
||||
bprop.5:dout2
|
||||
bprop.5:[CNode]:2:@dae47635340bc244097f692e3d086cc9ae28fd823d60946e421051e28dbccdad
|
|
@ -101,7 +101,6 @@ from ._thor_ops import (CusBatchMatMul, CusCholeskyTrsm, CusFusedAbsMax1, CusImg
|
|||
from .sparse_ops import (SparseToDense, SparseTensorDenseMatmul)
|
||||
from ._embedding_cache_ops import (CacheSwapTable, UpdateCache, MapCacheIdx, SubAndFilter,
|
||||
MapUniform, DynamicAssign, PadAndShift)
|
||||
from .quantum_ops import PQC, Evolution
|
||||
from .sponge_ops import (BondForce, BondEnergy, BondAtomEnergy, BondForceWithAtomEnergy, BondForceWithAtomVirial,
|
||||
DihedralForce, DihedralEnergy, DihedralAtomEnergy, DihedralForceWithAtomEnergy, AngleForce,
|
||||
AngleEnergy, AngleAtomEnergy, AngleForceWithAtomEnergy, PMEReciprocalForce,
|
||||
|
@ -466,8 +465,6 @@ __all__ = [
|
|||
"Range",
|
||||
"SearchSorted",
|
||||
"IndexAdd",
|
||||
"PQC",
|
||||
"Evolution",
|
||||
"AdaptiveAvgPool2D",
|
||||
"TensorScatterMax",
|
||||
"TensorScatterMin",
|
||||
|
|
|
@ -1,136 +0,0 @@
|
|||
# Copyright 2021 Huawei Technologies Co., Ltd
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
# ============================================================================
|
||||
"""Operators for quantum computing."""
|
||||
|
||||
from ..primitive import PrimitiveWithInfer, prim_attr_register
|
||||
from ..._checkparam import Validator as validator
|
||||
from ...common import dtype as mstype
|
||||
|
||||
|
||||
class PQC(PrimitiveWithInfer):
|
||||
r"""
|
||||
Evaluate a parameterized quantum circuit and calculate the gradient of each parameters.
|
||||
|
||||
Inputs of this operation is generated by MindQuantum framework.
|
||||
|
||||
Inputs:
|
||||
- **n_qubits** (int) - The qubit number of quantum simulator.
|
||||
- **encoder_params_names** (List[str]) - The parameters names of encoder circuit.
|
||||
- **ansatz_params_names** (List[str]) - The parameters names of ansatz circuit.
|
||||
- **gate_names** (List[str]) - The name of each gate.
|
||||
- **gate_matrix** (List[List[List[List[float]]]]) - Real part and image
|
||||
part of the matrix of quantum gate.
|
||||
- **gate_obj_qubits** (List[List[int]]) - Object qubits of each gate.
|
||||
- **gate_ctrl_qubits** (List[List[int]]) - Control qubits of each gate.
|
||||
- **gate_params_names** (List[List[str]]) - Parameter names of each gate.
|
||||
- **gate_coeff** (List[List[float]]) - Coefficient of each parameter of each gate.
|
||||
- **gate_requires_grad** (List[List[bool]]) - Whether to calculate gradient
|
||||
of parameters of gates.
|
||||
- **hams_pauli_coeff** (List[List[float]]) - Coefficient of pauli words.
|
||||
- **hams_pauli_word** (List[List[List[str]]]) - Pauli words.
|
||||
- **hams_pauli_qubit** (List[List[List[int]]]) - The qubit that pauli matrix act on.
|
||||
- **n_threads** (int) - Thread to evaluate input data.
|
||||
|
||||
Outputs:
|
||||
- **expected_value** (Tensor) - The expected value of hamiltonian.
|
||||
- **g1** (Tensor) - Gradient of encode circuit parameters.
|
||||
- **g2** (Tensor) - Gradient of ansatz circuit parameters.
|
||||
|
||||
Supported Platforms:
|
||||
``CPU``
|
||||
"""
|
||||
@prim_attr_register
|
||||
def __init__(self, n_qubits, encoder_params_names, ansatz_params_names,
|
||||
gate_names, gate_matrix, gate_obj_qubits, gate_ctrl_qubits,
|
||||
gate_params_names, gate_coeff, gate_requires_grad,
|
||||
hams_pauli_coeff, hams_pauli_word, hams_pauli_qubit,
|
||||
n_threads):
|
||||
self.init_prim_io_names(
|
||||
inputs=['encoder_data', 'ansatz_data'],
|
||||
outputs=['results', 'encoder_gradient', 'ansatz_gradient'])
|
||||
self.n_hams = len(hams_pauli_coeff)
|
||||
|
||||
def check_shape_size(self, encoder_data, ansatz_data):
|
||||
if len(encoder_data) != 2:
|
||||
raise ValueError(f"For '{self.name}', the dimension of 'encoder_data' should be 2, "
|
||||
f"but got {len(encoder_data)}.")
|
||||
if len(ansatz_data) != 1:
|
||||
raise ValueError(f"For '{self.name}', the dimension of 'ansatz_data' should be 1, "
|
||||
f"but got {len(ansatz_data)}.")
|
||||
|
||||
def infer_shape(self, encoder_data, ansatz_data):
|
||||
self.check_shape_size(encoder_data, ansatz_data)
|
||||
return [encoder_data[0], self.n_hams], [
|
||||
encoder_data[0], self.n_hams,
|
||||
len(self.encoder_params_names)
|
||||
], [encoder_data[0], self.n_hams,
|
||||
len(self.ansatz_params_names)]
|
||||
|
||||
def infer_dtype(self, encoder_data, ansatz_data):
|
||||
args = {'encoder_data': encoder_data, 'ansatz_data': ansatz_data}
|
||||
validator.check_tensors_dtypes_same_and_valid(args, mstype.float_type,
|
||||
self.name)
|
||||
return encoder_data, encoder_data, encoder_data
|
||||
|
||||
|
||||
class Evolution(PrimitiveWithInfer):
|
||||
r"""
|
||||
Inputs of this operation is generated by MindQuantum framework.
|
||||
|
||||
Inputs:
|
||||
- **n_qubits** (int) - The qubit number of quantum simulator.
|
||||
- **param_names** (List[str]) - The parameters names.
|
||||
- **gate_names** (List[str]) - The name of each gate.
|
||||
- **gate_matrix** (List[List[List[List[float]]]]) - Real part and image
|
||||
part of the matrix of quantum gate.
|
||||
- **gate_obj_qubits** (List[List[int]]) - Object qubits of each gate.
|
||||
- **gate_ctrl_qubits** (List[List[int]]) - Control qubits of each gate.
|
||||
- **gate_params_names** (List[List[str]]) - Parameter names of each gate.
|
||||
- **gate_coeff** (List[List[float]]) - Coefficient of each parameter of each gate.
|
||||
- **gate_requires_grad** (List[List[bool]]) - Whether to calculate gradient
|
||||
of parameters of gates.
|
||||
- **hams_pauli_coeff** (List[List[float]]) - Coefficient of pauli words.
|
||||
- **hams_pauli_word** (List[List[List[str]]]) - Pauli words.
|
||||
- **hams_pauli_qubit** (List[List[List[int]]]) - The qubit that pauli matrix act on.
|
||||
|
||||
Outputs:
|
||||
- **Quantum state** (Tensor) - The quantum state after evolution.
|
||||
|
||||
Supported Platforms:
|
||||
``CPU``
|
||||
"""
|
||||
@prim_attr_register
|
||||
def __init__(self, n_qubits, param_names, gate_names, gate_matrix,
|
||||
gate_obj_qubits, gate_ctrl_qubits, gate_params_names,
|
||||
gate_coeff, gate_requires_grad, hams_pauli_coeff,
|
||||
hams_pauli_word, hams_pauli_qubit):
|
||||
"""Initialize Evolution"""
|
||||
self.init_prim_io_names(inputs=['param_data'], outputs=['state'])
|
||||
self.n_qubits = n_qubits
|
||||
|
||||
def check_shape_size(self, param_data):
|
||||
if len(param_data) != 1:
|
||||
raise ValueError(f"For '{self.name}', the dimension of 'param_data' should be 1, "
|
||||
f"but got {len(param_data)}.")
|
||||
|
||||
def infer_shape(self, param_data):
|
||||
self.check_shape_size(param_data)
|
||||
return [1 << self.n_qubits, 2]
|
||||
|
||||
def infer_dtype(self, param_data):
|
||||
args = {'param_data': param_data}
|
||||
validator.check_tensors_dtypes_same_and_valid(args, mstype.float_type,
|
||||
self.name)
|
||||
return param_data
|
|
@ -2980,87 +2980,8 @@ test_case_quant_ops = [
|
|||
'skip': ['backward']}),
|
||||
]
|
||||
|
||||
test_case_quantum_ops = [
|
||||
('PQC', {
|
||||
'block': P.PQC(n_qubits=3,
|
||||
encoder_params_names=['e0', 'e1', 'e2'],
|
||||
ansatz_params_names=['a', 'b', 'c'],
|
||||
gate_names=['RX', 'RX', 'RX', 'npg', 'npg',
|
||||
'npg', 'RX', 'npg', 'npg', 'RZ',
|
||||
'npg', 'npg', 'RY'],
|
||||
gate_matrix=[[[['0.0', '0.0'], ['0.0', '0.0']],
|
||||
[['0.0', '0.0'], ['0.0', '0.0']]],
|
||||
[[['0.0', '0.0'], ['0.0', '0.0']],
|
||||
[['0.0', '0.0'], ['0.0', '0.0']]],
|
||||
[[['0.0', '0.0'], ['0.0', '0.0']],
|
||||
[['0.0', '0.0'], ['0.0', '0.0']]],
|
||||
[[['0.7071067811865475', '0.7071067811865475'],
|
||||
['0.7071067811865475', '-0.7071067811865475']],
|
||||
[['0.0', '0.0'], ['0.0', '0.0']]],
|
||||
[[['0.7071067811865475', '0.7071067811865475'],
|
||||
['0.7071067811865475', '-0.7071067811865475']],
|
||||
[['0.0', '0.0'], ['0.0', '0.0']]],
|
||||
[[['0.7071067811865475', '0.7071067811865475'],
|
||||
['0.7071067811865475', '-0.7071067811865475']],
|
||||
[['0.0', '0.0'], ['0.0', '0.0']]],
|
||||
[[['0.0', '0.0'], ['0.0', '0.0']],
|
||||
[['0.0', '0.0'], ['0.0', '0.0']]],
|
||||
[[['0.0', '1.0'], ['1.0', '0.0']],
|
||||
[['0.0', '0.0'], ['0.0', '0.0']]],
|
||||
[[['0.0', '-0.0'], ['0.0', '0.0']],
|
||||
[['0.0', '-1.0'], ['1.0', '0.0']]],
|
||||
[[['0.0', '0.0'], ['0.0', '0.0']],
|
||||
[['0.0', '0.0'], ['0.0', '0.0']]],
|
||||
[[['0.0', '1.0'], ['1.0', '0.0']],
|
||||
[['0.0', '0.0'], ['0.0', '0.0']]],
|
||||
[[['1.0', '0.0'], ['0.0', '-1.0']],
|
||||
[['0.0', '0.0'], ['0.0', '0.0']]],
|
||||
[[['0.0', '0.0'], ['0.0', '0.0']],
|
||||
[['0.0', '0.0'], ['0.0', '0.0']]]],
|
||||
gate_obj_qubits=[[0], [1], [2], [0], [1], [2],
|
||||
[0], [1], [2], [1], [1], [0], [2]],
|
||||
gate_ctrl_qubits=[[], [], [], [], [], [], [], [], [], [], [2], [], []],
|
||||
gate_params_names=[['e0'], ['e1'], ['e2'], [], [], [], ['a'], [], [],
|
||||
['b'], [], [], ['c']],
|
||||
gate_coeff=[[1.0], [1.0], [1.0], [], [], [], [1.0], [], [], [1.0], [],
|
||||
[], [1.0]],
|
||||
gate_requires_grad=[[True], [True], [True], [], [], [], [True], [], [],
|
||||
[True], [], [], [True]],
|
||||
hams_pauli_coeff=[[1.0]],
|
||||
hams_pauli_word=[[['X', 'Y', 'Z']]],
|
||||
hams_pauli_qubit=[[[0, 1, 2]]],
|
||||
n_threads=1),
|
||||
'desc_inputs': [Tensor(np.array([[1.0, 2.0, 3.0]]).astype(np.float32)),
|
||||
Tensor(np.array([2.0, 3.0, 4.0]).astype(np.float32))],
|
||||
'skip': ['backward']}),
|
||||
('Evolution', {
|
||||
'block': P.Evolution(n_qubits=3,
|
||||
param_names=['a'],
|
||||
gate_names=['npg', 'npg', 'npg', 'RY'],
|
||||
gate_matrix=[[[['0.7071067811865475', '0.7071067811865475'],
|
||||
['0.7071067811865475', '-0.7071067811865475']],
|
||||
[['0.0', '0.0'], ['0.0', '0.0']]],
|
||||
[[['0.7071067811865475', '0.7071067811865475'],
|
||||
['0.7071067811865475', '-0.7071067811865475']],
|
||||
[['0.0', '0.0'], ['0.0', '0.0']]],
|
||||
[[['0.0', '1.0'], ['1.0', '0.0']],
|
||||
[['0.0', '0.0'], ['0.0', '0.0']]],
|
||||
[[['0.0', '0.0'], ['0.0', '0.0']],
|
||||
[['0.0', '0.0'], ['0.0', '0.0']]]],
|
||||
gate_obj_qubits=[[0], [1], [0], [0]],
|
||||
gate_ctrl_qubits=[[], [], [1], []],
|
||||
gate_params_names=[[], [], [], ['a']],
|
||||
gate_coeff=[[], [], [], [1.0]],
|
||||
gate_requires_grad=[[], [], [], [True]],
|
||||
hams_pauli_coeff=[[1.0]],
|
||||
hams_pauli_word=[[['Z']]],
|
||||
hams_pauli_qubit=[[[0]]]),
|
||||
'desc_inputs': [Tensor(np.array([0.5]).astype(np.float32))],
|
||||
'skip': ['backward']}),
|
||||
]
|
||||
|
||||
test_case_lists = [test_case_nn_ops, test_case_math_ops, test_case_array_ops,
|
||||
test_case_other_ops, test_case_quant_ops, test_case_quantum_ops]
|
||||
test_case_other_ops, test_case_quant_ops]
|
||||
test_case = functools.reduce(lambda x, y: x + y, test_case_lists)
|
||||
# use -k to select certain testcast
|
||||
# pytest tests/python/ops/test_ops.py::test_backward -k LayerNorm
|
||||
|
|
|
@ -1,969 +0,0 @@
|
|||
diff --color -aur ProjectQ-0.5.1/projectq/backends/_sim/_cppkernels/intrin/kernel1.hpp ProjectQ-0.5.1_new/projectq/backends/_sim/_cppkernels/intrin/kernel1.hpp
|
||||
--- ProjectQ-0.5.1/projectq/backends/_sim/_cppkernels/intrin/kernel1.hpp 2020-06-05 21:07:57.000000000 +0800
|
||||
+++ ProjectQ-0.5.1_new/projectq/backends/_sim/_cppkernels/intrin/kernel1.hpp 2021-04-19 18:04:05.541802882 +0800
|
||||
@@ -17,18 +17,18 @@
|
||||
{
|
||||
__m256d v[2];
|
||||
|
||||
- v[0] = load2(&psi[I]);
|
||||
- v[1] = load2(&psi[I + d0]);
|
||||
+ v[0] = load2(psi + 2 * I);
|
||||
+ v[1] = load2(psi + 2 * (I + d0));
|
||||
|
||||
- _mm256_storeu2_m128d((double*)&psi[I + d0], (double*)&psi[I], add(mul(v[0], m[0], mt[0]), mul(v[1], m[1], mt[1])));
|
||||
+ _mm256_storeu2_m128d(psi + 2 * (I + d0), psi + 2 * I, add(mul(v[0], m[0], mt[0]), mul(v[1], m[1], mt[1])));
|
||||
|
||||
}
|
||||
|
||||
// bit indices id[.] are given from high to low (e.g. control first for CNOT)
|
||||
template <class V, class M>
|
||||
-void kernel(V &psi, unsigned id0, M const& m, std::size_t ctrlmask)
|
||||
+void kernel(V &psi, unsigned id0, M const& m, std::size_t ctrlmask, unsigned len)
|
||||
{
|
||||
- std::size_t n = psi.size();
|
||||
+ std::size_t n = len;
|
||||
std::size_t d0 = 1UL << id0;
|
||||
|
||||
__m256d mm[] = {load(&m[0][0], &m[1][0]), load(&m[0][1], &m[1][1])};
|
||||
diff --color -aur ProjectQ-0.5.1/projectq/backends/_sim/_cppkernels/intrin/kernel2.hpp ProjectQ-0.5.1_new/projectq/backends/_sim/_cppkernels/intrin/kernel2.hpp
|
||||
--- ProjectQ-0.5.1/projectq/backends/_sim/_cppkernels/intrin/kernel2.hpp 2020-06-05 21:07:57.000000000 +0800
|
||||
+++ ProjectQ-0.5.1_new/projectq/backends/_sim/_cppkernels/intrin/kernel2.hpp 2021-04-19 18:04:05.541802882 +0800
|
||||
@@ -17,21 +17,21 @@
|
||||
{
|
||||
__m256d v[4];
|
||||
|
||||
- v[0] = load2(&psi[I]);
|
||||
- v[1] = load2(&psi[I + d0]);
|
||||
- v[2] = load2(&psi[I + d1]);
|
||||
- v[3] = load2(&psi[I + d0 + d1]);
|
||||
+ v[0] = load2(psi + 2 * I);
|
||||
+ v[1] = load2(psi + 2 * (I + d0));
|
||||
+ v[2] = load2(psi + 2 * (I + d1));
|
||||
+ v[3] = load2(psi + 2 * (I + d0 + d1));
|
||||
|
||||
- _mm256_storeu2_m128d((double*)&psi[I + d0], (double*)&psi[I], add(mul(v[0], m[0], mt[0]), add(mul(v[1], m[1], mt[1]), add(mul(v[2], m[2], mt[2]), mul(v[3], m[3], mt[3])))));
|
||||
- _mm256_storeu2_m128d((double*)&psi[I + d0 + d1], (double*)&psi[I + d1], add(mul(v[0], m[4], mt[4]), add(mul(v[1], m[5], mt[5]), add(mul(v[2], m[6], mt[6]), mul(v[3], m[7], mt[7])))));
|
||||
+ _mm256_storeu2_m128d(psi + 2 * (I + d0), psi + 2 * I, add(mul(v[0], m[0], mt[0]), add(mul(v[1], m[1], mt[1]), add(mul(v[2], m[2], mt[2]), mul(v[3], m[3], mt[3])))));
|
||||
+ _mm256_storeu2_m128d(psi + 2 * (I + d0 + d1), psi + 2 * (I + d1), add(mul(v[0], m[4], mt[4]), add(mul(v[1], m[5], mt[5]), add(mul(v[2], m[6], mt[6]), mul(v[3], m[7], mt[7])))));
|
||||
|
||||
}
|
||||
|
||||
// bit indices id[.] are given from high to low (e.g. control first for CNOT)
|
||||
template <class V, class M>
|
||||
-void kernel(V &psi, unsigned id1, unsigned id0, M const& m, std::size_t ctrlmask)
|
||||
+void kernel(V &psi, unsigned id1, unsigned id0, M const& m, std::size_t ctrlmask, unsigned len)
|
||||
{
|
||||
- std::size_t n = psi.size();
|
||||
+ std::size_t n = len;
|
||||
std::size_t d0 = 1UL << id0;
|
||||
std::size_t d1 = 1UL << id1;
|
||||
|
||||
diff --color -aur ProjectQ-0.5.1/projectq/backends/_sim/_cppkernels/intrin/kernel3.hpp ProjectQ-0.5.1_new/projectq/backends/_sim/_cppkernels/intrin/kernel3.hpp
|
||||
--- ProjectQ-0.5.1/projectq/backends/_sim/_cppkernels/intrin/kernel3.hpp 2020-06-05 21:07:57.000000000 +0800
|
||||
+++ ProjectQ-0.5.1_new/projectq/backends/_sim/_cppkernels/intrin/kernel3.hpp 2021-04-19 18:04:05.541802882 +0800
|
||||
@@ -17,10 +17,10 @@
|
||||
{
|
||||
__m256d v[4];
|
||||
|
||||
- v[0] = load2(&psi[I]);
|
||||
- v[1] = load2(&psi[I + d0]);
|
||||
- v[2] = load2(&psi[I + d1]);
|
||||
- v[3] = load2(&psi[I + d0 + d1]);
|
||||
+ v[0] = load2(psi + 2 * I);
|
||||
+ v[1] = load2(psi + 2 * (I + d0));
|
||||
+ v[2] = load2(psi + 2 * (I + d1));
|
||||
+ v[3] = load2(psi + 2 * (I + d0 + d1));
|
||||
|
||||
__m256d tmp[4];
|
||||
|
||||
@@ -29,23 +29,23 @@
|
||||
tmp[2] = add(mul(v[0], m[8], mt[8]), add(mul(v[1], m[9], mt[9]), add(mul(v[2], m[10], mt[10]), mul(v[3], m[11], mt[11]))));
|
||||
tmp[3] = add(mul(v[0], m[12], mt[12]), add(mul(v[1], m[13], mt[13]), add(mul(v[2], m[14], mt[14]), mul(v[3], m[15], mt[15]))));
|
||||
|
||||
- v[0] = load2(&psi[I + d2]);
|
||||
- v[1] = load2(&psi[I + d0 + d2]);
|
||||
- v[2] = load2(&psi[I + d1 + d2]);
|
||||
- v[3] = load2(&psi[I + d0 + d1 + d2]);
|
||||
-
|
||||
- _mm256_storeu2_m128d((double*)&psi[I + d0], (double*)&psi[I], add(tmp[0], add(mul(v[0], m[16], mt[16]), add(mul(v[1], m[17], mt[17]), add(mul(v[2], m[18], mt[18]), mul(v[3], m[19], mt[19]))))));
|
||||
- _mm256_storeu2_m128d((double*)&psi[I + d0 + d1], (double*)&psi[I + d1], add(tmp[1], add(mul(v[0], m[20], mt[20]), add(mul(v[1], m[21], mt[21]), add(mul(v[2], m[22], mt[22]), mul(v[3], m[23], mt[23]))))));
|
||||
- _mm256_storeu2_m128d((double*)&psi[I + d0 + d2], (double*)&psi[I + d2], add(tmp[2], add(mul(v[0], m[24], mt[24]), add(mul(v[1], m[25], mt[25]), add(mul(v[2], m[26], mt[26]), mul(v[3], m[27], mt[27]))))));
|
||||
- _mm256_storeu2_m128d((double*)&psi[I + d0 + d1 + d2], (double*)&psi[I + d1 + d2], add(tmp[3], add(mul(v[0], m[28], mt[28]), add(mul(v[1], m[29], mt[29]), add(mul(v[2], m[30], mt[30]), mul(v[3], m[31], mt[31]))))));
|
||||
+ v[0] = load2(psi + 2 * (I + d2));
|
||||
+ v[1] = load2(psi + 2 * (I + d0 + d2));
|
||||
+ v[2] = load2(psi + 2 * (I + d1 + d2));
|
||||
+ v[3] = load2(psi + 2 * (I + d0 + d1 + d2));
|
||||
+
|
||||
+ _mm256_storeu2_m128d(psi + 2 * (I + d0), psi + 2 * I, add(tmp[0], add(mul(v[0], m[16], mt[16]), add(mul(v[1], m[17], mt[17]), add(mul(v[2], m[18], mt[18]), mul(v[3], m[19], mt[19]))))));
|
||||
+ _mm256_storeu2_m128d(psi + 2 * (I + d0 + d1), psi + 2 * (I + d1), add(tmp[1], add(mul(v[0], m[20], mt[20]), add(mul(v[1], m[21], mt[21]), add(mul(v[2], m[22], mt[22]), mul(v[3], m[23], mt[23]))))));
|
||||
+ _mm256_storeu2_m128d(psi + 2 * (I + d0 + d2), psi + 2 * (I + d2), add(tmp[2], add(mul(v[0], m[24], mt[24]), add(mul(v[1], m[25], mt[25]), add(mul(v[2], m[26], mt[26]), mul(v[3], m[27], mt[27]))))));
|
||||
+ _mm256_storeu2_m128d(psi + 2 * (I + d0 + d1 + d2), psi + 2 * (I + d1 + d2), add(tmp[3], add(mul(v[0], m[28], mt[28]), add(mul(v[1], m[29], mt[29]), add(mul(v[2], m[30], mt[30]), mul(v[3], m[31], mt[31]))))));
|
||||
|
||||
}
|
||||
|
||||
// bit indices id[.] are given from high to low (e.g. control first for CNOT)
|
||||
template <class V, class M>
|
||||
-void kernel(V &psi, unsigned id2, unsigned id1, unsigned id0, M const& m, std::size_t ctrlmask)
|
||||
+void kernel(V &psi, unsigned id2, unsigned id1, unsigned id0, M const& m, std::size_t ctrlmask, unsigned len)
|
||||
{
|
||||
- std::size_t n = psi.size();
|
||||
+ std::size_t n = len;
|
||||
std::size_t d0 = 1UL << id0;
|
||||
std::size_t d1 = 1UL << id1;
|
||||
std::size_t d2 = 1UL << id2;
|
||||
diff --color -aur ProjectQ-0.5.1/projectq/backends/_sim/_cppkernels/intrin/kernel4.hpp ProjectQ-0.5.1_new/projectq/backends/_sim/_cppkernels/intrin/kernel4.hpp
|
||||
--- ProjectQ-0.5.1/projectq/backends/_sim/_cppkernels/intrin/kernel4.hpp 2020-06-05 21:07:57.000000000 +0800
|
||||
+++ ProjectQ-0.5.1_new/projectq/backends/_sim/_cppkernels/intrin/kernel4.hpp 2021-04-19 18:04:05.541802882 +0800
|
||||
@@ -17,10 +17,10 @@
|
||||
{
|
||||
__m256d v[4];
|
||||
|
||||
- v[0] = load2(&psi[I]);
|
||||
- v[1] = load2(&psi[I + d0]);
|
||||
- v[2] = load2(&psi[I + d1]);
|
||||
- v[3] = load2(&psi[I + d0 + d1]);
|
||||
+ v[0] = load2(psi + 2 * I);
|
||||
+ v[1] = load2(psi + 2 * (I + d0));
|
||||
+ v[2] = load2(psi + 2 * (I + d1));
|
||||
+ v[3] = load2(psi + 2 * (I + d0 + d1));
|
||||
|
||||
__m256d tmp[8];
|
||||
|
||||
@@ -33,10 +33,10 @@
|
||||
tmp[6] = add(mul(v[0], m[24], mt[24]), add(mul(v[1], m[25], mt[25]), add(mul(v[2], m[26], mt[26]), mul(v[3], m[27], mt[27]))));
|
||||
tmp[7] = add(mul(v[0], m[28], mt[28]), add(mul(v[1], m[29], mt[29]), add(mul(v[2], m[30], mt[30]), mul(v[3], m[31], mt[31]))));
|
||||
|
||||
- v[0] = load2(&psi[I + d2]);
|
||||
- v[1] = load2(&psi[I + d0 + d2]);
|
||||
- v[2] = load2(&psi[I + d1 + d2]);
|
||||
- v[3] = load2(&psi[I + d0 + d1 + d2]);
|
||||
+ v[0] = load2(psi + 2 * (I + d2));
|
||||
+ v[1] = load2(psi + 2 * (I + d0 + d2));
|
||||
+ v[2] = load2(psi + 2 * (I + d1 + d2));
|
||||
+ v[3] = load2(psi + 2 * (I + d0 + d1 + d2));
|
||||
|
||||
tmp[0] = add(tmp[0], add(mul(v[0], m[32], mt[32]), add(mul(v[1], m[33], mt[33]), add(mul(v[2], m[34], mt[34]), mul(v[3], m[35], mt[35])))));
|
||||
tmp[1] = add(tmp[1], add(mul(v[0], m[36], mt[36]), add(mul(v[1], m[37], mt[37]), add(mul(v[2], m[38], mt[38]), mul(v[3], m[39], mt[39])))));
|
||||
@@ -47,10 +47,10 @@
|
||||
tmp[6] = add(tmp[6], add(mul(v[0], m[56], mt[56]), add(mul(v[1], m[57], mt[57]), add(mul(v[2], m[58], mt[58]), mul(v[3], m[59], mt[59])))));
|
||||
tmp[7] = add(tmp[7], add(mul(v[0], m[60], mt[60]), add(mul(v[1], m[61], mt[61]), add(mul(v[2], m[62], mt[62]), mul(v[3], m[63], mt[63])))));
|
||||
|
||||
- v[0] = load2(&psi[I + d3]);
|
||||
- v[1] = load2(&psi[I + d0 + d3]);
|
||||
- v[2] = load2(&psi[I + d1 + d3]);
|
||||
- v[3] = load2(&psi[I + d0 + d1 + d3]);
|
||||
+ v[0] = load2(psi + 2 * (I + d3));
|
||||
+ v[1] = load2(psi + 2 * (I + d0 + d3));
|
||||
+ v[2] = load2(psi + 2 * (I + d1 + d3));
|
||||
+ v[3] = load2(psi + 2 * (I + d0 + d1 + d3));
|
||||
|
||||
tmp[0] = add(tmp[0], add(mul(v[0], m[64], mt[64]), add(mul(v[1], m[65], mt[65]), add(mul(v[2], m[66], mt[66]), mul(v[3], m[67], mt[67])))));
|
||||
tmp[1] = add(tmp[1], add(mul(v[0], m[68], mt[68]), add(mul(v[1], m[69], mt[69]), add(mul(v[2], m[70], mt[70]), mul(v[3], m[71], mt[71])))));
|
||||
@@ -61,27 +61,27 @@
|
||||
tmp[6] = add(tmp[6], add(mul(v[0], m[88], mt[88]), add(mul(v[1], m[89], mt[89]), add(mul(v[2], m[90], mt[90]), mul(v[3], m[91], mt[91])))));
|
||||
tmp[7] = add(tmp[7], add(mul(v[0], m[92], mt[92]), add(mul(v[1], m[93], mt[93]), add(mul(v[2], m[94], mt[94]), mul(v[3], m[95], mt[95])))));
|
||||
|
||||
- v[0] = load2(&psi[I + d2 + d3]);
|
||||
- v[1] = load2(&psi[I + d0 + d2 + d3]);
|
||||
- v[2] = load2(&psi[I + d1 + d2 + d3]);
|
||||
- v[3] = load2(&psi[I + d0 + d1 + d2 + d3]);
|
||||
-
|
||||
- _mm256_storeu2_m128d((double*)&psi[I + d0], (double*)&psi[I], add(tmp[0], add(mul(v[0], m[96], mt[96]), add(mul(v[1], m[97], mt[97]), add(mul(v[2], m[98], mt[98]), mul(v[3], m[99], mt[99]))))));
|
||||
- _mm256_storeu2_m128d((double*)&psi[I + d0 + d1], (double*)&psi[I + d1], add(tmp[1], add(mul(v[0], m[100], mt[100]), add(mul(v[1], m[101], mt[101]), add(mul(v[2], m[102], mt[102]), mul(v[3], m[103], mt[103]))))));
|
||||
- _mm256_storeu2_m128d((double*)&psi[I + d0 + d2], (double*)&psi[I + d2], add(tmp[2], add(mul(v[0], m[104], mt[104]), add(mul(v[1], m[105], mt[105]), add(mul(v[2], m[106], mt[106]), mul(v[3], m[107], mt[107]))))));
|
||||
- _mm256_storeu2_m128d((double*)&psi[I + d0 + d1 + d2], (double*)&psi[I + d1 + d2], add(tmp[3], add(mul(v[0], m[108], mt[108]), add(mul(v[1], m[109], mt[109]), add(mul(v[2], m[110], mt[110]), mul(v[3], m[111], mt[111]))))));
|
||||
- _mm256_storeu2_m128d((double*)&psi[I + d0 + d3], (double*)&psi[I + d3], add(tmp[4], add(mul(v[0], m[112], mt[112]), add(mul(v[1], m[113], mt[113]), add(mul(v[2], m[114], mt[114]), mul(v[3], m[115], mt[115]))))));
|
||||
- _mm256_storeu2_m128d((double*)&psi[I + d0 + d1 + d3], (double*)&psi[I + d1 + d3], add(tmp[5], add(mul(v[0], m[116], mt[116]), add(mul(v[1], m[117], mt[117]), add(mul(v[2], m[118], mt[118]), mul(v[3], m[119], mt[119]))))));
|
||||
- _mm256_storeu2_m128d((double*)&psi[I + d0 + d2 + d3], (double*)&psi[I + d2 + d3], add(tmp[6], add(mul(v[0], m[120], mt[120]), add(mul(v[1], m[121], mt[121]), add(mul(v[2], m[122], mt[122]), mul(v[3], m[123], mt[123]))))));
|
||||
- _mm256_storeu2_m128d((double*)&psi[I + d0 + d1 + d2 + d3], (double*)&psi[I + d1 + d2 + d3], add(tmp[7], add(mul(v[0], m[124], mt[124]), add(mul(v[1], m[125], mt[125]), add(mul(v[2], m[126], mt[126]), mul(v[3], m[127], mt[127]))))));
|
||||
+ v[0] = load2(psi + 2 * (I + d2 + d3));
|
||||
+ v[1] = load2(psi + 2 * (I + d0 + d2 + d3));
|
||||
+ v[2] = load2(psi + 2 * (I + d1 + d2 + d3));
|
||||
+ v[3] = load2(psi + 2 * (I + d0 + d1 + d2 + d3));
|
||||
+
|
||||
+ _mm256_storeu2_m128d(psi + 2 * (I + d0), psi + 2 * I, add(tmp[0], add(mul(v[0], m[96], mt[96]), add(mul(v[1], m[97], mt[97]), add(mul(v[2], m[98], mt[98]), mul(v[3], m[99], mt[99]))))));
|
||||
+ _mm256_storeu2_m128d(psi + 2 * (I + d0 + d1), psi + 2 * (I + d1), add(tmp[1], add(mul(v[0], m[100], mt[100]), add(mul(v[1], m[101], mt[101]), add(mul(v[2], m[102], mt[102]), mul(v[3], m[103], mt[103]))))));
|
||||
+ _mm256_storeu2_m128d(psi + 2 * (I + d0 + d2), psi + 2 * (I + d2), add(tmp[2], add(mul(v[0], m[104], mt[104]), add(mul(v[1], m[105], mt[105]), add(mul(v[2], m[106], mt[106]), mul(v[3], m[107], mt[107]))))));
|
||||
+ _mm256_storeu2_m128d(psi + 2 * (I + d0 + d1 + d2), psi + 2 * (I + d1 + d2), add(tmp[3], add(mul(v[0], m[108], mt[108]), add(mul(v[1], m[109], mt[109]), add(mul(v[2], m[110], mt[110]), mul(v[3], m[111], mt[111]))))));
|
||||
+ _mm256_storeu2_m128d(psi + 2 * (I + d0 + d3), psi + 2 * (I + d3), add(tmp[4], add(mul(v[0], m[112], mt[112]), add(mul(v[1], m[113], mt[113]), add(mul(v[2], m[114], mt[114]), mul(v[3], m[115], mt[115]))))));
|
||||
+ _mm256_storeu2_m128d(psi + 2 * (I + d0 + d1 + d3), psi + 2 * (I + d1 + d3), add(tmp[5], add(mul(v[0], m[116], mt[116]), add(mul(v[1], m[117], mt[117]), add(mul(v[2], m[118], mt[118]), mul(v[3], m[119], mt[119]))))));
|
||||
+ _mm256_storeu2_m128d(psi + 2 * (I + d0 + d2 + d3), psi + 2 * (I + d2 + d3), add(tmp[6], add(mul(v[0], m[120], mt[120]), add(mul(v[1], m[121], mt[121]), add(mul(v[2], m[122], mt[122]), mul(v[3], m[123], mt[123]))))));
|
||||
+ _mm256_storeu2_m128d(psi + 2 * (I + d0 + d1 + d2 + d3), psi + 2 * (I + d1 + d2 + d3), add(tmp[7], add(mul(v[0], m[124], mt[124]), add(mul(v[1], m[125], mt[125]), add(mul(v[2], m[126], mt[126]), mul(v[3], m[127], mt[127]))))));
|
||||
|
||||
}
|
||||
|
||||
// bit indices id[.] are given from high to low (e.g. control first for CNOT)
|
||||
template <class V, class M>
|
||||
-void kernel(V &psi, unsigned id3, unsigned id2, unsigned id1, unsigned id0, M const& m, std::size_t ctrlmask)
|
||||
+void kernel(V &psi, unsigned id3, unsigned id2, unsigned id1, unsigned id0, M const& m, std::size_t ctrlmask, unsigned len)
|
||||
{
|
||||
- std::size_t n = psi.size();
|
||||
+ std::size_t n = len;
|
||||
std::size_t d0 = 1UL << id0;
|
||||
std::size_t d1 = 1UL << id1;
|
||||
std::size_t d2 = 1UL << id2;
|
||||
diff --color -aur ProjectQ-0.5.1/projectq/backends/_sim/_cppkernels/intrin/kernel5.hpp ProjectQ-0.5.1_new/projectq/backends/_sim/_cppkernels/intrin/kernel5.hpp
|
||||
--- ProjectQ-0.5.1/projectq/backends/_sim/_cppkernels/intrin/kernel5.hpp 2020-06-05 21:07:57.000000000 +0800
|
||||
+++ ProjectQ-0.5.1_new/projectq/backends/_sim/_cppkernels/intrin/kernel5.hpp 2021-04-19 18:04:05.541802882 +0800
|
||||
@@ -17,10 +17,10 @@
|
||||
{
|
||||
__m256d v[4];
|
||||
|
||||
- v[0] = load2(&psi[I]);
|
||||
- v[1] = load2(&psi[I + d0]);
|
||||
- v[2] = load2(&psi[I + d1]);
|
||||
- v[3] = load2(&psi[I + d0 + d1]);
|
||||
+ v[0] = load2(psi + 2 * I);
|
||||
+ v[1] = load2(psi + 2 * (I + d0));
|
||||
+ v[2] = load2(psi + 2 * (I + d1));
|
||||
+ v[3] = load2(psi + 2 * (I + d0 + d1));
|
||||
|
||||
__m256d tmp[16];
|
||||
|
||||
@@ -41,10 +41,10 @@
|
||||
tmp[14] = add(mul(v[0], m[56], mt[56]), add(mul(v[1], m[57], mt[57]), add(mul(v[2], m[58], mt[58]), mul(v[3], m[59], mt[59]))));
|
||||
tmp[15] = add(mul(v[0], m[60], mt[60]), add(mul(v[1], m[61], mt[61]), add(mul(v[2], m[62], mt[62]), mul(v[3], m[63], mt[63]))));
|
||||
|
||||
- v[0] = load2(&psi[I + d2]);
|
||||
- v[1] = load2(&psi[I + d0 + d2]);
|
||||
- v[2] = load2(&psi[I + d1 + d2]);
|
||||
- v[3] = load2(&psi[I + d0 + d1 + d2]);
|
||||
+ v[0] = load2(psi + 2 * (I + d2));
|
||||
+ v[1] = load2(psi + 2 * (I + d0 + d2));
|
||||
+ v[2] = load2(psi + 2 * (I + d1 + d2));
|
||||
+ v[3] = load2(psi + 2 * (I + d0 + d1 + d2));
|
||||
|
||||
tmp[0] = add(tmp[0], add(mul(v[0], m[64], mt[64]), add(mul(v[1], m[65], mt[65]), add(mul(v[2], m[66], mt[66]), mul(v[3], m[67], mt[67])))));
|
||||
tmp[1] = add(tmp[1], add(mul(v[0], m[68], mt[68]), add(mul(v[1], m[69], mt[69]), add(mul(v[2], m[70], mt[70]), mul(v[3], m[71], mt[71])))));
|
||||
@@ -63,10 +63,10 @@
|
||||
tmp[14] = add(tmp[14], add(mul(v[0], m[120], mt[120]), add(mul(v[1], m[121], mt[121]), add(mul(v[2], m[122], mt[122]), mul(v[3], m[123], mt[123])))));
|
||||
tmp[15] = add(tmp[15], add(mul(v[0], m[124], mt[124]), add(mul(v[1], m[125], mt[125]), add(mul(v[2], m[126], mt[126]), mul(v[3], m[127], mt[127])))));
|
||||
|
||||
- v[0] = load2(&psi[I + d3]);
|
||||
- v[1] = load2(&psi[I + d0 + d3]);
|
||||
- v[2] = load2(&psi[I + d1 + d3]);
|
||||
- v[3] = load2(&psi[I + d0 + d1 + d3]);
|
||||
+ v[0] = load2(psi + 2 * (I + d3));
|
||||
+ v[1] = load2(psi + 2 * (I + d0 + d3));
|
||||
+ v[2] = load2(psi + 2 * (I + d1 + d3));
|
||||
+ v[3] = load2(psi + 2 * (I + d0 + d1 + d3));
|
||||
|
||||
tmp[0] = add(tmp[0], add(mul(v[0], m[128], mt[128]), add(mul(v[1], m[129], mt[129]), add(mul(v[2], m[130], mt[130]), mul(v[3], m[131], mt[131])))));
|
||||
tmp[1] = add(tmp[1], add(mul(v[0], m[132], mt[132]), add(mul(v[1], m[133], mt[133]), add(mul(v[2], m[134], mt[134]), mul(v[3], m[135], mt[135])))));
|
||||
@@ -85,10 +85,10 @@
|
||||
tmp[14] = add(tmp[14], add(mul(v[0], m[184], mt[184]), add(mul(v[1], m[185], mt[185]), add(mul(v[2], m[186], mt[186]), mul(v[3], m[187], mt[187])))));
|
||||
tmp[15] = add(tmp[15], add(mul(v[0], m[188], mt[188]), add(mul(v[1], m[189], mt[189]), add(mul(v[2], m[190], mt[190]), mul(v[3], m[191], mt[191])))));
|
||||
|
||||
- v[0] = load2(&psi[I + d2 + d3]);
|
||||
- v[1] = load2(&psi[I + d0 + d2 + d3]);
|
||||
- v[2] = load2(&psi[I + d1 + d2 + d3]);
|
||||
- v[3] = load2(&psi[I + d0 + d1 + d2 + d3]);
|
||||
+ v[0] = load2(psi + 2 * (I + d2 + d3));
|
||||
+ v[1] = load2(psi + 2 * (I + d0 + d2 + d3));
|
||||
+ v[2] = load2(psi + 2 * (I + d1 + d2 + d3));
|
||||
+ v[3] = load2(psi + 2 * (I + d0 + d1 + d2 + d3));
|
||||
|
||||
tmp[0] = add(tmp[0], add(mul(v[0], m[192], mt[192]), add(mul(v[1], m[193], mt[193]), add(mul(v[2], m[194], mt[194]), mul(v[3], m[195], mt[195])))));
|
||||
tmp[1] = add(tmp[1], add(mul(v[0], m[196], mt[196]), add(mul(v[1], m[197], mt[197]), add(mul(v[2], m[198], mt[198]), mul(v[3], m[199], mt[199])))));
|
||||
@@ -107,10 +107,10 @@
|
||||
tmp[14] = add(tmp[14], add(mul(v[0], m[248], mt[248]), add(mul(v[1], m[249], mt[249]), add(mul(v[2], m[250], mt[250]), mul(v[3], m[251], mt[251])))));
|
||||
tmp[15] = add(tmp[15], add(mul(v[0], m[252], mt[252]), add(mul(v[1], m[253], mt[253]), add(mul(v[2], m[254], mt[254]), mul(v[3], m[255], mt[255])))));
|
||||
|
||||
- v[0] = load2(&psi[I + d4]);
|
||||
- v[1] = load2(&psi[I + d0 + d4]);
|
||||
- v[2] = load2(&psi[I + d1 + d4]);
|
||||
- v[3] = load2(&psi[I + d0 + d1 + d4]);
|
||||
+ v[0] = load2(psi + 2 * (I + d4));
|
||||
+ v[1] = load2(psi + 2 * (I + d0 + d4));
|
||||
+ v[2] = load2(psi + 2 * (I + d1 + d4));
|
||||
+ v[3] = load2(psi + 2 * (I + d0 + d1 + d4));
|
||||
|
||||
tmp[0] = add(tmp[0], add(mul(v[0], m[256], mt[256]), add(mul(v[1], m[257], mt[257]), add(mul(v[2], m[258], mt[258]), mul(v[3], m[259], mt[259])))));
|
||||
tmp[1] = add(tmp[1], add(mul(v[0], m[260], mt[260]), add(mul(v[1], m[261], mt[261]), add(mul(v[2], m[262], mt[262]), mul(v[3], m[263], mt[263])))));
|
||||
@@ -129,10 +129,10 @@
|
||||
tmp[14] = add(tmp[14], add(mul(v[0], m[312], mt[312]), add(mul(v[1], m[313], mt[313]), add(mul(v[2], m[314], mt[314]), mul(v[3], m[315], mt[315])))));
|
||||
tmp[15] = add(tmp[15], add(mul(v[0], m[316], mt[316]), add(mul(v[1], m[317], mt[317]), add(mul(v[2], m[318], mt[318]), mul(v[3], m[319], mt[319])))));
|
||||
|
||||
- v[0] = load2(&psi[I + d2 + d4]);
|
||||
- v[1] = load2(&psi[I + d0 + d2 + d4]);
|
||||
- v[2] = load2(&psi[I + d1 + d2 + d4]);
|
||||
- v[3] = load2(&psi[I + d0 + d1 + d2 + d4]);
|
||||
+ v[0] = load2(psi + 2 * (I + d2 + d4));
|
||||
+ v[1] = load2(psi + 2 * (I + d0 + d2 + d4));
|
||||
+ v[2] = load2(psi + 2 * (I + d1 + d2 + d4));
|
||||
+ v[3] = load2(psi + 2 * (I + d0 + d1 + d2 + d4));
|
||||
|
||||
tmp[0] = add(tmp[0], add(mul(v[0], m[320], mt[320]), add(mul(v[1], m[321], mt[321]), add(mul(v[2], m[322], mt[322]), mul(v[3], m[323], mt[323])))));
|
||||
tmp[1] = add(tmp[1], add(mul(v[0], m[324], mt[324]), add(mul(v[1], m[325], mt[325]), add(mul(v[2], m[326], mt[326]), mul(v[3], m[327], mt[327])))));
|
||||
@@ -151,10 +151,10 @@
|
||||
tmp[14] = add(tmp[14], add(mul(v[0], m[376], mt[376]), add(mul(v[1], m[377], mt[377]), add(mul(v[2], m[378], mt[378]), mul(v[3], m[379], mt[379])))));
|
||||
tmp[15] = add(tmp[15], add(mul(v[0], m[380], mt[380]), add(mul(v[1], m[381], mt[381]), add(mul(v[2], m[382], mt[382]), mul(v[3], m[383], mt[383])))));
|
||||
|
||||
- v[0] = load2(&psi[I + d3 + d4]);
|
||||
- v[1] = load2(&psi[I + d0 + d3 + d4]);
|
||||
- v[2] = load2(&psi[I + d1 + d3 + d4]);
|
||||
- v[3] = load2(&psi[I + d0 + d1 + d3 + d4]);
|
||||
+ v[0] = load2(psi + 2 * (I + d3 + d4));
|
||||
+ v[1] = load2(psi + 2 * (I + d0 + d3 + d4));
|
||||
+ v[2] = load2(psi + 2 * (I + d1 + d3 + d4));
|
||||
+ v[3] = load2(psi + 2 * (I + d0 + d1 + d3 + d4));
|
||||
|
||||
tmp[0] = add(tmp[0], add(mul(v[0], m[384], mt[384]), add(mul(v[1], m[385], mt[385]), add(mul(v[2], m[386], mt[386]), mul(v[3], m[387], mt[387])))));
|
||||
tmp[1] = add(tmp[1], add(mul(v[0], m[388], mt[388]), add(mul(v[1], m[389], mt[389]), add(mul(v[2], m[390], mt[390]), mul(v[3], m[391], mt[391])))));
|
||||
@@ -173,35 +173,35 @@
|
||||
tmp[14] = add(tmp[14], add(mul(v[0], m[440], mt[440]), add(mul(v[1], m[441], mt[441]), add(mul(v[2], m[442], mt[442]), mul(v[3], m[443], mt[443])))));
|
||||
tmp[15] = add(tmp[15], add(mul(v[0], m[444], mt[444]), add(mul(v[1], m[445], mt[445]), add(mul(v[2], m[446], mt[446]), mul(v[3], m[447], mt[447])))));
|
||||
|
||||
- v[0] = load2(&psi[I + d2 + d3 + d4]);
|
||||
- v[1] = load2(&psi[I + d0 + d2 + d3 + d4]);
|
||||
- v[2] = load2(&psi[I + d1 + d2 + d3 + d4]);
|
||||
- v[3] = load2(&psi[I + d0 + d1 + d2 + d3 + d4]);
|
||||
-
|
||||
- _mm256_storeu2_m128d((double*)&psi[I + d0], (double*)&psi[I], add(tmp[0], add(mul(v[0], m[448], mt[448]), add(mul(v[1], m[449], mt[449]), add(mul(v[2], m[450], mt[450]), mul(v[3], m[451], mt[451]))))));
|
||||
- _mm256_storeu2_m128d((double*)&psi[I + d0 + d1], (double*)&psi[I + d1], add(tmp[1], add(mul(v[0], m[452], mt[452]), add(mul(v[1], m[453], mt[453]), add(mul(v[2], m[454], mt[454]), mul(v[3], m[455], mt[455]))))));
|
||||
- _mm256_storeu2_m128d((double*)&psi[I + d0 + d2], (double*)&psi[I + d2], add(tmp[2], add(mul(v[0], m[456], mt[456]), add(mul(v[1], m[457], mt[457]), add(mul(v[2], m[458], mt[458]), mul(v[3], m[459], mt[459]))))));
|
||||
- _mm256_storeu2_m128d((double*)&psi[I + d0 + d1 + d2], (double*)&psi[I + d1 + d2], add(tmp[3], add(mul(v[0], m[460], mt[460]), add(mul(v[1], m[461], mt[461]), add(mul(v[2], m[462], mt[462]), mul(v[3], m[463], mt[463]))))));
|
||||
- _mm256_storeu2_m128d((double*)&psi[I + d0 + d3], (double*)&psi[I + d3], add(tmp[4], add(mul(v[0], m[464], mt[464]), add(mul(v[1], m[465], mt[465]), add(mul(v[2], m[466], mt[466]), mul(v[3], m[467], mt[467]))))));
|
||||
- _mm256_storeu2_m128d((double*)&psi[I + d0 + d1 + d3], (double*)&psi[I + d1 + d3], add(tmp[5], add(mul(v[0], m[468], mt[468]), add(mul(v[1], m[469], mt[469]), add(mul(v[2], m[470], mt[470]), mul(v[3], m[471], mt[471]))))));
|
||||
- _mm256_storeu2_m128d((double*)&psi[I + d0 + d2 + d3], (double*)&psi[I + d2 + d3], add(tmp[6], add(mul(v[0], m[472], mt[472]), add(mul(v[1], m[473], mt[473]), add(mul(v[2], m[474], mt[474]), mul(v[3], m[475], mt[475]))))));
|
||||
- _mm256_storeu2_m128d((double*)&psi[I + d0 + d1 + d2 + d3], (double*)&psi[I + d1 + d2 + d3], add(tmp[7], add(mul(v[0], m[476], mt[476]), add(mul(v[1], m[477], mt[477]), add(mul(v[2], m[478], mt[478]), mul(v[3], m[479], mt[479]))))));
|
||||
- _mm256_storeu2_m128d((double*)&psi[I + d0 + d4], (double*)&psi[I + d4], add(tmp[8], add(mul(v[0], m[480], mt[480]), add(mul(v[1], m[481], mt[481]), add(mul(v[2], m[482], mt[482]), mul(v[3], m[483], mt[483]))))));
|
||||
- _mm256_storeu2_m128d((double*)&psi[I + d0 + d1 + d4], (double*)&psi[I + d1 + d4], add(tmp[9], add(mul(v[0], m[484], mt[484]), add(mul(v[1], m[485], mt[485]), add(mul(v[2], m[486], mt[486]), mul(v[3], m[487], mt[487]))))));
|
||||
- _mm256_storeu2_m128d((double*)&psi[I + d0 + d2 + d4], (double*)&psi[I + d2 + d4], add(tmp[10], add(mul(v[0], m[488], mt[488]), add(mul(v[1], m[489], mt[489]), add(mul(v[2], m[490], mt[490]), mul(v[3], m[491], mt[491]))))));
|
||||
- _mm256_storeu2_m128d((double*)&psi[I + d0 + d1 + d2 + d4], (double*)&psi[I + d1 + d2 + d4], add(tmp[11], add(mul(v[0], m[492], mt[492]), add(mul(v[1], m[493], mt[493]), add(mul(v[2], m[494], mt[494]), mul(v[3], m[495], mt[495]))))));
|
||||
- _mm256_storeu2_m128d((double*)&psi[I + d0 + d3 + d4], (double*)&psi[I + d3 + d4], add(tmp[12], add(mul(v[0], m[496], mt[496]), add(mul(v[1], m[497], mt[497]), add(mul(v[2], m[498], mt[498]), mul(v[3], m[499], mt[499]))))));
|
||||
- _mm256_storeu2_m128d((double*)&psi[I + d0 + d1 + d3 + d4], (double*)&psi[I + d1 + d3 + d4], add(tmp[13], add(mul(v[0], m[500], mt[500]), add(mul(v[1], m[501], mt[501]), add(mul(v[2], m[502], mt[502]), mul(v[3], m[503], mt[503]))))));
|
||||
- _mm256_storeu2_m128d((double*)&psi[I + d0 + d2 + d3 + d4], (double*)&psi[I + d2 + d3 + d4], add(tmp[14], add(mul(v[0], m[504], mt[504]), add(mul(v[1], m[505], mt[505]), add(mul(v[2], m[506], mt[506]), mul(v[3], m[507], mt[507]))))));
|
||||
- _mm256_storeu2_m128d((double*)&psi[I + d0 + d1 + d2 + d3 + d4], (double*)&psi[I + d1 + d2 + d3 + d4], add(tmp[15], add(mul(v[0], m[508], mt[508]), add(mul(v[1], m[509], mt[509]), add(mul(v[2], m[510], mt[510]), mul(v[3], m[511], mt[511]))))));
|
||||
+ v[0] = load2(psi + 2 * (I + d2 + d3 + d4));
|
||||
+ v[1] = load2(psi + 2 * (I + d0 + d2 + d3 + d4));
|
||||
+ v[2] = load2(psi + 2 * (I + d1 + d2 + d3 + d4));
|
||||
+ v[3] = load2(psi + 2 * (I + d0 + d1 + d2 + d3 + d4));
|
||||
+
|
||||
+ _mm256_storeu2_m128d(psi + 2 * (I + d0), psi + 2 * I, add(tmp[0], add(mul(v[0], m[448], mt[448]), add(mul(v[1], m[449], mt[449]), add(mul(v[2], m[450], mt[450]), mul(v[3], m[451], mt[451]))))));
|
||||
+ _mm256_storeu2_m128d(psi + 2 * (I + d0 + d1), psi + 2 * (I + d1), add(tmp[1], add(mul(v[0], m[452], mt[452]), add(mul(v[1], m[453], mt[453]), add(mul(v[2], m[454], mt[454]), mul(v[3], m[455], mt[455]))))));
|
||||
+ _mm256_storeu2_m128d(psi + 2 * (I + d0 + d2), psi + 2 * (I + d2), add(tmp[2], add(mul(v[0], m[456], mt[456]), add(mul(v[1], m[457], mt[457]), add(mul(v[2], m[458], mt[458]), mul(v[3], m[459], mt[459]))))));
|
||||
+ _mm256_storeu2_m128d(psi + 2 * (I + d0 + d1 + d2), psi + 2 * (I + d1 + d2), add(tmp[3], add(mul(v[0], m[460], mt[460]), add(mul(v[1], m[461], mt[461]), add(mul(v[2], m[462], mt[462]), mul(v[3], m[463], mt[463]))))));
|
||||
+ _mm256_storeu2_m128d(psi + 2 * (I + d0 + d3), psi + 2 * (I + d3), add(tmp[4], add(mul(v[0], m[464], mt[464]), add(mul(v[1], m[465], mt[465]), add(mul(v[2], m[466], mt[466]), mul(v[3], m[467], mt[467]))))));
|
||||
+ _mm256_storeu2_m128d(psi + 2 * (I + d0 + d1 + d3), psi + 2 * (I + d1 + d3), add(tmp[5], add(mul(v[0], m[468], mt[468]), add(mul(v[1], m[469], mt[469]), add(mul(v[2], m[470], mt[470]), mul(v[3], m[471], mt[471]))))));
|
||||
+ _mm256_storeu2_m128d(psi + 2 * (I + d0 + d2 + d3), psi + 2 * (I + d2 + d3), add(tmp[6], add(mul(v[0], m[472], mt[472]), add(mul(v[1], m[473], mt[473]), add(mul(v[2], m[474], mt[474]), mul(v[3], m[475], mt[475]))))));
|
||||
+ _mm256_storeu2_m128d(psi + 2 * (I + d0 + d1 + d2 + d3), psi + 2 * (I + d1 + d2 + d3), add(tmp[7], add(mul(v[0], m[476], mt[476]), add(mul(v[1], m[477], mt[477]), add(mul(v[2], m[478], mt[478]), mul(v[3], m[479], mt[479]))))));
|
||||
+ _mm256_storeu2_m128d(psi + 2 * (I + d0 + d4), psi + 2 * (I + d4), add(tmp[8], add(mul(v[0], m[480], mt[480]), add(mul(v[1], m[481], mt[481]), add(mul(v[2], m[482], mt[482]), mul(v[3], m[483], mt[483]))))));
|
||||
+ _mm256_storeu2_m128d(psi + 2 * (I + d0 + d1 + d4), psi + 2 * (I + d1 + d4), add(tmp[9], add(mul(v[0], m[484], mt[484]), add(mul(v[1], m[485], mt[485]), add(mul(v[2], m[486], mt[486]), mul(v[3], m[487], mt[487]))))));
|
||||
+ _mm256_storeu2_m128d(psi + 2 * (I + d0 + d2 + d4), psi + 2 * (I + d2 + d4), add(tmp[10], add(mul(v[0], m[488], mt[488]), add(mul(v[1], m[489], mt[489]), add(mul(v[2], m[490], mt[490]), mul(v[3], m[491], mt[491]))))));
|
||||
+ _mm256_storeu2_m128d(psi + 2 * (I + d0 + d1 + d2 + d4), psi + 2 * (I + d1 + d2 + d4), add(tmp[11], add(mul(v[0], m[492], mt[492]), add(mul(v[1], m[493], mt[493]), add(mul(v[2], m[494], mt[494]), mul(v[3], m[495], mt[495]))))));
|
||||
+ _mm256_storeu2_m128d(psi + 2 * (I + d0 + d3 + d4), psi + 2 * (I + d3 + d4), add(tmp[12], add(mul(v[0], m[496], mt[496]), add(mul(v[1], m[497], mt[497]), add(mul(v[2], m[498], mt[498]), mul(v[3], m[499], mt[499]))))));
|
||||
+ _mm256_storeu2_m128d(psi + 2 * (I + d0 + d1 + d3 + d4), psi + 2 * (I + d1 + d3 + d4), add(tmp[13], add(mul(v[0], m[500], mt[500]), add(mul(v[1], m[501], mt[501]), add(mul(v[2], m[502], mt[502]), mul(v[3], m[503], mt[503]))))));
|
||||
+ _mm256_storeu2_m128d(psi + 2 * (I + d0 + d2 + d3 + d4), psi + 2 * (I + d2 + d3 + d4), add(tmp[14], add(mul(v[0], m[504], mt[504]), add(mul(v[1], m[505], mt[505]), add(mul(v[2], m[506], mt[506]), mul(v[3], m[507], mt[507]))))));
|
||||
+ _mm256_storeu2_m128d(psi + 2 * (I + d0 + d1 + d2 + d3 + d4), psi + 2 * (I + d1 + d2 + d3 + d4), add(tmp[15], add(mul(v[0], m[508], mt[508]), add(mul(v[1], m[509], mt[509]), add(mul(v[2], m[510], mt[510]), mul(v[3], m[511], mt[511]))))));
|
||||
|
||||
}
|
||||
|
||||
// bit indices id[.] are given from high to low (e.g. control first for CNOT)
|
||||
template <class V, class M>
|
||||
-void kernel(V &psi, unsigned id4, unsigned id3, unsigned id2, unsigned id1, unsigned id0, M const& m, std::size_t ctrlmask)
|
||||
+void kernel(V &psi, unsigned id4, unsigned id3, unsigned id2, unsigned id1, unsigned id0, M const& m, std::size_t ctrlmask, unsigned len)
|
||||
{
|
||||
- std::size_t n = psi.size();
|
||||
+ std::size_t n = len;
|
||||
std::size_t d0 = 1UL << id0;
|
||||
std::size_t d1 = 1UL << id1;
|
||||
std::size_t d2 = 1UL << id2;
|
||||
diff --color -aur ProjectQ-0.5.1/projectq/backends/_sim/_cppkernels/simulator.hpp ProjectQ-0.5.1_new/projectq/backends/_sim/_cppkernels/simulator.hpp
|
||||
--- ProjectQ-0.5.1/projectq/backends/_sim/_cppkernels/simulator.hpp 2020-06-05 21:07:57.000000000 +0800
|
||||
+++ ProjectQ-0.5.1_new/projectq/backends/_sim/_cppkernels/simulator.hpp 2021-04-20 11:46:27.115554725 +0800
|
||||
@@ -18,11 +18,7 @@
|
||||
#include <vector>
|
||||
#include <complex>
|
||||
|
||||
-#if defined(NOINTRIN) || !defined(INTRIN)
|
||||
-#include "nointrin/kernels.hpp"
|
||||
-#else
|
||||
#include "intrin/kernels.hpp"
|
||||
-#endif
|
||||
|
||||
#include "intrin/alignedallocator.hpp"
|
||||
#include "fusion.hpp"
|
||||
@@ -32,173 +28,29 @@
|
||||
#include <tuple>
|
||||
#include <random>
|
||||
#include <functional>
|
||||
-
|
||||
+#include <cstring>
|
||||
|
||||
class Simulator{
|
||||
public:
|
||||
using calc_type = double;
|
||||
using complex_type = std::complex<calc_type>;
|
||||
- using StateVector = std::vector<complex_type, aligned_allocator<complex_type,512>>;
|
||||
+ using StateVector = calc_type *;
|
||||
using Map = std::map<unsigned, unsigned>;
|
||||
using RndEngine = std::mt19937;
|
||||
using Term = std::vector<std::pair<unsigned, char>>;
|
||||
using TermsDict = std::vector<std::pair<Term, calc_type>>;
|
||||
using ComplexTermsDict = std::vector<std::pair<Term, complex_type>>;
|
||||
+ StateVector vec_;
|
||||
|
||||
- Simulator(unsigned seed = 1) : N_(0), vec_(1,0.), fusion_qubits_min_(4),
|
||||
+ Simulator(unsigned seed = 1, unsigned N = 0) : N_(N), fusion_qubits_min_(4),
|
||||
fusion_qubits_max_(5), rnd_eng_(seed) {
|
||||
+ len_ = 1UL << (N_ + 1);
|
||||
+ vec_ = (StateVector)calloc(len_, sizeof(calc_type));
|
||||
vec_[0]=1.; // all-zero initial state
|
||||
std::uniform_real_distribution<double> dist(0., 1.);
|
||||
rng_ = std::bind(dist, std::ref(rnd_eng_));
|
||||
- }
|
||||
-
|
||||
- void allocate_qubit(unsigned id){
|
||||
- if (map_.count(id) == 0){
|
||||
- map_[id] = N_++;
|
||||
- StateVector newvec; // avoid large memory allocations
|
||||
- if( tmpBuff1_.capacity() >= (1UL << N_) )
|
||||
- std::swap(newvec, tmpBuff1_);
|
||||
- newvec.resize(1UL << N_);
|
||||
-#pragma omp parallel for schedule(static)
|
||||
- for (std::size_t i = 0; i < newvec.size(); ++i)
|
||||
- newvec[i] = (i < vec_.size())?vec_[i]:0.;
|
||||
- std::swap(vec_, newvec);
|
||||
- // recycle large memory
|
||||
- std::swap(tmpBuff1_, newvec);
|
||||
- if( tmpBuff1_.capacity() < tmpBuff2_.capacity() )
|
||||
- std::swap(tmpBuff1_, tmpBuff2_);
|
||||
- }
|
||||
- else
|
||||
- throw(std::runtime_error(
|
||||
- "AllocateQubit: ID already exists. Qubit IDs should be unique."));
|
||||
- }
|
||||
-
|
||||
- bool get_classical_value(unsigned id, calc_type tol = 1.e-12){
|
||||
- run();
|
||||
- unsigned pos = map_[id];
|
||||
- std::size_t delta = (1UL << pos);
|
||||
-
|
||||
- for (std::size_t i = 0; i < vec_.size(); i += 2*delta){
|
||||
- for (std::size_t j = 0; j < delta; ++j){
|
||||
- if (std::norm(vec_[i+j]) > tol)
|
||||
- return false;
|
||||
- if (std::norm(vec_[i+j+delta]) > tol)
|
||||
- return true;
|
||||
- }
|
||||
- }
|
||||
- assert(false); // this will never happen
|
||||
- return false; // suppress 'control reaches end of non-void...'
|
||||
- }
|
||||
-
|
||||
- bool is_classical(unsigned id, calc_type tol = 1.e-12){
|
||||
- run();
|
||||
- unsigned pos = map_[id];
|
||||
- std::size_t delta = (1UL << pos);
|
||||
-
|
||||
- short up = 0, down = 0;
|
||||
- #pragma omp parallel for schedule(static) reduction(|:up,down)
|
||||
- for (std::size_t i = 0; i < vec_.size(); i += 2*delta){
|
||||
- for (std::size_t j = 0; j < delta; ++j){
|
||||
- up = up | ((std::norm(vec_[i+j]) > tol)&1);
|
||||
- down = down | ((std::norm(vec_[i+j+delta]) > tol)&1);
|
||||
- }
|
||||
- }
|
||||
-
|
||||
- return 1 == (up^down);
|
||||
- }
|
||||
-
|
||||
- void collapse_vector(unsigned id, bool value = false, bool shrink = false){
|
||||
- run();
|
||||
- unsigned pos = map_[id];
|
||||
- std::size_t delta = (1UL << pos);
|
||||
-
|
||||
- if (!shrink){
|
||||
- #pragma omp parallel for schedule(static)
|
||||
- for (std::size_t i = 0; i < vec_.size(); i += 2*delta){
|
||||
- for (std::size_t j = 0; j < delta; ++j)
|
||||
- vec_[i+j+static_cast<std::size_t>(!value)*delta] = 0.;
|
||||
- }
|
||||
- }
|
||||
- else{
|
||||
- StateVector newvec; // avoid costly memory reallocations
|
||||
- if( tmpBuff1_.capacity() >= (1UL << (N_-1)) )
|
||||
- std::swap(tmpBuff1_, newvec);
|
||||
- newvec.resize((1UL << (N_-1)));
|
||||
- #pragma omp parallel for schedule(static) if(0)
|
||||
- for (std::size_t i = 0; i < vec_.size(); i += 2*delta)
|
||||
- std::copy_n(&vec_[i + static_cast<std::size_t>(value)*delta],
|
||||
- delta, &newvec[i/2]);
|
||||
- std::swap(vec_, newvec);
|
||||
- std::swap(tmpBuff1_, newvec);
|
||||
- if( tmpBuff1_.capacity() < tmpBuff2_.capacity() )
|
||||
- std::swap(tmpBuff1_, tmpBuff2_);
|
||||
-
|
||||
- for (auto& p : map_){
|
||||
- if (p.second > pos)
|
||||
- p.second--;
|
||||
- }
|
||||
- map_.erase(id);
|
||||
- N_--;
|
||||
- }
|
||||
- }
|
||||
-
|
||||
- void measure_qubits(std::vector<unsigned> const& ids, std::vector<bool> &res){
|
||||
- run();
|
||||
-
|
||||
- std::vector<unsigned> positions(ids.size());
|
||||
- for (unsigned i = 0; i < ids.size(); ++i)
|
||||
- positions[i] = map_[ids[i]];
|
||||
-
|
||||
- calc_type P = 0.;
|
||||
- calc_type rnd = rng_();
|
||||
-
|
||||
- // pick entry at random with probability |entry|^2
|
||||
- std::size_t pick = 0;
|
||||
- while (P < rnd && pick < vec_.size())
|
||||
- P += std::norm(vec_[pick++]);
|
||||
-
|
||||
- pick--;
|
||||
- // determine result vector (boolean values for each qubit)
|
||||
- // and create mask to detect bad entries (i.e., entries that don't agree with measurement)
|
||||
- res = std::vector<bool>(ids.size());
|
||||
- std::size_t mask = 0;
|
||||
- std::size_t val = 0;
|
||||
- for (unsigned i = 0; i < ids.size(); ++i){
|
||||
- bool r = ((pick >> positions[i]) & 1) == 1;
|
||||
- res[i] = r;
|
||||
- mask |= (1UL << positions[i]);
|
||||
- val |= (static_cast<std::size_t>(r&1) << positions[i]);
|
||||
- }
|
||||
- // set bad entries to 0
|
||||
- calc_type N = 0.;
|
||||
- #pragma omp parallel for reduction(+:N) schedule(static)
|
||||
- for (std::size_t i = 0; i < vec_.size(); ++i){
|
||||
- if ((i & mask) != val)
|
||||
- vec_[i] = 0.;
|
||||
- else
|
||||
- N += std::norm(vec_[i]);
|
||||
- }
|
||||
- // re-normalize
|
||||
- N = 1./std::sqrt(N);
|
||||
- #pragma omp parallel for schedule(static)
|
||||
- for (std::size_t i = 0; i < vec_.size(); ++i)
|
||||
- vec_[i] *= N;
|
||||
- }
|
||||
-
|
||||
- std::vector<bool> measure_qubits_return(std::vector<unsigned> const& ids){
|
||||
- std::vector<bool> ret;
|
||||
- measure_qubits(ids, ret);
|
||||
- return ret;
|
||||
- }
|
||||
-
|
||||
- void deallocate_qubit(unsigned id){
|
||||
- run();
|
||||
- assert(map_.count(id) == 1);
|
||||
- if (!is_classical(id))
|
||||
- throw(std::runtime_error("Error: Qubit has not been measured / uncomputed! There is most likely a bug in your code."));
|
||||
-
|
||||
- bool value = get_classical_value(id);
|
||||
- collapse_vector(id, value, true);
|
||||
+ for (unsigned i = 0; i < N_; i++)
|
||||
+ map_[i] = i;
|
||||
}
|
||||
|
||||
template <class M>
|
||||
@@ -221,84 +73,13 @@
|
||||
fused_gates_ = fused_gates;
|
||||
}
|
||||
|
||||
- template <class F, class QuReg>
|
||||
- void emulate_math(F const& f, QuReg quregs, const std::vector<unsigned>& ctrl,
|
||||
- bool parallelize = false){
|
||||
- run();
|
||||
- auto ctrlmask = get_control_mask(ctrl);
|
||||
-
|
||||
- for (unsigned i = 0; i < quregs.size(); ++i)
|
||||
- for (unsigned j = 0; j < quregs[i].size(); ++j)
|
||||
- quregs[i][j] = map_[quregs[i][j]];
|
||||
-
|
||||
- StateVector newvec; // avoid costly memory reallocations
|
||||
- if( tmpBuff1_.capacity() >= vec_.size() )
|
||||
- std::swap(newvec, tmpBuff1_);
|
||||
- newvec.resize(vec_.size());
|
||||
-#pragma omp parallel for schedule(static)
|
||||
- for (std::size_t i = 0; i < vec_.size(); i++)
|
||||
- newvec[i] = 0;
|
||||
-
|
||||
-//#pragma omp parallel reduction(+:newvec[:newvec.size()]) if(parallelize) // requires OpenMP 4.5
|
||||
- {
|
||||
- std::vector<int> res(quregs.size());
|
||||
- //#pragma omp for schedule(static)
|
||||
- for (std::size_t i = 0; i < vec_.size(); ++i){
|
||||
- if ((ctrlmask&i) == ctrlmask){
|
||||
- for (unsigned qr_i = 0; qr_i < quregs.size(); ++qr_i){
|
||||
- res[qr_i] = 0;
|
||||
- for (unsigned qb_i = 0; qb_i < quregs[qr_i].size(); ++qb_i)
|
||||
- res[qr_i] |= ((i >> quregs[qr_i][qb_i])&1) << qb_i;
|
||||
- }
|
||||
- f(res);
|
||||
- auto new_i = i;
|
||||
- for (unsigned qr_i = 0; qr_i < quregs.size(); ++qr_i){
|
||||
- for (unsigned qb_i = 0; qb_i < quregs[qr_i].size(); ++qb_i){
|
||||
- if (!(((new_i >> quregs[qr_i][qb_i])&1) == ((res[qr_i] >> qb_i)&1)))
|
||||
- new_i ^= (1UL << quregs[qr_i][qb_i]);
|
||||
- }
|
||||
- }
|
||||
- newvec[new_i] += vec_[i];
|
||||
- }
|
||||
- else
|
||||
- newvec[i] += vec_[i];
|
||||
- }
|
||||
- }
|
||||
- std::swap(vec_, newvec);
|
||||
- std::swap(tmpBuff1_, newvec);
|
||||
- }
|
||||
-
|
||||
- // faster version without calling python
|
||||
- template<class QuReg>
|
||||
- inline void emulate_math_addConstant(int a, const QuReg& quregs, const std::vector<unsigned>& ctrl)
|
||||
- {
|
||||
- emulate_math([a](std::vector<int> &res){for(auto& x: res) x = x + a;}, quregs, ctrl, true);
|
||||
- }
|
||||
-
|
||||
- // faster version without calling python
|
||||
- template<class QuReg>
|
||||
- inline void emulate_math_addConstantModN(int a, int N, const QuReg& quregs, const std::vector<unsigned>& ctrl)
|
||||
- {
|
||||
- emulate_math([a,N](std::vector<int> &res){for(auto& x: res) x = (x + a) % N;}, quregs, ctrl, true);
|
||||
- }
|
||||
-
|
||||
- // faster version without calling python
|
||||
- template<class QuReg>
|
||||
- inline void emulate_math_multiplyByConstantModN(int a, int N, const QuReg& quregs, const std::vector<unsigned>& ctrl)
|
||||
- {
|
||||
- emulate_math([a,N](std::vector<int> &res){for(auto& x: res) x = (x * a) % N;}, quregs, ctrl, true);
|
||||
- }
|
||||
-
|
||||
calc_type get_expectation_value(TermsDict const& td, std::vector<unsigned> const& ids){
|
||||
run();
|
||||
calc_type expectation = 0.;
|
||||
|
||||
- StateVector current_state; // avoid costly memory reallocations
|
||||
- if( tmpBuff1_.capacity() >= vec_.size() )
|
||||
- std::swap(tmpBuff1_, current_state);
|
||||
- current_state.resize(vec_.size());
|
||||
+ StateVector current_state = (StateVector)malloc(len_ *sizeof(calc_type));
|
||||
#pragma omp parallel for schedule(static)
|
||||
- for (std::size_t i = 0; i < vec_.size(); ++i)
|
||||
+ for (std::size_t i = 0; i < len_; ++i)
|
||||
current_state[i] = vec_[i];
|
||||
|
||||
for (auto const& term : td){
|
||||
@@ -306,81 +87,53 @@
|
||||
apply_term(term.first, ids, {});
|
||||
calc_type delta = 0.;
|
||||
#pragma omp parallel for reduction(+:delta) schedule(static)
|
||||
- for (std::size_t i = 0; i < vec_.size(); ++i){
|
||||
- auto const a1 = std::real(current_state[i]);
|
||||
- auto const b1 = -std::imag(current_state[i]);
|
||||
- auto const a2 = std::real(vec_[i]);
|
||||
- auto const b2 = std::imag(vec_[i]);
|
||||
+ for (std::size_t i = 0; i < (len_ >> 1); ++i){
|
||||
+ auto const a1 = current_state[2 * i];
|
||||
+ auto const b1 = -current_state[2 * i + 1];
|
||||
+ auto const a2 = vec_[2 * i];
|
||||
+ auto const b2 = vec_[2 * i + 1];
|
||||
delta += a1 * a2 - b1 * b2;
|
||||
// reset vec_
|
||||
- vec_[i] = current_state[i];
|
||||
+ vec_[2 * i] = current_state[2 * i];
|
||||
+ vec_[2 * i + 1] = current_state[2 * i + 1];
|
||||
}
|
||||
expectation += coefficient * delta;
|
||||
}
|
||||
- std::swap(current_state, tmpBuff1_);
|
||||
+ if (NULL != current_state){
|
||||
+ free(current_state);
|
||||
+ current_state = NULL;
|
||||
+ }
|
||||
return expectation;
|
||||
}
|
||||
|
||||
void apply_qubit_operator(ComplexTermsDict const& td, std::vector<unsigned> const& ids){
|
||||
run();
|
||||
- StateVector new_state, current_state; // avoid costly memory reallocations
|
||||
- if( tmpBuff1_.capacity() >= vec_.size() )
|
||||
- std::swap(tmpBuff1_, new_state);
|
||||
- if( tmpBuff2_.capacity() >= vec_.size() )
|
||||
- std::swap(tmpBuff2_, current_state);
|
||||
- new_state.resize(vec_.size());
|
||||
- current_state.resize(vec_.size());
|
||||
+ StateVector new_state = (StateVector)calloc(len_, sizeof(calc_type));
|
||||
+ StateVector current_state = (StateVector)malloc(len_ * sizeof(calc_type));
|
||||
#pragma omp parallel for schedule(static)
|
||||
- for (std::size_t i = 0; i < vec_.size(); ++i){
|
||||
- new_state[i] = 0;
|
||||
+ for (std::size_t i = 0; i < len_; ++i){
|
||||
current_state[i] = vec_[i];
|
||||
}
|
||||
for (auto const& term : td){
|
||||
auto const& coefficient = term.second;
|
||||
apply_term(term.first, ids, {});
|
||||
#pragma omp parallel for schedule(static)
|
||||
- for (std::size_t i = 0; i < vec_.size(); ++i){
|
||||
- new_state[i] += coefficient * vec_[i];
|
||||
- vec_[i] = current_state[i];
|
||||
+ for (std::size_t i = 0; i < (len_ >> 1); ++i){
|
||||
+ new_state[2 * i] += coefficient.real() * vec_[2 * i] - coefficient.imag() * vec_[2 * i + 1];
|
||||
+ new_state[2 * i + 1] += coefficient.real() * vec_[2 * i + 1] + coefficient.imag() * vec_[2 * i];
|
||||
+ vec_[2 * i] = current_state[2 * i];
|
||||
+ vec_[2 * i + 1] = current_state[2 * i + 1];
|
||||
}
|
||||
}
|
||||
- std::swap(vec_, new_state);
|
||||
- std::swap(tmpBuff1_, new_state);
|
||||
- std::swap(tmpBuff2_, current_state);
|
||||
- }
|
||||
-
|
||||
- calc_type get_probability(std::vector<bool> const& bit_string,
|
||||
- std::vector<unsigned> const& ids){
|
||||
- run();
|
||||
- if (!check_ids(ids))
|
||||
- throw(std::runtime_error("get_probability(): Unknown qubit id. Please make sure you have called eng.flush()."));
|
||||
- std::size_t mask = 0, bit_str = 0;
|
||||
- for (unsigned i = 0; i < ids.size(); ++i){
|
||||
- mask |= 1UL << map_[ids[i]];
|
||||
- bit_str |= (bit_string[i]?1UL:0UL) << map_[ids[i]];
|
||||
- }
|
||||
- calc_type probability = 0.;
|
||||
- #pragma omp parallel for reduction(+:probability) schedule(static)
|
||||
- for (std::size_t i = 0; i < vec_.size(); ++i)
|
||||
- if ((i & mask) == bit_str)
|
||||
- probability += std::norm(vec_[i]);
|
||||
- return probability;
|
||||
- }
|
||||
-
|
||||
- complex_type const& get_amplitude(std::vector<bool> const& bit_string,
|
||||
- std::vector<unsigned> const& ids){
|
||||
- run();
|
||||
- std::size_t chk = 0;
|
||||
- std::size_t index = 0;
|
||||
- for (unsigned i = 0; i < ids.size(); ++i){
|
||||
- if (map_.count(ids[i]) == 0)
|
||||
- break;
|
||||
- chk |= 1UL << map_[ids[i]];
|
||||
- index |= (bit_string[i]?1UL:0UL) << map_[ids[i]];
|
||||
+ if (NULL != vec_)
|
||||
+ free(vec_);
|
||||
+ vec_ = new_state;
|
||||
+ if (NULL != new_state)
|
||||
+ new_state = NULL;
|
||||
+ if (NULL != current_state){
|
||||
+ free(current_state);
|
||||
+ current_state = NULL;
|
||||
}
|
||||
- if (chk + 1 != vec_.size())
|
||||
- throw(std::runtime_error("The second argument to get_amplitude() must be a permutation of all allocated qubits. Please make sure you have called eng.flush()."));
|
||||
- return vec_[index];
|
||||
}
|
||||
|
||||
void emulate_time_evolution(TermsDict const& tdict, calc_type const& time,
|
||||
@@ -400,87 +153,71 @@
|
||||
}
|
||||
unsigned s = std::abs(time) * op_nrm + 1.;
|
||||
complex_type correction = std::exp(-time * I * tr / (double)s);
|
||||
- auto output_state = vec_;
|
||||
+ auto output_state = copy(vec_, len_);
|
||||
auto ctrlmask = get_control_mask(ctrl);
|
||||
for (unsigned i = 0; i < s; ++i){
|
||||
calc_type nrm_change = 1.;
|
||||
for (unsigned k = 0; nrm_change > 1.e-12; ++k){
|
||||
auto coeff = (-time * I) / double(s * (k + 1));
|
||||
- auto current_state = vec_;
|
||||
- auto update = StateVector(vec_.size(), 0.);
|
||||
+ auto current_state = copy(vec_, len_);
|
||||
+ auto update = (StateVector)calloc(len_, sizeof(calc_type));
|
||||
for (auto const& tup : td){
|
||||
apply_term(tup.first, ids, {});
|
||||
#pragma omp parallel for schedule(static)
|
||||
- for (std::size_t j = 0; j < vec_.size(); ++j){
|
||||
+ for (std::size_t j = 0; j < len_; ++j){
|
||||
update[j] += vec_[j] * tup.second;
|
||||
vec_[j] = current_state[j];
|
||||
}
|
||||
}
|
||||
nrm_change = 0.;
|
||||
#pragma omp parallel for reduction(+:nrm_change) schedule(static)
|
||||
- for (std::size_t j = 0; j < vec_.size(); ++j){
|
||||
- update[j] *= coeff;
|
||||
- vec_[j] = update[j];
|
||||
+ for (std::size_t j = 0; j < (len_ >> 1); ++j){
|
||||
+ complex_type tmp(update[2 * j], update[2 * j + 1]);
|
||||
+ tmp *= coeff;
|
||||
+ update[2 * j] *= std::real(tmp);
|
||||
+ update[2 * j + 1] *= std::imag(tmp);
|
||||
+ vec_[2 * j] = update[2 * j];
|
||||
+ vec_[2 * j + 1] = update[2 * j + 1];
|
||||
if ((j & ctrlmask) == ctrlmask){
|
||||
- output_state[j] += update[j];
|
||||
- nrm_change += std::norm(update[j]);
|
||||
+ output_state[2 * j] += update[2 * j];
|
||||
+ output_state[2 * j + 1] += update[2 * j + 1];
|
||||
+ nrm_change += std::sqrt(update[2 * j] * update[2 * j] + update[2 * j + 1] * update[2 * j + 1]);
|
||||
}
|
||||
}
|
||||
nrm_change = std::sqrt(nrm_change);
|
||||
+ if (NULL != current_state){
|
||||
+ free(current_state);
|
||||
+ current_state = NULL;
|
||||
+ }
|
||||
+ if (NULL != update){
|
||||
+ free(update);
|
||||
+ update = NULL;
|
||||
+ }
|
||||
}
|
||||
#pragma omp parallel for schedule(static)
|
||||
- for (std::size_t j = 0; j < vec_.size(); ++j){
|
||||
- if ((j & ctrlmask) == ctrlmask)
|
||||
- output_state[j] *= correction;
|
||||
- vec_[j] = output_state[j];
|
||||
+ for (std::size_t j = 0; j < (len_ >>1); ++j){
|
||||
+ if ((j & ctrlmask) == ctrlmask){
|
||||
+ complex_type tmp(output_state[2 * j], output_state[2 * j + 1]);
|
||||
+ tmp *= correction;
|
||||
+ output_state[2 * j] = std::real(tmp);
|
||||
+ output_state[2 * j + 1] =std::imag(tmp);
|
||||
+ }
|
||||
+ vec_[2 * j] = output_state[2 * j];
|
||||
+ vec_[2 * j + 1] = output_state[2 * j + 1];
|
||||
}
|
||||
}
|
||||
+ if (NULL != output_state){
|
||||
+ free(output_state);
|
||||
+ output_state = NULL;
|
||||
+ }
|
||||
}
|
||||
|
||||
void set_wavefunction(StateVector const& wavefunction, std::vector<unsigned> const& ordering){
|
||||
run();
|
||||
- // make sure there are 2^n amplitudes for n qubits
|
||||
- assert(wavefunction.size() == (1UL << ordering.size()));
|
||||
- // check that all qubits have been allocated previously
|
||||
- if (map_.size() != ordering.size() || !check_ids(ordering))
|
||||
- throw(std::runtime_error("set_wavefunction(): Invalid mapping provided. Please make sure all qubits have been allocated previously (call eng.flush())."));
|
||||
-
|
||||
- // set mapping and wavefunction
|
||||
- for (unsigned i = 0; i < ordering.size(); ++i)
|
||||
- map_[ordering[i]] = i;
|
||||
- #pragma omp parallel for schedule(static)
|
||||
- for (std::size_t i = 0; i < wavefunction.size(); ++i)
|
||||
- vec_[i] = wavefunction[i];
|
||||
- }
|
||||
-
|
||||
- void collapse_wavefunction(std::vector<unsigned> const& ids, std::vector<bool> const& values){
|
||||
- run();
|
||||
- assert(ids.size() == values.size());
|
||||
- if (!check_ids(ids))
|
||||
- throw(std::runtime_error("collapse_wavefunction(): Unknown qubit id(s) provided. Try calling eng.flush() before invoking this function."));
|
||||
- std::size_t mask = 0, val = 0;
|
||||
- for (unsigned i = 0; i < ids.size(); ++i){
|
||||
- mask |= (1UL << map_[ids[i]]);
|
||||
- val |= ((values[i]?1UL:0UL) << map_[ids[i]]);
|
||||
- }
|
||||
- // set bad entries to 0 and compute probability of outcome to renormalize
|
||||
- calc_type N = 0.;
|
||||
- #pragma omp parallel for reduction(+:N) schedule(static)
|
||||
- for (std::size_t i = 0; i < vec_.size(); ++i){
|
||||
- if ((i & mask) == val)
|
||||
- N += std::norm(vec_[i]);
|
||||
- }
|
||||
- if (N < 1.e-12)
|
||||
- throw(std::runtime_error("collapse_wavefunction(): Invalid collapse! Probability is ~0."));
|
||||
- // re-normalize (if possible)
|
||||
- N = 1./std::sqrt(N);
|
||||
- #pragma omp parallel for schedule(static)
|
||||
- for (std::size_t i = 0; i < vec_.size(); ++i){
|
||||
- if ((i & mask) != val)
|
||||
- vec_[i] = 0.;
|
||||
- else
|
||||
- vec_[i] *= N;
|
||||
+ if (NULL != vec_){
|
||||
+ free(vec_);
|
||||
}
|
||||
+ vec_ = copy(wavefunction, len_);
|
||||
}
|
||||
|
||||
void run(){
|
||||
@@ -500,23 +237,23 @@
|
||||
switch (ids.size()){
|
||||
case 1:
|
||||
#pragma omp parallel
|
||||
- kernel(vec_, ids[0], m, ctrlmask);
|
||||
+ kernel(vec_, ids[0], m, ctrlmask, len_ >> 1);
|
||||
break;
|
||||
case 2:
|
||||
#pragma omp parallel
|
||||
- kernel(vec_, ids[1], ids[0], m, ctrlmask);
|
||||
+ kernel(vec_, ids[1], ids[0], m, ctrlmask, len_ >> 1);
|
||||
break;
|
||||
case 3:
|
||||
#pragma omp parallel
|
||||
- kernel(vec_, ids[2], ids[1], ids[0], m, ctrlmask);
|
||||
+ kernel(vec_, ids[2], ids[1], ids[0], m, ctrlmask, len_ >> 1);
|
||||
break;
|
||||
case 4:
|
||||
#pragma omp parallel
|
||||
- kernel(vec_, ids[3], ids[2], ids[1], ids[0], m, ctrlmask);
|
||||
+ kernel(vec_, ids[3], ids[2], ids[1], ids[0], m, ctrlmask, len_ >> 1);
|
||||
break;
|
||||
case 5:
|
||||
#pragma omp parallel
|
||||
- kernel(vec_, ids[4], ids[3], ids[2], ids[1], ids[0], m, ctrlmask);
|
||||
+ kernel(vec_, ids[4], ids[3], ids[2], ids[1], ids[0], m, ctrlmask, len_ >> 1);
|
||||
break;
|
||||
default:
|
||||
throw std::invalid_argument("Gates with more than 5 qubits are not supported!");
|
||||
@@ -525,12 +262,27 @@
|
||||
fused_gates_ = Fusion();
|
||||
}
|
||||
|
||||
- std::tuple<Map, StateVector&> cheat(){
|
||||
+ std::vector<complex_type> cheat(){
|
||||
run();
|
||||
- return make_tuple(map_, std::ref(vec_));
|
||||
+ std::vector<complex_type> result;
|
||||
+ for (unsigned int i = 0; i < (len_ >> 1); i++){
|
||||
+ result.push_back({vec_[2 * i], vec_[2 * i + 1]});
|
||||
+ }
|
||||
+ return result;
|
||||
+ }
|
||||
+
|
||||
+ inline StateVector copy(StateVector source, unsigned len){
|
||||
+ StateVector result = (StateVector)malloc(len * sizeof(calc_type));
|
||||
+#pragma omp parallel for schedule(static)
|
||||
+ for (std::size_t i = 0; i < len; ++i) {
|
||||
+ result[i] = source[i];
|
||||
}
|
||||
+ return result;
|
||||
+}
|
||||
|
||||
~Simulator(){
|
||||
+ if (NULL != vec_)
|
||||
+ free(vec_);
|
||||
}
|
||||
|
||||
private:
|
||||
@@ -562,18 +314,13 @@
|
||||
}
|
||||
|
||||
unsigned N_; // #qubits
|
||||
- StateVector vec_;
|
||||
+ unsigned len_;
|
||||
Map map_;
|
||||
Fusion fused_gates_;
|
||||
unsigned fusion_qubits_min_, fusion_qubits_max_;
|
||||
RndEngine rnd_eng_;
|
||||
std::function<double()> rng_;
|
||||
-
|
||||
- // large array buffers to avoid costly reallocations
|
||||
- static StateVector tmpBuff1_, tmpBuff2_;
|
||||
};
|
||||
|
||||
-Simulator::StateVector Simulator::tmpBuff1_;
|
||||
-Simulator::StateVector Simulator::tmpBuff2_;
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue