Sequential Quantum Gate Decomposer  v1.9.6
Powerful decomposition of general unitarias into one- and two-qubit gates gates
noisy_circuit.h
Go to the documentation of this file.
1 /*
2 Copyright 2025 SQUANDER Contributors
3 
4 Licensed under the Apache License, Version 2.0 (the "License");
5 you may not use this file except in compliance with the License.
6 You may obtain a copy of the License at
7 
8  http://www.apache.org/licenses/LICENSE-2.0
9 
10 Unless required by applicable law or agreed to in writing, software
11 distributed under the License is distributed on an "AS IS" BASIS,
12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 See the License for the specific language governing permissions and
14 limitations under the License.
15 */
16 
17 #pragma once
18 
19 #include "density_matrix.h"
20 #include "density_operation.h"
21 #include <memory>
22 #include <vector>
23 
24 // Forward declarations for gate types
25 class Gate;
26 class Gates_block;
27 
28 namespace squander {
29 namespace density {
30 
57 class NoisyCircuit {
58 public:
59  // ================================================================
60  // Constructors & Destructor
61  // ================================================================
62 
67  explicit NoisyCircuit(int qbit_num);
68 
72  ~NoisyCircuit();
73 
74  // Disable copy (operations own their resources)
75  NoisyCircuit(const NoisyCircuit &) = delete;
76  NoisyCircuit &operator=(const NoisyCircuit &) = delete;
77 
78  // Move semantics
79  NoisyCircuit(NoisyCircuit &&other) noexcept;
80  NoisyCircuit &operator=(NoisyCircuit &&other) noexcept;
81 
82  // ================================================================
83  // Single-Qubit Gates (constant - no parameters)
84  // ================================================================
85 
86  void add_H(int target);
87  void add_X(int target);
88  void add_Y(int target);
89  void add_Z(int target);
90  void add_S(int target);
91  void add_Sdg(int target);
92  void add_T(int target);
93  void add_Tdg(int target);
94  void add_SX(int target);
95 
96  // ================================================================
97  // Single-Qubit Parametric Gates
98  // ================================================================
99 
100  void add_RX(int target);
101  void add_RY(int target);
102  void add_RZ(int target);
103  void add_U1(int target);
104  void add_U2(int target);
105  void add_U3(int target);
106 
107  // ================================================================
108  // Two-Qubit Gates (constant)
109  // ================================================================
110 
111  void add_CNOT(int target, int control);
112  void add_CZ(int target, int control);
113  void add_CH(int target, int control);
114 
115  // ================================================================
116  // Two-Qubit Parametric Gates
117  // ================================================================
118 
119  void add_CRY(int target, int control);
120  void add_CRZ(int target, int control);
121  void add_CRX(int target, int control);
122  void add_CP(int target, int control);
123 
124  // ================================================================
125  // Noise Channel Addition
126  // ================================================================
127 
132  void add_depolarizing(int qbit_num);
133 
139  void add_depolarizing(int qbit_num, double error_rate);
140 
145  void add_local_depolarizing(int target);
146 
152  void add_local_depolarizing(int target, double error_rate);
153 
158  void add_amplitude_damping(int target);
159 
165  void add_amplitude_damping(int target, double gamma);
166 
171  void add_phase_damping(int target);
172 
178  void add_phase_damping(int target, double lambda);
179 
180  // ================================================================
181  // Circuit Execution
182  // ================================================================
183 
193  void apply_to(const double *params, int param_count, DensityMatrix &rho);
194 
198  void apply_to(const matrix_base<double> &params, DensityMatrix &rho);
199 
200  // ================================================================
201  // Properties
202  // ================================================================
203 
207  int get_qbit_num() const { return qbit_num_; }
208 
212  int get_parameter_num() const { return total_params_; }
213 
217  size_t get_operation_count() const { return operations_.size(); }
218 
219  // ================================================================
220  // Inspection
221  // ================================================================
222 
226  struct OperationInfo {
227  std::string name;
231  };
232 
236  std::vector<OperationInfo> get_operation_info() const;
237 
238 private:
240  std::vector<std::unique_ptr<IDensityOperation>> operations_;
241  std::vector<int> param_starts_;
242  int total_params_ = 0;
243 
244  // Helper to add an operation and update parameter tracking
245  void add_operation(std::unique_ptr<IDensityOperation> op);
246 
247  // Helper to add a gate by type
248  void add_gate_internal(Gate *gate);
249 };
250 
251 } // namespace density
252 } // namespace squander
void add_CZ(int target, int control)
void add_RZ(int target)
1 parameter
void add_CRZ(int target, int control)
1 parameter
void add_CNOT(int target, int control)
void add_local_depolarizing(int target)
Add parametric local single-qubit depolarizing noise (1 parameter)
NoisyCircuit & operator=(const NoisyCircuit &)=delete
void add_U2(int target)
2 parameters
void add_phase_damping(int target)
Add parametric phase damping noise (1 parameter)
void apply_to(const double *params, int param_count, DensityMatrix &rho)
Apply entire circuit to density matrix.
void add_U1(int target)
1 parameter
std::vector< OperationInfo > get_operation_info() const
Get information about all operations.
void add_CP(int target, int control)
1 parameter
void add_U3(int target)
3 parameters
int get_qbit_num() const
Get number of qubits.
NoisyCircuit(int qbit_num)
Create empty circuit for n qubits.
std::vector< std::unique_ptr< IDensityOperation > > operations_
void add_depolarizing(int qbit_num)
Add parametric depolarizing noise channel (1 parameter)
void add_CRY(int target, int control)
1 parameter
Quantum density matrix ρ for mixed-state representation.
int get_parameter_num() const
Get total number of parameters needed.
std::vector< int > param_starts_
void add_RY(int target)
1 parameter
Information about a circuit operation.
void add_CH(int target, int control)
size_t get_operation_count() const
Get number of operations in the circuit.
A class responsible for grouping two-qubit (CNOT,CZ,CH) and one-qubit gates into layers.
Definition: Gates_block.h:44
Base class for the representation of general gate operations.
Definition: Gate.h:86
void add_RX(int target)
1 parameter
void add_operation(std::unique_ptr< IDensityOperation > op)
void add_CRX(int target, int control)
1 parameter
Quantum circuit with noise for density matrix simulation.
Definition: noisy_circuit.h:57
void add_amplitude_damping(int target)
Add parametric amplitude damping noise (1 parameter)