Quandary
Loading...
Searching...
No Matches
oscillator.hpp
Go to the documentation of this file.
1#include <stdio.h>
2#include "defs.hpp"
3#include "controlbasis.hpp"
4#include <fstream>
5#include <iostream>
6#include <iomanip>
7#include <petscmat.h>
8#include <vector>
9#include <assert.h>
10#include "util.hpp"
11#include "config.hpp"
12#include <stdlib.h>
13#include<random>
14
15#pragma once
16
38 protected:
39 int myid;
40 size_t nlevels;
41 double ground_freq;
42 double selfkerr;
43
46 double decay_time;
47 double dephase_time;
48
49 std::vector<double> params;
50 double Tfinal;
51 std::vector<ControlBasis *> basisfunctions;
52 std::vector<double> carrier_freq;
53
57 PetscInt localsize_u;
58 PetscInt ilow;
59 PetscInt iupp;
60
62
63 public:
64 PetscInt dim_preOsc;
65 PetscInt dim_postOsc;
66
67 Oscillator();
68
78 Oscillator(const Config& config, size_t id, std::mt19937 rand_engine, int param_offset, bool quietmode);
79
80 virtual ~Oscillator();
81
87 size_t getNParams() { return params.size(); };
88
94 size_t getNLevels() { return nlevels; };
95
101 double getSelfkerr() { return selfkerr; };
102
108 double getDetuning() { return detuning_freq; };
109
115 double getDecayTime() {return decay_time; };
116
122 double getDephaseTime() {return dephase_time; };
123
129 size_t getNParameterizations() {return basisfunctions.size(); };
130
136 size_t getNCarrierfrequencies() {return carrier_freq.size(); };
137
143 ControlType getControlType() {return basisfunctions[0]->getType(); };
144
150 int getNSplines() {return basisfunctions[0]->getNSplines();};
151
157 double getRotFreq() {return (ground_freq - detuning_freq) / (2.0*M_PI); };
158
165 int getNSegParams(int parameterizationID);
166
172 void setParams(const double* x);
173
179 void getParams(double* x);
180
186 void clearParams() { params.clear(); };
187
198 int evalControl(const double t, double* Re_ptr, double* Im_ptr);
199
209 int evalControl_diff(const double t, double* grad_for_this_oscillator, const double pbar, const double qbar);
210
218 int evalControl_Labframe(const double t, double* f_ptr);
219
228 double expectedEnergy(const Vec x);
229
237 void expectedEnergy_diff(const Vec x, Vec x_bar, const double obj_bar);
238
247 void population(const Vec x, std::vector<double> &pop);
248
256 double evalControlVariation();
257
265 void evalControlVariationDiff(Vec G, double var_reg_bar, int skip_to_oscillator);
266};
267
268
269
Configuration class containing all validated settings.
Definition config.hpp:57
Quantum oscillator (multi-level qubit) with control capabilities.
Definition oscillator.hpp:37
int mpisize_petsc
Size of PETSc's communicator.
Definition oscillator.hpp:56
double getDephaseTime()
Retrieves the T2 dephasing time.
Definition oscillator.hpp:122
double getSelfkerr()
Retrieves the self-Kerr coefficient.
Definition oscillator.hpp:101
PetscInt iupp
Last index (+1) of the local sub vector u,v.
Definition oscillator.hpp:59
virtual ~Oscillator()
Definition oscillator.cpp:170
double expectedEnergy(const Vec x)
Computes expected energy for this oscillator.
Definition oscillator.cpp:355
double evalControlVariation()
Evaluates control variation penalty term.
Definition oscillator.cpp:200
double getRotFreq()
Retrieves the rotating frame frequency.
Definition oscillator.hpp:157
int getNSegParams(int parameterizationID)
Retrieves the number of parameters for a specific parameterization.
Definition oscillator.cpp:191
double selfkerr
Self-Kerr frequency , multiplies .
Definition oscillator.hpp:42
int evalControl_Labframe(const double t, double *f_ptr)
Evaluates lab-frame control function.
Definition oscillator.cpp:319
PetscInt dim_postOsc
Dimension of coupled subsystems following this oscillator.
Definition oscillator.hpp:65
size_t getNLevels()
Retrieves the number of energy levels.
Definition oscillator.hpp:94
int mpirank_world
Rank of MPI_COMM_WORLD.
Definition oscillator.hpp:54
double ground_freq
Fundamental 0-1 transition frequency of this oscillator .
Definition oscillator.hpp:41
PetscInt dim_preOsc
Dimension of coupled subsystems preceding this oscillator.
Definition oscillator.hpp:64
std::vector< ControlBasis * > basisfunctions
Basis functions for control parameterization foreach time parameterization. Note: Currently only one ...
Definition oscillator.hpp:51
double decay_time
Characteristic time for T1 decay operations.
Definition oscillator.hpp:46
int getNSplines()
Retrieves the number of splines used in the control parameterization.
Definition oscillator.hpp:150
PetscInt localsize_u
Size of local sub vector u or v in state x=[u,v].
Definition oscillator.hpp:57
void evalControlVariationDiff(Vec G, double var_reg_bar, int skip_to_oscillator)
Computes derivative of control variation penalty.
Definition oscillator.cpp:215
size_t nlevels
Number of energy levels for this oscillator.
Definition oscillator.hpp:40
int evalControl_diff(const double t, double *grad_for_this_oscillator, const double pbar, const double qbar)
Computes derivatives of control functions p(t) and q(t) with respect to the parameters.
Definition oscillator.cpp:283
size_t getNCarrierfrequencies()
Retrieves the number of carrier frequencies.
Definition oscillator.hpp:136
void population(const Vec x, std::vector< double > &pop)
Computes population in each energy level of this oscillator.
Definition oscillator.cpp:443
double getDecayTime()
Retrieves the T1 decay time.
Definition oscillator.hpp:115
double dephase_time
Characteristic time for T2 dephasing operations.
Definition oscillator.hpp:47
bool control_zero_boundary_condition
Flag to enforce boundary conditions on controls.
Definition oscillator.hpp:61
Oscillator()
Definition oscillator.cpp:7
std::vector< double > params
Control parameters for this oscillator.
Definition oscillator.hpp:49
ControlType getControlType()
Retrieves the type of control parameterization.
Definition oscillator.hpp:143
double Tfinal
Final evolution time.
Definition oscillator.hpp:50
PetscInt ilow
First index of the local sub vector u,v.
Definition oscillator.hpp:58
int mpirank_petsc
Rank of PETSc's communicator.
Definition oscillator.hpp:55
int myid
Integer identifier for this oscillator.
Definition oscillator.hpp:39
void clearParams()
Clears all control parameters.
Definition oscillator.hpp:186
int evalControl(const double t, double *Re_ptr, double *Im_ptr)
Evaluates the rotating-frame control functions.
Definition oscillator.cpp:234
void setParams(const double *x)
Sets control parameters from a global storage.
Definition oscillator.cpp:177
DecoherenceType decoherence_type
Type of Lindblad decoherence operators to include.
Definition oscillator.hpp:45
std::vector< double > carrier_freq
Frequencies of the carrier waves.
Definition oscillator.hpp:52
double getDetuning()
Retrieves the detuning frequency.
Definition oscillator.hpp:108
double detuning_freq
Detuning frequency, detuning = ground_freq - rotational_freq, multiplies .
Definition oscillator.hpp:44
size_t getNParameterizations()
Retrieves the number of control parameterizations in this oscillator (currently always 1).
Definition oscillator.hpp:129
void expectedEnergy_diff(const Vec x, Vec x_bar, const double obj_bar)
Computes derivative of expected energy computation.
Definition oscillator.cpp:401
size_t getNParams()
Retrieves the number of control parameters.
Definition oscillator.hpp:87
void getParams(double *x)
Retrieves control parameters into a global storage.
Definition oscillator.cpp:185
Core type definitions and enumerations for Quandary quantum optimal control.
DecoherenceType
Available Lindblad operator types for open quantum systems, or NONE for closed quantum systems.
Definition defs.hpp:31
ControlType
Types of control parameterizations.
Definition defs.hpp:149
#define M_PI
Definition defs.hpp:16