20
20
#include < cstddef>
21
21
#include < cstdint>
22
22
#include < functional>
23
+ #include < iomanip>
24
+ #include < iostream>
23
25
#include < memory>
24
26
#include < ostream>
25
27
#include < stdexcept>
@@ -125,6 +127,28 @@ IfElseOperation& IfElseOperation::operator=(const IfElseOperation& op) {
125
127
return *this ;
126
128
}
127
129
130
+ std::ostream&
131
+ IfElseOperation::print (std::ostream& os, const Permutation& permutation,
132
+ [[maybe_unused]] const std::size_t prefixWidth,
133
+ const std::size_t nqubits) const {
134
+ if (thenOp) {
135
+ thenOp->print (os, permutation, prefixWidth, nqubits);
136
+ }
137
+
138
+ os << " " << " \033 [1m\033 [35m" ;
139
+ if (controlRegister.has_value ()) {
140
+ assert (!controlBit.has_value ());
141
+ os << controlRegister->getName () << " == " << expectedValueRegister;
142
+ }
143
+ if (controlBit.has_value ()) {
144
+ assert (!controlRegister.has_value ());
145
+ os << (expectedValueBit ? " !" : " " ) << " c[" << controlBit.value () << " ]" ;
146
+ }
147
+ os << " \033 [0m" ;
148
+
149
+ return os;
150
+ }
151
+
128
152
bool IfElseOperation::equals (const Operation& operation,
129
153
const Permutation& perm1,
130
154
const Permutation& perm2) const {
@@ -197,7 +221,9 @@ void IfElseOperation::dumpOpenQASM(std::ostream& of,
197
221
of << controlRegister->getName () << ' '
198
222
<< getInvertedComparisonKind (comparisonKind) << ' '
199
223
<< expectedValueRegister;
200
- } else if (controlBit.has_value ()) {
224
+ }
225
+ if (controlBit.has_value ()) {
226
+ assert (!controlRegister.has_value ());
201
227
of << (expectedValueBit ? " !" : " " ) << bitMap.at (*controlBit).second ;
202
228
}
203
229
of << " ) " ;
@@ -219,10 +245,12 @@ std::size_t std::hash<qc::IfElseOperation>::operator()(
219
245
qc::hashCombine (seed, std::hash<qc::Operation>{}(*op.getElseOp ()));
220
246
}
221
247
if (const auto & reg = op.getControlRegister (); reg.has_value ()) {
248
+ assert (!op.getControlBit ().has_value ());
222
249
qc::hashCombine (seed, std::hash<qc::ClassicalRegister>{}(reg.value ()));
223
250
qc::hashCombine (seed, op.getExpectedValueRegister ());
224
251
}
225
252
if (const auto & bit = op.getControlBit (); bit.has_value ()) {
253
+ assert (!op.getControlRegister ().has_value ());
226
254
qc::hashCombine (seed, bit.value ());
227
255
qc::hashCombine (seed, static_cast <std::size_t >(op.getExpectedValueBit ()));
228
256
}
0 commit comments