| 154 | } |
| 155 | |
| 156 | void QProgToOriginIR::transformQGate(AbstractQGateNode * pQGate, bool is_dagger) |
| 157 | { |
| 158 | if (nullptr == pQGate || nullptr == pQGate->getQGate()) |
| 159 | { |
| 160 | QCERR("pQGate is null"); |
| 161 | throw invalid_argument("pQGate is null"); |
| 162 | } |
| 163 | |
| 164 | QVec qubits_vector; |
| 165 | QVec ctr_qubits_vector; |
| 166 | bool is_toffoli = false; |
| 167 | bool is_barrier = false; |
| 168 | string all_ctr_qubits; |
| 169 | pQGate->getQuBitVector(qubits_vector); |
| 170 | pQGate->getControlVector(ctr_qubits_vector); |
| 171 | |
| 172 | if (PAULI_X_GATE == pQGate->getQGate()->getGateType() |
| 173 | && 2 == ctr_qubits_vector.size()) |
| 174 | { |
| 175 | is_toffoli = true; |
| 176 | } |
| 177 | if (BARRIER_GATE == pQGate->getQGate()->getGateType()) |
| 178 | { |
| 179 | is_barrier = true; |
| 180 | } |
| 181 | |
| 182 | if (pQGate->isDagger()) |
| 183 | { |
| 184 | m_OriginIR.emplace_back("DAGGER"); |
| 185 | } |
| 186 | if (!ctr_qubits_vector.empty()) |
| 187 | { |
| 188 | for (auto val : ctr_qubits_vector) |
| 189 | { |
| 190 | all_ctr_qubits = all_ctr_qubits + transformQubitFormat(val) + ","; |
| 191 | } |
| 192 | if (!is_toffoli && !is_barrier) |
| 193 | { |
| 194 | m_OriginIR.emplace_back("CONTROL " + all_ctr_qubits.substr(0, all_ctr_qubits.length() - 1)); |
| 195 | } |
| 196 | } |
| 197 | auto iter = m_gatetype.find(pQGate->getQGate()->getGateType()); |
| 198 | if (iter == m_gatetype.end()) |
| 199 | { |
| 200 | QCERR("unknown error"); |
| 201 | throw runtime_error("unknown error"); |
| 202 | } |
| 203 | |
| 204 | string first_qubit = transformQubitFormat(qubits_vector.front()); |
| 205 | string all_qubits; |
| 206 | for (auto _val : qubits_vector) |
| 207 | { |
| 208 | all_qubits = all_qubits + transformQubitFormat(_val) + ","; |
| 209 | } |
| 210 | all_qubits = all_qubits.substr(0, all_qubits.length() - 1); |
| 211 | |
| 212 | string item = iter->second; |
| 213 | switch (iter->first) |
nothing calls this directly
no test coverage detected