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

Method Parse

Core/Utilities/Tools/ArchGraph.cpp:130–230  ·  view source on GitHub ↗

* JsonBackendParser ********************************************************************/

Source from the content-addressed store, hash-verified

128* JsonBackendParser
129********************************************************************/
130std::unique_ptr<ArchGraph> JsonBackendParser<ArchGraph>::Parse(const rapidjson::Value& root)
131{
132 auto &quantum_chip_arch = root[JsonFields<ArchGraph>::_quantum_chip_arch_label.c_str()];
133
134 std::string name = "quantum_chip";
135 if (quantum_chip_arch.HasMember(JsonFields<ArchGraph>::_name_label.c_str()))
136 {
137 name = quantum_chip_arch[JsonFields<ArchGraph>::_name_label.c_str()].GetString();
138 }
139
140 if (!quantum_chip_arch[JsonFields<ArchGraph>::_qubits_label.c_str()].IsUint())
141 {
142 QCERR_AND_THROW(run_fail, "Error: ArchGraph json error.");
143 }
144 const uint32_t qubits = quantum_chip_arch[JsonFields<ArchGraph>::_qubits_label.c_str()].GetUint();
145
146 auto graph = ArchGraph::Create(qubits);
147 graph->putReg(name, std::to_string(qubits));
148
149 std::string adj_mat;
150 if (quantum_chip_arch.HasMember(JsonFields<ArchGraph>::_adj_list_label.c_str()))
151 {
152 adj_mat = JsonFields<ArchGraph>::_adj_list_label;
153 }
154 else if (quantum_chip_arch.HasMember("AdjMatrix")) {
155 adj_mat = "AdjMatrix";
156 }
157
158 if (adj_mat.empty())
159 {
160 QCERR_AND_THROW(run_fail, "Error: ArchGraph json error, no adjacent-matrix config.");
161 }
162 auto &adj = quantum_chip_arch[adj_mat.c_str()];
163
164 if (qubits < adj.MemberCount())
165 {
166 QCERR_AND_THROW(run_fail, "Error: ArchGraph json cofigure error.");
167 }
168
169 uint32_t qubit_index = 0;
170 for (rapidjson::Value::ConstMemberIterator iter = adj.MemberBegin(); iter != adj.MemberEnd(); ++iter, ++qubit_index)
171 {
172 std::string str_key = iter->name.GetString();
173 uint32_t key = stoi(str_key);
174#if 0
175 if (key != qubit_index)
176 {
177 QCERR_AND_THROW(run_fail, "Error: ArchGraph json index error occurs.");
178 }
179#endif
180
181 auto &iList = iter->value;
182 if (!iList.IsArray())
183 {
184 QCERR_AND_THROW(run_fail, "Error: ArchGraph json error.");
185 }
186
187 for (uint32_t j = 0, f = iList.Size(); j < f; ++j)

Callers

nothing calls this directly

Calls 11

HasMemberMethod · 0.80
GetStringMethod · 0.80
putRegMethod · 0.80
MemberCountMethod · 0.80
MemberBeginMethod · 0.80
MemberEndMethod · 0.80
GetDoubleMethod · 0.80
setWMethod · 0.80
emptyMethod · 0.45
SizeMethod · 0.45
putEdgeMethod · 0.45

Tested by

no test coverage detected