MCPcopy Create free account
hub / github.com/OriginQ/QPanda-2 / iqp_encode

Method iqp_encode

QAlg/Encode/Encode.cpp:835–887  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

833}
834
835void Encode::iqp_encode(const QVec &q, const vector<double>& data, const std::vector<pair<int, int>>& control_vector, const bool& inverse, const int& repeats)
836{
837 int size = data.size();
838
839 if (size > q.size()) {
840 QCERR_AND_THROW_ERRSTR(run_fail, "Error: data size or qubits size error.");
841 }
842
843 std::vector<pair<int, int>> control_vector_temp = control_vector;
844 int repeats_temp = repeats;
845
846 if (control_vector.empty())
847 {
848 for (int i = 0; i < size - 1; ++i) {
849 control_vector_temp.push_back({ i,i + 1 });
850 }
851 }
852
853 std::vector<double>data_temp(data);
854 QCircuit cir_tmp = QCircuit();
855
856 while (repeats_temp > 0)
857 {
858 repeats_temp--;
859 for (int i = 0; i < size; ++i) {
860 cir_tmp << H(q[i]);
861 }
862
863 for (int i = 0; i < size; ++i) {
864 cir_tmp << RZ(q[i], data[i]);
865 }
866
867 for (auto i : control_vector_temp) {
868 cir_tmp << CNOT(q[i.first], q[i.second]) << RZ(q[i.second], data[i.first] * data[i.second]) << CNOT(q[i.first], q[i.second]);
869 }
870
871 if (inverse) {
872 m_qcircuit << cir_tmp.dagger();
873 }
874 else {
875 m_qcircuit << cir_tmp;
876 }
877 }
878
879
880
881 for (int i = 0; i < data.size(); ++i)
882 {
883 m_out_qubits.push_back(q[i]);
884 }
885
886 return;
887}
888
889void Encode::ds_quantum_state_preparation(const QVec &q, const std::map<std::string, double>& data)
890{

Callers 1

Calls 8

HClass · 0.85
RZClass · 0.85
CNOTClass · 0.85
QCircuitClass · 0.50
sizeMethod · 0.45
emptyMethod · 0.45
push_backMethod · 0.45
daggerMethod · 0.45

Tested by 1