Skip to content
Merged
12 changes: 6 additions & 6 deletions include/controlbasis.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ class ControlBasis {
virtual int getNSplines() {return 0;};

/* Variation of control parameters */
virtual double computeVariation(std::vector<double>& params, int carrierfreqID){return 0.0;};
virtual void computeVariation_diff(double* grad, std::vector<double>&params, double var_bar, int carrierfreqID){};
virtual double computeVariation(std::vector<double>& /*params*/, int /*carrierfreqID*/){return 0.0;};
virtual void computeVariation_diff(double* /*grad*/, std::vector<double>& /*params*/, double /*var_bar*/, int /*carrierfreqID*/){};

/* Default: do nothing. For some control parameterizations, this can be used to enforce that the controls start and end at zero. E.g. the Splines will overwrite the parameters x of the first and last two splines by zero, so that the splines start and end at zero. */
virtual void enforceBoundary(double* x, int carrier_id) {};
virtual void enforceBoundary(double* /*x*/, int /*carrier_id*/) {};

/* Evaluate the Basis(alpha, t) at time t using the coefficients coeff. */
virtual void evaluate(const double t, const std::vector<double>& coeff, int carrier_freq_id, double* Blt1, double*Blt2) = 0;
Expand Down Expand Up @@ -198,8 +198,8 @@ class ConstantTransferFunction : public TransferFunction {
ConstantTransferFunction(double constant_, std::vector<double> onofftimes);
~ConstantTransferFunction();

double eval(double x, double time) {return isOn(constant, time); };
double der(double x, double time) {return 0.0; };
double eval(double /*x*/, double time) {return isOn(constant, time); };
double der(double /*x*/, double /*time*/) {return 0.0; };
};

/*
Expand All @@ -212,7 +212,7 @@ class IdentityTransferFunction : public TransferFunction {
~IdentityTransferFunction();

double eval(double x, double time) {return isOn(x, time); };
double der(double x, double time) {return isOn(1.0, time); };
double der(double /*x*/, double time) {return isOn(1.0, time); };
};


