Sequential Quantum Gate Decomposer  v1.9.6
Powerful decomposition of general unitarias into one- and two-qubit gates gates
Variational_Quantum_Eigensolver_Base.h
Go to the documentation of this file.
1 /*
2 Created on Fri Jun 26 14:13:26 2020
3 Copyright 2020 Peter Rakyta, Ph.D.
4 
5 Licensed under the Apache License, Version 2.0 (the "License");
6 you may not use this file except in compliance with the License.
7 You may obtain a copy of the License at
8 
9  http://www.apache.org/licenses/LICENSE-2.0
10 
11 Unless required by applicable law or agreed to in writing, software
12 distributed under the License is distributed on an "AS IS" BASIS,
13 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 See the License for the specific language governing permissions and
15 limitations under the License.
16 
17 @author: Peter Rakyta, Ph.D.
18 */
23 #ifndef VARIATIONAL_QUANTUM_EIGENSOLVER_BASE_H
24 #define VARIATIONAL_QUANTUM_EIGENSOLVER_BASE_H
25 
26 #include "Optimization_Interface.h"
27 
28 namespace squander {
29 namespace density {
30 class DensityMatrix;
31 class NoisyCircuit;
32 } // namespace density
33 } // namespace squander
34 
35 //=====================================================================================================================================================================================
36 //=====================================================================================================================================================================================
37 //=====================================================================================================================================================================================
38 
39 // --- SimulationResult struct ---
55  double mean;
56  double variance;
57  double std_error;
58 };
59 //=====================================================================================================================================================================================
60 //=====================================================================================================================================================================================
61 //=====================================================================================================================================================================================
62 
64 typedef enum ansatz_type { HEA, HEA_ZYZ } ansatz_type;
65 
67 typedef enum vqe_backend_type {
71 
73 typedef enum density_noise_type {
78 
87 
93  double value;
94 };
95 
98  std::string name;
99  bool is_unitary;
106  double fixed_value;
107 };
108 
115 public:
116  //================================================================================================================================================================================
117  //================================================================================================================================================================================
118  //================================================================================================================================================================================
119 
126  Matrix get_initial_state() const { return initial_state.copy(); }
127 
129  std::string get_density_bridge_source_label() const;
130 
138  std::vector<DensityBridgeOperationInfo> inspect_density_bridge();
139  //================================================================================================================================================================================
140  //================================================================================================================================================================================
141  //================================================================================================================================================================================
142 
143 private:
146 
149 
152 
155 
158 
160  std::vector<DensityNoiseSpec> density_noise_specs;
161 
162  void validate_density_anchor_support(bool require_optimizer_support = false,
163  bool require_gradient_support = false);
164  void
165  append_density_noise_for_gate_index(squander::density::NoisyCircuit &circuit,
166  int gate_index) const;
167  void lower_anchor_circuit_to_noisy_circuit(
169  double evaluate_density_matrix_backend(Matrix_real &parameters);
170  double expectation_value_of_density_energy_real(
171  const squander::density::DensityMatrix &rho) const;
172  bool density_optimizer_supported() const;
173 
174 public:
175  //================================================================================================================================================================================
176  //================================================================================================================================================================================
177  //================================================================================================================================================================================
178 
194  std::vector<std::tuple<int, int, double>> zz_terms;
196 
198  std::vector<std::pair<int, double>> z_terms;
199 
201  std::vector<std::tuple<int, int, double>> xx_terms;
202 
204  std::vector<std::tuple<int, int, double>> yy_terms;
205 
206  //================================================================================================================================================================================
207  //================================================================================================================================================================================
208  //================================================================================================================================================================================
209 
215 
225  Matrix_sparse Hamiltonian_in, int qbit_num_in,
226  std::map<std::string, Config_Element> &config_in,
227  int accelerator_num = 0);
228 
233 
244  QGD_Complex16 Expectation_value_of_energy(Matrix &State_left,
245  Matrix &State_right);
246 
257  double Expectation_value_of_energy_real(Matrix &State_left,
258  Matrix &State_right);
259 
260  //=====================================================================================================================================================================================
261  //=====================================================================================================================================================================================
262  //=====================================================================================================================================================================================
263 
274  SimulationResult Expectation_value_with_shot_noise_real(Matrix &State,
275  int shots,
276  uint64_t seed,
277  double p_readout);
278 
279  //=====================================================================================================================================================================================
280  //=====================================================================================================================================================================================
281  //=====================================================================================================================================================================================
282 
290  virtual double optimization_problem(Matrix_real &parameters) override;
291 
299  virtual double optimization_problem_non_static(Matrix_real parameters,
300  void *void_instance) override;
301 
302 #ifdef __GROQ__
303 
311  double optimization_problem_Groq(Matrix_real &parameters, int chosen_device);
312 #endif
313 
322 
330  double optimization_problem(double *parameters);
331 
341  virtual void
342  optimization_problem_combined_non_static(Matrix_real parameters,
343  void *void_instance, double *f0,
344  Matrix_real &grad) override;
345 
353  virtual void optimization_problem_combined(Matrix_real parameters, double *f0,
354  Matrix_real grad) override;
355 
364  static void optimization_problem_grad_vqe(Matrix_real parameters,
365  void *void_instance,
366  Matrix_real &grad);
367 
372  void initialize_zero_state();
373 
378  void start_optimization();
379 
385  void set_ansatz(ansatz_type ansatz_in);
386 
393  void generate_circuit(int layers, int inner_blocks);
394 
400  void set_gate_structure(std::string filename);
401 
406  void set_custom_gate_structure(Gates_block *gate_structure_in);
407 
413  void set_initial_state(Matrix initial_state_in);
414 
419  void set_density_noise_specs(
420  const std::vector<DensityNoiseSpec> &density_noise_specs_in);
421 };
422 
423 #endif
int shots
Definition: noise.py:65
ansatz_type ansatz
Ansatz type (HEA stands for hardware efficient ansatz)
vqe_circuit_source_type circuit_source
Provenance of the currently configured circuit.
ansatz_type
Type definition of the fifferent types of ansatz.
std::vector< std::tuple< int, int, double > > yy_terms
Coupling terms of the form coeff * Y_i * Y_j.
std::vector< std::pair< int, double > > z_terms
Local magnetic field terms of the form coeff * Z_i.
Reviewable metadata describing one lowered density-bridge operation.
vqe_backend_type
Supported execution backends for the VQE workflow contract.
Class to store data of complex arrays and its properties.
Definition: matrix_sparse.h:38
Matrix initial_state
Quantum state used as an initial state in the VQE iterations.
vqe_backend_type backend_mode
Effective execution backend selected for this VQE instance.
ansatz_type
Type definition of the fifferent types of ansatz.
A base class to determine the decomposition of an N-qubit unitary into a sequence of CNOT and U3 gate...
Quantum density matrix ρ for mixed-state representation.
Container for statistics returned by shot-noise simulations.
density_noise_type
Supported local noise channels.
Structure type representing complex numbers in the SQUANDER package.
Definition: QGDTypes.h:38
A base class to solve VQE problems This class can be used to approximate the ground state of the inpu...
Double-precision complex matrix (float64).
Definition: matrix.h:38
A class responsible for grouping two-qubit (CNOT,CZ,CH) and one-qubit gates into layers.
Definition: Gates_block.h:44
Matrix_sparse Hamiltonian
The Hamiltonian of the system.
Matrix get_initial_state() const
Return a copy of the stored initial state used for VQE runs.
std::vector< std::tuple< int, int, double > > xx_terms
Coupling terms of the form coeff * X_i * X_j.
Ordered fixed-noise insertion metadata.
vqe_circuit_source_type
Provenance of the active VQE circuit used for backend validation.
std::vector< DensityNoiseSpec > density_noise_specs
Ordered fixed local-noise insertions for the density backend.
Quantum circuit with noise for density matrix simulation.
Definition: noisy_circuit.h:57
Class to store data of complex arrays and its properties.
Definition: matrix_real.h:41
virtual double optimization_problem(const double *parameters)
This is an abstact definition of function giving the cost functions measuring the entaglement of the ...