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

Method sparse_isometry

QAlg/Encode/Encode.cpp:1176–1294  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1174 return { alpha,beta,phi };
1175}
1176void Encode::sparse_isometry(const QVec &q, const std::map<std::string, double>& data)
1177{
1178
1179 if (data.empty())
1180 {
1181 QCERR_AND_THROW_ERRSTR(run_fail, "Error: The input map data must not null.");
1182 }
1183
1184 int size = (*data.begin()).first.size();
1185
1186 for (auto i : data)
1187 {
1188 if (i.first.size() != size)
1189 {
1190 QCERR_AND_THROW_ERRSTR(run_fail, "Error: The input map data.key must have same dimension.");
1191 }
1192 for (char c : i.first)
1193 {
1194 if (c != '0'&&c != '1')
1195 {
1196 QCERR_AND_THROW_ERRSTR(run_fail, "Error: The input map data.key must be binary string.");
1197 }
1198 }
1199
1200 }
1201
1202 const double max_precision = 1e-13;
1203 double tmp_sum = 0.0;
1204
1205 for (const auto i : data)
1206 {
1207
1208 tmp_sum += i.second*i.second;
1209 }
1210
1211 if (std::abs(1.0 - tmp_sum) > max_precision)
1212 {
1213 if (std::abs(tmp_sum) < max_precision)
1214 {
1215 QCERR("Error: The input vector b is zero.");
1216 return;
1217 }
1218
1219 QCERR_AND_THROW_ERRSTR(run_fail, "Error: The input vector b must satisfy the normalization condition.");
1220 }
1221
1222 if (data.size() == 1)
1223 {
1224 basic_encode(q, (*data.begin()).first);
1225 return;
1226 }
1227
1228 std::string key;
1229 QVec qubits;
1230 key = (*data.begin()).first;
1231 int n_qubits = key.size();
1232
1233 if (n_qubits > q.size()) {

Callers 1

Calls 14

RYClass · 0.85
absFunction · 0.50
ceilFunction · 0.50
log2Function · 0.50
acosFunction · 0.50
amplitude_encodeFunction · 0.50
emptyMethod · 0.45
sizeMethod · 0.45
beginMethod · 0.45
push_backMethod · 0.45
endMethod · 0.45
daggerMethod · 0.45

Tested by 1