Linopt
Linear optics circuit calculator
circuit.h
1 /* Copyright © 2018, 2019, Quantum Optical Technologies Laboratories
2  * <https://www.qotlabs.org/en/>
3  * Contributed by: Struchalin Gleb <struchalin.gleb@physics.msu.ru>
4  * Dyakonov Ivan <iv.dyakonov@physics.msu.ru>
5  *
6  * This file is part of Linopt.
7  *
8  * Linopt is free software: you can redistribute it and/or modify
9  * it under the terms of the GNU Lesser General Public License as published by
10  * the Free Software Foundation, either version 3 of the License, or
11  * (at your option) any later version.
12  *
13  * Linopt is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public License
19  * along with Linopt. If not, see <https://www.gnu.org/licenses/>.
20  */
21 
22 #ifndef CIRCUIT_H
23 #define CIRCUIT_H
24 
25 #include "states.h"
26 #include "matrix.h"
27 
28 namespace linopt
29 {
30 
31 class Circuit
32 {
33 public:
34  const State &getInputState() const;
35  void setInputState(const State &s);
36  const Basis getOutputBasis() const;
37  void setOutputBasis(const Basis &bout);
38  const Matrix &getUnitary() const;
39  void setUnitary(const Matrix &U);
40  template<typename ExecPolicy = execution::Seq>
41  const State &outputState();
42 
43 private:
44  State inputState;
45  Matrix unitary;
46  State outputState_;
47 
48  // Indicates whether variable `outputState_` is valid
49  bool outputStateValid = true;
50 
51  // Cache struct for `calcFockAmp1()`
52  struct UinFin
53  {
54  Matrix Uin;
55  int tot;
56  Complex mult;
57  };
58 
59  static void copyColumnsOnInput(Matrix &Ucc, const Matrix &U, const Fock &fin);
60  static void copyRowsOnOutput(Matrix &Ucr, const Matrix &Uin, const Fock &fout);
61  // Calculates amplitude corresponding to the output Fock state `fout`
62  Complex calcFockAmp(const Fock &fout) const;
63  // Optimized version of `calcFockAmp()` when `inputState` has size = 1
64  Complex calcFockAmp1(const UinFin &precomputed, const Fock &fout) const;
65 };
66 
67 } // Namespace linopt
68 
69 #endif // CIRCUIT_H
The class representing a linear optical state.
Definition: states.h:236
The main namespace containing all library classes, functions, etc.
Definition: circuit.h:28
Definition: circuit.h:31
The class representing a Fock state.
Definition: states.h:56
The class representing a collection of Fock states.
Definition: states.h:181