XACC
exception.h
Go to the documentation of this file.
1 /*
2  * This file is part of Quantum++.
3  *
4  * MIT License
5  *
6  * Copyright (c) 2013 - 2020 Vlad Gheorghiu.
7  *
8  * Permission is hereby granted, free of charge, to any person obtaining a copy
9  * of this software and associated documentation files (the "Software"), to deal
10  * in the Software without restriction, including without limitation the rights
11  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12  * copies of the Software, and to permit persons to whom the Software is
13  * furnished to do so, subject to the following conditions:
14  *
15  * The above copyright notice and this permission notice shall be included in
16  * all copies or substantial portions of the Software.
17  *
18  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24  * SOFTWARE.
25  */
26 
32 #ifndef CLASSES_EXCEPTION1_H_
33 #define CLASSES_EXCEPTION1_H_
34 
35 namespace qpp {
40 namespace exception {
71 class Exception : public std::exception {
72  private:
73  std::string where_;
74  mutable std::string msg_;
75 
76  public:
82  explicit Exception(const std::string& where) : where_{where}, msg_{} {}
83 
89  const char* what() const noexcept override {
90  msg_.clear();
91  msg_ += "In ";
92  msg_ += where_;
93  msg_ += ": ";
94  msg_ += description();
95  msg_ += "!";
96 
97  return msg_.c_str();
98  }
99 
105  virtual std::string description() const = 0;
106 }; /* class Exception */
107 
108 inline std::string Exception::description() const {
109  return "qpp::exception::Exception";
110 }
111 
119 class Unknown : public Exception {
120  public:
121  std::string description() const override { return "UNKNOWN EXCEPTION"; }
122 
123  using Exception::Exception;
124 };
125 
132 class ZeroSize : public Exception {
133  public:
134  std::string description() const override { return "Object has zero size"; }
135 
136  using Exception::Exception;
137 };
138 
145 class MatrixNotSquare : public Exception {
146  public:
147  std::string description() const override { return "Matrix is not square"; }
148 
149  using Exception::Exception;
150 };
151 
158 class MatrixNotCvector : public Exception {
159  public:
160  std::string description() const override {
161  return "Matrix is not a column vector";
162  }
163 
164  using Exception::Exception;
165 };
166 
173 class MatrixNotRvector : public Exception {
174  public:
175  std::string description() const override {
176  return "Matrix is not a row vector";
177  }
178 
179  using Exception::Exception;
180 };
181 
188 class MatrixNotVector : public Exception {
189  public:
190  std::string description() const override {
191  return "Matrix is not a vector";
192  }
193 
194  using Exception::Exception;
195 };
196 
203 class MatrixNotSquareNorCvector : public Exception {
204  public:
205  std::string description() const override {
206  return "Matrix is not square nor column vector";
207  }
208 
209  using Exception::Exception;
210 };
211 
218 class MatrixNotSquareNorRvector : public Exception {
219  public:
220  std::string description() const override {
221  return "Matrix is not square nor row vector";
222  }
223 
224  using Exception::Exception;
225 };
226 
233 class MatrixNotSquareNorVector : public Exception {
234  public:
235  std::string description() const override {
236  return "Matrix is not square nor vector";
237  }
238 
239  using Exception::Exception;
240 };
241 
248 class MatrixMismatchSubsys : public Exception {
249  public:
250  std::string description() const override {
251  return "Matrix mismatch subsystems";
252  }
253 
254  using Exception::Exception;
255 };
256 
263 class DimsInvalid : public Exception {
264  public:
265  std::string description() const override { return "Invalid dimension(s)"; }
266 
267  using Exception::Exception;
268 };
269 
276 class DimsNotEqual : public Exception {
277  public:
278  std::string description() const override { return "Dimensions not equal"; }
279 
280  using Exception::Exception;
281 };
282 
290 class DimsMismatchMatrix : public Exception {
291  public:
292  std::string description() const override {
293  return "Dimension(s) mismatch matrix size";
294  }
295 
296  using Exception::Exception;
297 };
298 
306 class DimsMismatchCvector : public Exception {
307  public:
308  std::string description() const override {
309  return "Dimension(s) mismatch column vector size";
310  }
311 
312  using Exception::Exception;
313 };
314 
322 class DimsMismatchRvector : public Exception {
323  public:
324  std::string description() const override {
325  return "Dimension(s) mismatch row vector size";
326  }
327 
328  using Exception::Exception;
329 };
330 
339 class DimsMismatchVector : public Exception {
340  public:
341  std::string description() const override {
342  return "Dimension(s) mismatch vector size";
343  }
344 
345  using Exception::Exception;
346 };
347 
355 class SubsysMismatchDims : public Exception {
356  public:
357  std::string description() const override {
358  return "Subsystems mismatch dimensions";
359  }
360 
361  using Exception::Exception;
362 };
363 
370 class PermInvalid : public Exception {
371  public:
372  std::string description() const override { return "Invalid permutation"; }
373 
374  using Exception::Exception;
375 };
376 
384 class PermMismatchDims : public Exception {
385  public:
386  std::string description() const override {
387  return "Permutation mismatch dimensions";
388  }
389 
390  using Exception::Exception;
391 };
392 
399 class NotQubitMatrix : public Exception {
400  public:
401  std::string description() const override { return "Matrix is not 2 x 2"; }
402 
403  using Exception::Exception;
404 };
405 
412 class NotQubitCvector : public Exception {
413  public:
414  std::string description() const override {
415  return "Column vector is not 2 x 1";
416  }
417 
418  using Exception::Exception;
419 };
420 
427 class NotQubitRvector : public Exception {
428  public:
429  std::string description() const override {
430  return "Row vector is not 1 x 2";
431  }
432 
433  using Exception::Exception;
434 };
435 
442 class NotQubitVector : public Exception {
443  public:
444  std::string description() const override {
445  return "Vector is not 2 x 1 nor 1 x 2";
446  }
447 
448  using Exception::Exception;
449 };
450 
457 class NotQubitSubsys : public Exception {
458  public:
459  std::string description() const override {
460  return "Subsystems are not qubits";
461  }
462 
463  using Exception::Exception;
464 };
465 
472 class NotBipartite : public Exception {
473  public:
474  std::string description() const override { return "Not bi-partite"; }
475 
476  using Exception::Exception;
477 };
478 
486 class NoCodeword : public Exception {
487  public:
488  std::string description() const override {
489  return "Codeword does not exist";
490  }
491 
492  using Exception::Exception;
493 };
494 
501 class OutOfRange : public Exception {
502  public:
503  std::string description() const override { return "Argument out of range"; }
504 
505  using Exception::Exception;
506 };
507 
514 class TypeMismatch : public Exception {
515  public:
516  std::string description() const override { return "Type mismatch"; }
517 
518  using Exception::Exception;
519 };
520 
527 class SizeMismatch : public Exception {
528  public:
529  std::string description() const override { return "Size mismatch"; }
530 
531  using Exception::Exception;
532 };
533 
540 class UndefinedType : public Exception {
541  public:
542  std::string description() const override {
543  return "Not defined for this type";
544  }
545 
546  using Exception::Exception;
547 };
548 
555 class QuditAlreadyMeasured : public Exception {
556  public:
557  std::string description() const override {
558  return "Qudit was already measured (destructively)";
559  }
560 
561  using Exception::Exception;
562 };
563 
571 class Duplicates : public Exception {
572  public:
573  std::string description() const override {
574  return "System (e.g. std::vector) contains duplicates";
575  }
576 
577  using Exception::Exception;
578 };
579 
586 class CustomException : public Exception {
587  std::string what_{};
588 
589  std::string description() const override {
590  return "CUSTOM EXCEPTION " + what_;
591  }
592 
593  public:
594  CustomException(const std::string& where, const std::string& what)
595  : Exception{where}, what_{what} {}
596 };
597 
602 class NotImplemented : public Exception {
603  public:
604  std::string description() const override { return "Not yet implemented"; }
605 
606  using Exception::Exception;
607 };
608 
613 class InvalidIterator : public Exception {
614  public:
615  std::string description() const override { return "Invalid iterator"; }
616 
617  using Exception::Exception;
618 };
619 
624 class FileNotFound : public Exception {
625  public:
626  std::string description() const override { return "File not found"; }
627 
628  using Exception::Exception;
629 };
630 
635 class LexicalError : public Exception {
636  public:
637  std::string description() const override { return "Lexical error"; }
638 
639  using Exception::Exception;
640 };
641 
646 class ParseError : public Exception {
647  public:
648  std::string description() const override { return "Parse error"; }
649 
650  using Exception::Exception;
651 };
652 
657 class SemanticError : public Exception {
658  public:
659  std::string description() const override { return "Semantic error"; }
660 
661  using Exception::Exception;
662 };
663 
668 class Undeclared : public Exception {
669  public:
670  std::string description() const override { return "Undeclared variable"; }
671 
672  using Exception::Exception;
673 };
674 
675 } /* namespace exception */
676 } /* namespace qpp */
677 
678 #endif /* CLASSES_EXCEPTION1_H_ */
Quantum++ main namespace.
Definition: circuits.h:35