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

Method parseQGateDataNode

Core/Utilities/Compiler/QProgDataParse.cpp:263–461  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

261
262
263void QProgDataParse::parseQGateDataNode(QProg &prog, const uint32_t &type_and_number, const uint32_t &qubits_data)
264{
265 QVec ctrl_qubits_vector;
266 if (!m_control_qubits_addr.empty())
267 {
268 for (auto qubit_addr : m_control_qubits_addr)
269 {
270 auto qubit = m_quantum_machine->allocateQubitThroughVirAddress(qubit_addr);
271 ctrl_qubits_vector.push_back(qubit);
272 }
273 m_control_qubits_addr.clear();
274 }
275
276 uint16_t type = (type_and_number & 0xffff) >> 1;
277 bool is_dagger = (type_and_number & 0x01) ? true : false;
278
279 const int kQubitMax = 2;
280 uint16_t qubit_array[kQubitMax] = { 0 };
281 qubit_array[0] = qubits_data & 0xffff;
282 qubit_array[1] = qubits_data >> (kCountMoveBit);
283
284 auto qubit0 = m_quantum_machine->allocateQubitThroughVirAddress(qubit_array[0]);
285 auto iter = std::find(m_qubits_addr.begin(), m_qubits_addr.end(), qubit_array[0]);
286 if (m_qubits_addr.end() == iter)
287 {
288 m_qubits_addr.push_back(qubit_array[0]);
289 }
290
291 uint32_t tmp = 1u << type;
292 if (kSingleGateValue & tmp)
293 {
294 auto iter = kSingleGateFun.find(type);
295 if (iter == kSingleGateFun.end())
296 {
297 QCERR("parse gate type error!");
298 throw runtime_error("parse gate type error!");
299 }
300
301 auto gate = iter->second(qubit0);
302 gate.setDagger(is_dagger);
303 gate.setControl(ctrl_qubits_vector);
304 prog << gate;
305 }
306 else if (kSingleGateAngleValue & tmp)
307 {
308 auto iter = kSingleGateAngelFun.find(type);
309 if (iter == kSingleGateAngelFun.end())
310 {
311 QCERR("parse gate type error!");
312 throw runtime_error("parse gate type error!");
313 }
314
315 m_iter++;
316 float angle = getAngle(*m_iter);
317 auto gate = iter->second(qubit0, angle);
318 gate.setDagger(is_dagger);
319 gate.setControl(ctrl_qubits_vector);
320 prog << gate;

Callers

nothing calls this directly

Calls 11

findFunction · 0.50
getAngleFunction · 0.50
emptyMethod · 0.45
push_backMethod · 0.45
clearMethod · 0.45
beginMethod · 0.45
endMethod · 0.45
findMethod · 0.45
setDaggerMethod · 0.45
setControlMethod · 0.45

Tested by

no test coverage detected