Expand Down
6 changes: 3 additions & 3 deletions include/mastereq.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,10 @@ class MasterEq{
void setTransferOnOffTimes(std::vector<double> tlist);

/* Return the i-th oscillator */
Oscillator* getOscillator(const int i);
Oscillator* getOscillator(const size_t i);

/* Return number of oscillators */
int getNOscillators();
size_t getNOscillators();

/* Return dimension of vectorized system N^2 (for Lindblad solver) or N (for Schroedinger solver) */
int getDim();
Expand Down Expand Up @@ -437,7 +437,7 @@ inline void L1decay(const int it, const int n, const int i, const int ip, const


// Transpose of offdiagonal L1decay
inline void L1decay_T(const int it, const int n, const int i, const int ip, const int stridei, const int strideip, const double* xptr, const double decayi, double* yre, double* yim){
inline void L1decay_T(const int it, const int i, const int ip, const int stridei, const int strideip, const double* xptr, const double decayi, double* yre, double* yim){
if (fabs(decayi) > 1e-12) {
if (i > 0 && ip > 0) {
double l1off = decayi * sqrt(i*ip);
Expand Down
2 changes: 1 addition & 1 deletion include/optimproblem.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
class OptimProblem {

/* ODE stuff */
int ninit; /* Number of initial conditions to be considered (N^2, N, or 1) */
size_t ninit; /* Number of initial conditions to be considered (N^2, N, or 1) */
int ninit_local; /* Local number of initial conditions on this processor */
Vec rho_t0; /* Storage for initial condition of the ODE */
Vec rho_t0_bar; /* Adjoint of ODE initial condition */
Expand Down
2 changes: 1 addition & 1 deletion include/optimtarget.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class OptimTarget{
If target is a gate, this holds the transformed state VrhoV^\dagger.
If target is read from file, this holds the target density matrix from that file. */
InitialConditionType initcond_type; /* Type of initial conditions */
std::vector<int> initcond_IDs; /* Integer list for pure-state initialization */
std::vector<size_t> initcond_IDs; /* Integer list for pure-state initialization */
LindbladType lindbladtype; /* Type of decoherence (lindblad vs schroedinger) */

Vec aux; /* auxiliary vector needed when computing the objective for gate optimization */
Expand Down
10 changes: 5 additions & 5 deletions include/oscillator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,18 +48,18 @@ class Oscillator {
int dim_postOsc; // Dimension of coupled subsystem following this oscillator

Oscillator();
Oscillator(MapParam config, int id, std::vector<int> nlevels_all_, std::vector<std::string>& controlsegments, std::vector<std::string>& controlinitializations, double ground_freq_, double selfkerr_, double rotational_freq_, double decay_time_, double dephase_time_, std::vector<double> carrier_freq_, double Tfinal_, LindbladType lindbladtype_, std::default_random_engine rand_engine);
Oscillator(MapParam config, size_t id, std::vector<int> nlevels_all_, std::vector<std::string>& controlsegments, std::vector<std::string>& controlinitializations, double ground_freq_, double selfkerr_, double rotational_freq_, double decay_time_, double dephase_time_, std::vector<double> carrier_freq_, double Tfinal_, LindbladType lindbladtype_, std::default_random_engine rand_engine);
virtual ~Oscillator();

/* Return the constants */
int getNParams() { return params.size(); };
int getNLevels() { return nlevels; };
size_t getNParams() { return params.size(); };
size_t getNLevels() { return nlevels; };
double getSelfkerr() { return selfkerr; };
double getDetuning() { return detuning_freq; };
double getDecayTime() {return decay_time; };
double getDephaseTime() {return dephase_time; };
int getNSegments() {return basisfunctions.size(); };
int getNCarrierfrequencies() {return carrier_freq.size(); };
size_t getNSegments() {return basisfunctions.size(); };
size_t getNCarrierfrequencies() {return carrier_freq.size(); };
ControlType getControlType(int isegment=0) {return basisfunctions[isegment]->getType(); };
int getNSplines(int isegment=0) {return basisfunctions[isegment]->getNSplines();};
double getRotFreq() {return (ground_freq - detuning_freq) / (2.0*M_PI); };
Expand Down
12 changes: 6 additions & 6 deletions include/timestepper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,17 +50,17 @@ class TimeStepper{
bool storeFWD; /* Flag that determines if primal states should be stored during forward evaluation */

TimeStepper();
TimeStepper(MapParam config, MasterEq* mastereq_, int ntime_, double total_time_, Output* output_, bool storeFWD_);
TimeStepper(MasterEq* mastereq_, int ntime_, double total_time_, Output* output_, bool storeFWD_);
virtual ~TimeStepper();

/* Return the state at a certain time index */
Vec getState(int tindex);
Vec getState(size_t tindex);

/* Solve the ODE forward in time with initial condition rho_t0. Return state at final time step */
Vec solveODE(int initid, Vec rho_t0);

/* Solve the adjoint ODE backwards in time from terminal condition rho_t0_bar */
void solveAdjointODE(int initid, Vec rho_t0_bar, Vec finalstate, double Jbar_penalty, double Jbar_penalty_dpdm, double Jbar_penalty_energy);
void solveAdjointODE(Vec rho_t0_bar, Vec finalstate, double Jbar_penalty, double Jbar_penalty_dpdm, double Jbar_penalty_energy);

/* evaluate the penalty integral term */
double penaltyIntegral(double time, const Vec x);
Expand All @@ -84,7 +84,7 @@ class TimeStepper{
class ExplEuler : public TimeStepper {
Vec stage;
public:
ExplEuler(MapParam config, MasterEq* mastereq_, int ntime_, double total_time_, Output* output_, bool storeFWD_);
ExplEuler(MasterEq* mastereq_, int ntime_, double total_time_, Output* output_, bool storeFWD_);
~ExplEuler();

/* Evolve state forward from tstart to tstop */
Expand Down Expand Up @@ -116,7 +116,7 @@ class ImplMidpoint : public TimeStepper {
Vec tmp, err; /* Auxiliary vector for applying the neuman iterations */

public:
ImplMidpoint(MapParam config, MasterEq* mastereq_, int ntime_, double total_time_, LinearSolverType linsolve_type_, int linsolve_maxiter_, Output* output_, bool storeFWD_);
ImplMidpoint(MasterEq* mastereq_, int ntime_, double total_time_, LinearSolverType linsolve_type_, int linsolve_maxiter_, Output* output_, bool storeFWD_);
~ImplMidpoint();


Expand All @@ -140,7 +140,7 @@ class CompositionalImplMidpoint : public ImplMidpoint {
int order;

public:
CompositionalImplMidpoint(MapParam config, int order_, MasterEq* mastereq_, int ntime_, double total_time_, LinearSolverType linsolve_type_, int linsolve_maxiter_, Output* output_, bool storeFWD_);
CompositionalImplMidpoint(int order_, MasterEq* mastereq_, int ntime_, double total_time_, LinearSolverType linsolve_type_, int linsolve_maxiter_, Output* output_, bool storeFWD_);
~CompositionalImplMidpoint();

void evolveFWD(const double tstart, const double tstop, Vec x);
Expand Down
4 changes: 0 additions & 4 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,6 @@ if(WITH_SLEPC)
target_compile_options(quandary PRIVATE -DWITH_SLEPC)
endif()

# Suppress compiler warnings temporarily
# TODO fix these and remove this!
add_definitions(-w)

install(
TARGETS quandary
RUNTIME DESTINATION bin
Expand Down
1 change: 0 additions & 1 deletion src/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,6 @@ void MapParam::GetVecIntParam(std::string key, std::vector<int> &fillme, int def
{
std::map<std::string, std::string>::const_iterator it_value = this->find(key);
std::string lineexp;
double val;
if (it_value == this->end())
{
if (mpi_rank == 0 && !quietmode && warnme)
Expand Down
6 changes: 3 additions & 3 deletions src/controlbasis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ void BSpline2nd::evaluate(const double t, const std::vector<double>& coeff, int

}

void BSpline2nd::derivative(const double t, const std::vector<double>& coeff, double* coeff_diff, const double valbar1, const double valbar2, int carrier_freq_id) {
void BSpline2nd::derivative(const double t, const std::vector<double>& /*coeff*/, double* coeff_diff, const double valbar1, const double valbar2, int carrier_freq_id) {

/* Iterate over basis function */
for (int l=0; l<nsplines; l++) {
Expand Down Expand Up @@ -242,7 +242,7 @@ void BSpline0::evaluate(const double t, const std::vector<double>& coeff, int ca
}
}

void BSpline0::derivative(const double t, const std::vector<double>& coeff, double* coeff_diff, const double valbar1, const double valbar2, int carrier_freq_id) {
void BSpline0::derivative(const double t, const std::vector<double>& /*coeff*/, double* coeff_diff, const double valbar1, const double valbar2, int carrier_freq_id) {

// Figure out which basis function is active at this time point
int splineID = ceil((t-tstart)/dtknot - 0.5);
Expand Down Expand Up @@ -332,7 +332,7 @@ void TransferFunction::storeOnOffTimes(std::vector<double>onofftimes_){

// Copy the list of time points that determine when the transfer functions are active
onofftimes.clear();
for (int i=0; i<onofftimes_.size(); i++) {
for (size_t i=0; i<onofftimes_.size(); i++) {
onofftimes.push_back( onofftimes_[i] );
}
}
Expand Down
10 changes: 5 additions & 5 deletions src/gate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,19 @@ Gate::Gate(std::vector<int> nlevels_, std::vector<int> nessential_, double time_
final_time = time_;
gate_rot_freq = gate_rot_freq_;
lindbladtype = lindbladtype_;
for (int i=0; i<gate_rot_freq.size(); i++){
for (size_t i=0; i<gate_rot_freq.size(); i++){
gate_rot_freq[i] *= 2.*M_PI;
}

/* Dimension of gate = \prod_j nessential_j */
dim_ess = 1;
for (int i=0; i<nessential.size(); i++) {
for (size_t i=0; i<nessential.size(); i++) {
dim_ess *= nessential[i];
}

/* Dimension of system matrix rho */
dim_rho = 1;
for (int i=0; i<nlevels.size(); i++) {
for (size_t i=0; i<nlevels.size(); i++) {
dim_rho *= nlevels[i];
}

Expand Down Expand Up @@ -98,10 +98,10 @@ void Gate::assembleGate(){
for (PetscInt row=0; row<dim_ess; row++){
int r = row;
double freq = 0.0;
for (int iosc=0; iosc<nlevels.size(); iosc++){
for (size_t iosc=0; iosc<nlevels.size(); iosc++){
// compute dimension of essential levels of all following subsystems
int dim_post = 1;
for (int josc=iosc+1; josc<nlevels.size();josc++) {
for (size_t josc=iosc+1; josc<nlevels.size();josc++) {
dim_post *= nessential[josc];
}
// compute the frequency
Expand Down
45 changes: 22 additions & 23 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,12 @@ int main(int argc,char **argv)
/* Get the number of essential levels per oscillator.
* Default: same as number of levels */
std::vector<int> nessential(nlevels.size());
for (int iosc = 0; iosc<nlevels.size(); iosc++) nessential[iosc] = nlevels[iosc];
for (size_t iosc = 0; iosc<nlevels.size(); iosc++) nessential[iosc] = nlevels[iosc];
/* Overwrite if config option is given */
std::vector<int> read_nessential;
config.GetVecIntParam("nessential", read_nessential, -1);
if (read_nessential[0] > -1) {
for (int iosc = 0; iosc<nlevels.size(); iosc++){
for (size_t iosc = 0; iosc<nlevels.size(); iosc++){
if (iosc < read_nessential.size()) nessential[iosc] = read_nessential[iosc];
else nessential[iosc] = read_nessential[read_nessential.size()-1];
if (nessential[iosc] > nlevels[iosc]) nessential[iosc] = nlevels[iosc];
Expand All @@ -113,7 +113,7 @@ int main(int argc,char **argv)
else if (initcondstr[0].compare("Nplus1") == 0 ) {
// compute system dimension N
ninit = 1;
for (int i=0; i<nlevels.size(); i++){
for (size_t i=0; i<nlevels.size(); i++){
ninit *= nlevels[i];
}
ninit +=1;
Expand All @@ -123,10 +123,10 @@ int main(int argc,char **argv)
/* Compute ninit = dim(subsystem defined by list of oscil IDs) */
ninit = 1;
if (initcondstr.size() < 2) {
for (int j=0; j<nlevels.size(); j++) initcondstr.push_back(std::to_string(j));
for (size_t j=0; j<nlevels.size(); j++) initcondstr.push_back(std::to_string(j));
}
for (int i = 1; i<initcondstr.size(); i++){
int oscilID = atoi(initcondstr[i].c_str());
for (size_t i = 1; i<initcondstr.size(); i++){
size_t oscilID = atoi(initcondstr[i].c_str());
if (oscilID < nessential.size()) ninit *= nessential[oscilID];
}
if (initcondstr[0].compare("basis") == 0 ) {
Expand Down Expand Up @@ -235,7 +235,7 @@ int main(int argc,char **argv)
// Get control segment types, carrierwaves and control initialization
std::string default_seg_str = "spline, 10, 0.0, "+std::to_string(total_time); // Default for first oscillator control segment
std::string default_init_str = "constant, 0.0"; // Default for first oscillator initialization
for (int i = 0; i < nlevels.size(); i++){
for (size_t i = 0; i < nlevels.size(); i++){
// Get carrier wave frequencies
std::vector<double> carrier_freq;
std::string key = "carrier_frequency" + std::to_string(i);
Expand All @@ -255,8 +255,8 @@ int main(int argc,char **argv)
// Update the default for control type
default_seg_str = "";
default_init_str = "";
for (int l = 0; l<controltype_str.size(); l++) default_seg_str += controltype_str[l]+=", ";
for (int l = 0; l<controlinit_str.size(); l++) default_init_str += controlinit_str[l]+=", ";
for (size_t l = 0; l<controltype_str.size(); l++) default_seg_str += controltype_str[l]+=", ";
for (size_t l = 0; l<controlinit_str.size(); l++) default_init_str += controlinit_str[l]+=", ";
}

// Get pi-pulses, if any
Expand All @@ -269,16 +269,16 @@ int main(int argc,char **argv)
printf("apply_pipulse config option: <oscilID>, <tstart>, <tstop>, <amp>, <anotherOscilID>, <anotherTstart>, <anotherTstop>, <anotherAmp> ...\n");
exit(1);
}
int k=0;
size_t k=0;
while (k < pipulse_str.size()){
// Set pipulse for this oscillator
int pipulse_id = atoi(pipulse_str[k+0].c_str());
size_t pipulse_id = atoi(pipulse_str[k+0].c_str());
oscil_vec[pipulse_id]->pipulse.tstart.push_back(atof(pipulse_str[k+1].c_str()));
oscil_vec[pipulse_id]->pipulse.tstop.push_back(atof(pipulse_str[k+2].c_str()));
oscil_vec[pipulse_id]->pipulse.amp.push_back(atof(pipulse_str[k+3].c_str()));
if (mpirank_world==0) printf("Applying PiPulse to oscillator %d in [%f,%f]: |p+iq|=%f\n", pipulse_id, oscil_vec[pipulse_id]->pipulse.tstart.back(), oscil_vec[pipulse_id]->pipulse.tstop.back(), oscil_vec[pipulse_id]->pipulse.amp.back());
if (mpirank_world==0) printf("Applying PiPulse to oscillator %zu in [%f,%f]: |p+iq|=%f\n", pipulse_id, oscil_vec[pipulse_id]->pipulse.tstart.back(), oscil_vec[pipulse_id]->pipulse.tstop.back(), oscil_vec[pipulse_id]->pipulse.amp.back());
// Set zero control for all other oscillators during this pipulse
for (int i=0; i<nlevels.size(); i++){
for (size_t i=0; i<nlevels.size(); i++){
if (i != pipulse_id) {
oscil_vec[i]->pipulse.tstart.push_back(atof(pipulse_str[k+1].c_str()));
oscil_vec[i]->pipulse.tstop.push_back(atof(pipulse_str[k+2].c_str()));
Expand Down Expand Up @@ -312,8 +312,8 @@ int main(int argc,char **argv)
// Compute coupling rotation frequencies eta_ij = w^r_i - w^r_j
std::vector<double> eta(nlevels.size()*(nlevels.size()-1)/2.);
int idx = 0;
for (int iosc=0; iosc<nlevels.size(); iosc++){
for (int josc=iosc+1; josc<nlevels.size(); josc++){
for (size_t iosc=0; iosc<nlevels.size(); iosc++){
for (size_t josc=iosc+1; josc<nlevels.size(); josc++){
eta[idx] = rot_freq[iosc] - rot_freq[josc];
idx++;
}
Expand All @@ -334,12 +334,12 @@ int main(int argc,char **argv)
// Some screen output
if (mpirank_world == 0 && !quietmode) {
std::cout<< "System: ";
for (int i=0; i<nlevels.size(); i++) {
for (size_t i=0; i<nlevels.size(); i++) {
std::cout<< nlevels[i];
if (i < nlevels.size()-1) std::cout<< "x";
}
std::cout<<" (essential levels: ";
for (int i=0; i<nlevels.size(); i++) {
for (size_t i=0; i<nlevels.size(); i++) {
std::cout<< nessential[i];
if (i < nlevels.size()-1) std::cout<< "x";
}
Expand All @@ -363,16 +363,15 @@ int main(int argc,char **argv)

/* My time stepper */
bool storeFWD = false;
int ninit_local = ninit / mpisize_init;
if (mastereq->lindbladtype != LindbladType::NONE &&
(runtype == RunType::GRADIENT || runtype == RunType::OPTIMIZATION) ) storeFWD = true; // if NOT Schroedinger solver and running gradient optim: store forward states. Otherwise, they will be recomputed during gradient.

std::string timesteppertypestr = config.GetStrParam("timestepper", "IMR");
TimeStepper* mytimestepper;
if (timesteppertypestr.compare("IMR")==0) mytimestepper = new ImplMidpoint(config, mastereq, ntime, total_time, linsolvetype, linsolve_maxiter, output, storeFWD);
else if (timesteppertypestr.compare("IMR4")==0) mytimestepper = new CompositionalImplMidpoint(config, 4, mastereq, ntime, total_time, linsolvetype, linsolve_maxiter, output, storeFWD);
else if (timesteppertypestr.compare("IMR8")==0) mytimestepper = new CompositionalImplMidpoint(config, 8, mastereq, ntime, total_time, linsolvetype, linsolve_maxiter, output, storeFWD);
else if (timesteppertypestr.compare("EE")==0) mytimestepper = new ExplEuler(config, mastereq, ntime, total_time, output, storeFWD);
if (timesteppertypestr.compare("IMR")==0) mytimestepper = new ImplMidpoint(mastereq, ntime, total_time, linsolvetype, linsolve_maxiter, output, storeFWD);
else if (timesteppertypestr.compare("IMR4")==0) mytimestepper = new CompositionalImplMidpoint(4, mastereq, ntime, total_time, linsolvetype, linsolve_maxiter, output, storeFWD);
else if (timesteppertypestr.compare("IMR8")==0) mytimestepper = new CompositionalImplMidpoint(8, mastereq, ntime, total_time, linsolvetype, linsolve_maxiter, output, storeFWD);
else if (timesteppertypestr.compare("EE")==0) mytimestepper = new ExplEuler(mastereq, ntime, total_time, output, storeFWD);
else {
printf("\n\n ERROR: Unknow timestepping type: %s.\n\n", timesteppertypestr.c_str());
exit(1);
Expand Down Expand Up @@ -730,7 +729,7 @@ int main(int argc,char **argv)
#endif

/* Clean up */
for (int i=0; i<nlevels.size(); i++){
for (size_t i=0; i<nlevels.size(); i++){
delete oscil_vec[i];
}
delete [] oscil_vec;
Expand Down
Loading