30 indices_.push_back( static_cast<size_t> (index) );
36 for (
int index = index_min; index <= index_max; ++index)
37 indices_.push_back( static_cast<size_t> (index) );
58 std::cout <<
"Indices: ";
61 std::cout << elems <<
" ";
63 std::cout << std::endl;
80 selected_qubits_ = indices;
85 return selected_qubits_;
90 std::cout <<
"Selected Qubits - ";
91 getSelectedQubits().printMembers();
108 selected_bits_ = indices;
113 return selected_bits_;
118 std::cout <<
"Selected Bits - ";
119 getSelectedBits().printMembers();
130 : qubits_ (qubits_involved),
131 rotation_angle_ (
std::numeric_limits<double>::max()), bit_controlled_(false)
134 type_ = toLowerCase(type);
137 Operation(
const std::string type,
Qubits qubits_involved,
const double rotation_angle)
138 : qubits_ (qubits_involved),
139 rotation_angle_ (rotation_angle), bit_controlled_(false)
142 type_ = toLowerCase(type);
146 : rotation_angle_ (
std::numeric_limits<double>::max()), bit_controlled_(false)
149 type_ = toLowerCase(type);
150 measure_parity_qubits_ = std::pair<Qubits,Qubits> (qubit_pair1,qubit_pair2);
151 measure_parity_axis_ = std::pair<std::string,std::string> (toLowerCase(axis1),toLowerCase(axis2));
155 : rotation_angle_ (
std::numeric_limits<double>::max()), bit_controlled_(false)
158 type_ = toLowerCase(type);
159 all_qubits_bits_ =
true;
163 : rotation_angle_ (
std::numeric_limits<double>::max()), bit_controlled_(false)
166 type_ = toLowerCase(type);
167 wait_time_ = waitInt;
171 : rotation_angle_ (
std::numeric_limits<double>::max()), bit_controlled_(false)
174 type_ = toLowerCase(type);
175 bits_ = display_bits;
179 : rotation_angle_ (
std::numeric_limits<double>::max()), bit_controlled_(false)
182 type_ = toLowerCase(type);
183 two_qubit_pairs_ = std::pair<Qubits,Qubits> (qubit_pair1,qubit_pair2);
187 : rotation_angle_ (rotations), bit_controlled_(false)
190 type_ = toLowerCase(type);
191 two_qubit_pairs_ = std::pair<Qubits,Qubits> (qubit_pair1,qubit_pair2);
195 : rotation_angle_ (
std::numeric_limits<double>::max()), bit_controlled_(false)
198 type_ = toLowerCase(type);
199 toffoli_qubit_pairs_ = std::pair<Qubits, std::pair<Qubits,Qubits>> (
201 std::pair<Qubits,Qubits> (qubit_pair2,qubit_pair3)
205 Operation(
const std::string type,
const std::string state_filename)
206 : rotation_angle_ (
std::numeric_limits<double>::max()), bit_controlled_(false)
209 type_ = toLowerCase(type);
210 state_filename_ = removeQuotes(state_filename);
220 return state_filename_;
230 if (type_ ==
"toffoli")
232 switch (qubit_pair_index) {
233 case 1:
return toffoli_qubit_pairs_.first;
break;
234 case 2:
return toffoli_qubit_pairs_.second.first;
break;
235 case 3:
return toffoli_qubit_pairs_.second.second;
break;
236 default:
throw std::runtime_error( std::string(
"Accessing qubit pair ")
237 + std::to_string(qubit_pair_index)
238 + std::string(
" on operation ") + type_ );
return qubits_;
241 else if (type_ ==
"cnot" || type_ ==
"cz" || type_ ==
"swap" || type_ ==
"cr" || type_ ==
"crk")
243 switch(qubit_pair_index){
244 case 1:
return two_qubit_pairs_.first;
break;
245 case 2:
return two_qubit_pairs_.second;
break;
246 default:
throw std::runtime_error( std::string(
"Accessing qubit pair ")
247 + std::to_string(qubit_pair_index)
248 + std::string(
" on operation ") + type_ );
return qubits_;
253 throw std::runtime_error( std::string(
"Accessing qubit pair ")
254 + std::to_string(qubit_pair_index)
255 + std::string(
" on operation ") + type_ );
262 return rotation_angle_;
267 std::pair< std::pair<Qubits,Qubits>, std::pair<std::string,std::string> > pair_result (measure_parity_qubits_, measure_parity_axis_);
273 return two_qubit_pairs_;
278 return toffoli_qubit_pairs_;
283 return bit_controlled_;
288 return all_qubits_bits_;
293 bits_ = control_bits;
294 bit_controlled_ =
true;
314 unitary_matrix_elements_ = input;
319 return unitary_matrix_elements_;
324 std::cout <<
"Operation " << type_ <<
": ";
325 if ( type_ ==
"rx" || type_ ==
"ry" || type_ ==
"rz" )
327 getQubitsInvolved().printMembers();
328 std::cout <<
"Rotations = " << getRotationAngle() << std::endl;
330 else if (type_ ==
"measure_parity")
332 std::cout << std::endl;
333 auto measureParityProperties = getMeasureParityQubitsAndAxis();
334 measureParityProperties.first.first.printMembers();
335 std::cout <<
"With axis " << measureParityProperties.second.first << std::endl;
336 measureParityProperties.first.second.printMembers();
337 std::cout <<
"With axis " << measureParityProperties.second.second << std::endl;
339 else if (type_ ==
"cnot" || type_ ==
"cz" || type_ ==
"swap")
341 std::cout << std::endl;
342 std::cout <<
"Qubit Pair 1: ";
343 getTwoQubitPairs().first.printMembers();
344 std::cout <<
"Qubit Pair 2: ";
345 getTwoQubitPairs().second.printMembers();
347 else if (type_ ==
"cr")
349 std::cout << std::endl;
350 std::cout <<
"Qubit Pair 1: ";
351 getTwoQubitPairs().first.printMembers();
352 std::cout <<
"Qubit Pair 2: ";
353 getTwoQubitPairs().second.printMembers();
354 std::cout <<
"Rotation = " << getRotationAngle() << std::endl;
356 else if (type_ ==
"toffoli")
358 std::cout << std::endl;
359 std::cout <<
"Qubit Pair 1: ";
360 getToffoliQubitPairs().first.printMembers();
361 std::cout <<
"Qubit Pair 2: ";
362 getToffoliQubitPairs().second.first.printMembers();
363 std::cout <<
"Qubit Pair 3: ";
364 getToffoliQubitPairs().second.second.printMembers();
366 else if (type_ ==
"skip")
368 std::cout << std::endl;
369 std::cout <<
"Wait time (integer) = " << getWaitTime() << std::endl;
371 else if (type_ ==
"wait")
373 std::cout << std::endl;
374 std::cout <<
"Wait time (integer) = " << getWaitTime() << std::endl;
376 else if ( (type_ ==
"display") || (type_ ==
"display_binary") )
378 std::cout <<
"Display bits: ";
379 getDisplayBits().printMembers();
381 else getQubitsInvolved().printMembers();
383 if (isBitControlled()){
384 std::cout <<
"Bit controlled with bits: ";
385 getControlBits().printMembers();
393 std::string lower_case_input = string_input;
394 std::transform(lower_case_input.begin(), lower_case_input.end(), lower_case_input.begin(), ::tolower);
395 return lower_case_input;
400 std::string result = string_input;
401 result.erase(result.begin());
402 result.erase(result.end()-1);
412 bool all_qubits_bits_ =
false;
432 operations_.push_back(valid_op);
434 linenumber_ = linenumber;
439 return operations_.back();
444 operations_.push_back(valid_op);
449 operations_.push_back(valid_op);
465 linenumber_ = linenumber;
477 std::cout <<
"Parallel operations cluster: " << std::endl;
478 for (
auto elem : getOperations())
479 elem -> printOperation();
480 std::cout <<
"End Parallel operations \n" << std::endl;
484 std::cout <<
"Serial operation: " << std::endl;
485 for (
auto elem : getOperations())
486 elem -> printOperation();
487 std::cout <<
"End Serial operation \n" << std::endl;
506 SubCircuit(
const char* name,
const int subcircuit_number,
const int linenumber):
507 name_ (
std::string(name) ),
508 number_iterations_ ( 1 ),
509 subcircuit_number_ ( subcircuit_number ),
510 linenumber_ (linenumber)
516 return number_iterations_;
521 number_iterations_ = iterations;
531 return subcircuit_number_;
541 operations_cluster_.push_back(opclus);
546 return operations_cluster_.back();
551 return operations_cluster_;
556 std::cout <<
"Subcircuit Name = " << nameSubCircuit() <<
" , Rank = " << rankSubCircuit() << std::endl;
557 std::cout << nameSubCircuit() <<
" has " << numberIterations() <<
" iterations." << std::endl;
558 std::cout <<
"Contains these operations clusters:" << std::endl;
559 for (
auto elem : getOperationsCluster())
560 elem->printOperations();
561 std::cout <<
"End of subcircuit " << nameSubCircuit() << std::endl << std::endl;
579 subcircuits_.push_back ( default_circuit );
584 subcircuits_.push_back(subcircuit);
589 return subcircuits_.size();
594 return subcircuits_.back();
614 std::vector<double> default_param(1, 0.);
615 setErrorModel(
"None", default_param);
620 qubit_register_ = participating_number;
625 return qubit_register_;
630 return version_number_;
635 version_number_ = version;
646 std::transform(name_key.begin(), name_key.end(), name_key.begin(), ::tolower);
648 std::pair<NumericalIdentifiers, bool> map_value (indices, isQubit);
649 mappings_[name_key] = map_value;
655 std::transform(name_key.begin(), name_key.end(), name_key.begin(), ::tolower);
657 if (mappings_.find(name_key) != mappings_.end() &&
658 mappings_.find(name_key)->second.second == isQubit)
659 return mappings_.find(name_key)->second.first;
661 throw std::runtime_error(std::string(
"Could not get wanted mapping ") +
662 name_key +
": Line " + std::to_string(linenumber));
665 void setErrorModel(std::string error_model_type, std::vector<double> error_model_num_params)
667 error_model_.first = error_model_type;
668 error_model_.second = error_model_num_params;
673 return error_model_.first;
678 return error_model_.second;
684 for (
auto elem : mappings_)
686 std::cout << elem.first <<
": ";
687 elem.second.first.printMembers(); std::cout << elem.second.second << std::endl;
695 std::cout <<
"Current error model: " << error_model_.first
696 <<
"\nError Probability = " ;
697 for (
auto i : getErrorModelParameters()){
698 std::cout << i << std::endl;
706 std::map< std::string , std::pair<NumericalIdentifiers,bool> >
mappings_;
const Bits & getControlBits() const
OperationsCluster * lastOperationsCluster()
double getRotationAngle() const
void versionNumber(double version)
std::pair< Qubits, Qubits > measure_parity_qubits_
void qubitRegister(int participating_number)
std::vector< SubCircuit > subcircuits_
std::string toLowerCase(const std::string &string_input)
void printErrorModel() const
SubCircuits & getSubCircuits()
std::string state_filename_
void addMappings(std::string name_key, NumericalIdentifiers indices, bool isQubit)
Bits(NumericalIdentifiers indices)
void setErrorModel(std::string error_model_type, std::vector< double > error_model_num_params)
bool isBitControlled() const
Operation(const std::string type, Qubits qubit_pair1, std::string axis1, Qubits qubit_pair2, std::string axis2)
Qubits(NumericalIdentifiers indices)
void printOperation() const
SubCircuit & lastSubCircuit()
NumericalIdentifiers()=default
size_t subcircuit_number_
void printMappings() const
const std::pair< Qubits, std::pair< Qubits, Qubits > > & getToffoliQubitPairs() const
const Qubits & getQubitsInvolved(const int qubit_pair_index) const
Operation(const std::string type, Qubits qubits_involved)
const NumericalIdentifiers & getSelectedQubits() const
void addToVector(const int index)
OperationsCluster(Operation *valid_op, int linenumber)
std::pair< std::string, std::vector< double > > error_model_
const Qubits & getQubitsInvolved() const
const std::vector< SubCircuit > & getAllSubCircuits() const
Operation(const std::string type, Qubits qubit_pair1, Qubits qubit_pair2)
Operation(const std::string type, Qubits qubits_involved, const double rotation_angle)
Operation(const std::string type, Qubits qubit_pair1, Qubits qubit_pair2, double rotations)
const NumericalIdentifiers & getSelectedBits() const
void printMembers() const
int getLineNumber() const
int getLineNumber() const
std::vector< Operation * > operations_
const std::vector< OperationsCluster * > & getOperationsCluster() const
const std::string & nameSubCircuit() const
size_t rankSubCircuit() const
std::string removeQuotes(const std::string &string_input)
void addToVector(const int index_min, const int index_max)
const std::pair< std::pair< Qubits, Qubits >, std::pair< std::string, std::string > > getMeasureParityQubitsAndAxis() const
Namespace used for most of the original API.
Operation(const std::string type, const std::string state_filename)
const std::string getErrorModelType() const
std::vector< OperationsCluster * > operations_cluster_
Operation(const std::string type, Qubits qubit_pair1, Qubits qubit_pair2, Qubits qubit_pair3)
Operation(const std::string type)
std::vector< size_t > indices_
std::string getType() const
const std::pair< Qubits, Qubits > & getTwoQubitPairs() const
std::map< std::string, std::pair< NumericalIdentifiers, bool > > mappings_
void setSelectedQubits(NumericalIdentifiers indices)
std::string getStateFilename() const
const Bits & getDisplayBits() const
double versionNumber() const
Operation(const std::string type, const int waitInt)
void setSelectedBits(NumericalIdentifiers indices)
size_t numberOfSubCircuits() const
Operation * lastOperation()
NumericalIdentifiers selected_bits_
const std::vector< double > & getUMatrixElements() const
const std::vector< Operation * > & getOperations() const
std::pair< Qubits, std::pair< Qubits, Qubits > > toffoli_qubit_pairs_
NumericalIdentifiers selected_qubits_
void printMembers() const
void addParallelOperation(Operation *valid_op)
std::pair< std::string, std::string > measure_parity_axis_
std::vector< double > getErrorModelParameters() const
void addOperation(Operation *valid_op)
std::vector< double > unitary_matrix_elements_
void addOperationsCluster(OperationsCluster *opclus)
void setLineNumber(int linenumber)
std::pair< Qubits, Qubits > two_qubit_pairs_
bool allQubitsBits() const
void addSubCircuit(SubCircuit subcircuit)
void setUMatrixElements(const std::vector< double > input)
const NumericalIdentifiers & getMappedIndices(std::string name_key, bool isQubit, int linenumber) const
SubCircuit(const char *name, const int subcircuit_number, const int linenumber)
const std::vector< size_t > & getIndices() const
void setControlBits(Bits control_bits)
void printMembers() const
void printMembers() const
Operation(const std::string type, const Bits display_bits)
int numberIterations() const
void numberIterations(int iterations)