Quandary
Loading...
Searching...
No Matches
Public Member Functions | Public Attributes | Protected Attributes | List of all members
Output Class Reference

Output management for quantum control simulations and optimization. More...

#include <output.hpp>

Public Member Functions

 Output ()
 
 Output (const Config &config, MPI_Comm comm_petsc, MPI_Comm comm_init, bool quietmode=false)
 Constructor with configuration and MPI setup.
 
 ~Output ()
 
void writeOptimFile (int optim_iter, double objective, double gnorm, double stepsize, double Favg, double cost, double tikh_regul, double penalty_leakage, double penalty_dpdm, double penalty_energy, double penalty_variation, double penalty_weightedcost)
 Writes optimization progress to history file.
 
void writeControls (Vec params, MasterEq *mastereq, int ntime, double dt)
 Writes current control pulses per oscillator and control parameters.
 
void writeGradient (Vec grad)
 Writes gradient vector for debugging adjoint calculations.
 
void openTrajectoryDataFiles (std::string prefix, int initid)
 Opens data files for time evolution output for one oscillator.
 
void writeTrajectoryDataFiles (int timestep, double time, const Vec state, MasterEq *mastereq)
 Writes time evolution data to files.
 
void closeTrajectoryDataFiles ()
 Closes open time evolution data files.
 

Public Attributes

std::string output_dir
 Directory path for output data files.
 
int output_optimization_stride
 Write output files every N optimization iterations.
 

Protected Attributes

int mpirank_world
 Rank of processor in MPI_COMM_WORLD.
 
int mpirank_petsc
 Rank of processor for PETSc parallelization.
 
int mpisize_petsc
 Size of communicator for PETSc parallelization.
 
int mpirank_init
 Rank of processor for initial condition parallelization.
 
bool quietmode
 Flag for reduced screen output.
 
FILEoptimfile
 Output file for logging optimization progress.
 
int output_timestep_stride
 Time domain output frequency (write every N time steps)
 
std::vector< OutputTypeoutput_observables
 List of output types applied to all oscillators.
 
size_t noscillators
 Number of oscillators in the system.
 
bool writeFullState
 Flag to determine if evolution of full state vector should be written to file.
 
bool writeExpectedEnergy
 Flag to determine if evolution of expected energy per oscillator should be written to files.
 
bool writeExpectedEnergy_comp
 Flag to determine if evolution of expected energy of the full composite system should be written to file.
 
bool writePopulation
 Flag to determine if the evolution of the energy level occupations per oscillator should be written to files.
 
bool writePopulation_comp
 Flag to determine if the evolution of the energy level occupations of the full composite system should be written to file.
 
FILEufile
 File for writing real part of fullstate evolution.
 
FILEvfile
 File for writing imaginary part of fullstate evolution.
 
std::vector< FILE * > expectedfile
 Files for expected energy evolution per oscillator.
 
std::vector< FILE * > populationfile
 Files for population evolution per oscillator.
 
FILEexpectedfile_comp
 File for expected energy evolution of the full composite system.
 
FILEpopulationfile_comp
 File for population evolution of the full composite system.
 

Detailed Description

Output management for quantum control simulations and optimization.

This class handles all file output operations for Quandary, including optimization progress logging, control pulse output, state evolution data, and population dynamics. It manages MPI-aware output to avoid duplicate writes in parallel runs.

Constructor & Destructor Documentation

◆ Output() [1/2]

Output::Output ( )

◆ Output() [2/2]

Output::Output ( const Config config,
MPI_Comm  comm_petsc,
MPI_Comm  comm_init,
bool  quietmode = false 
)

Constructor with configuration and MPI setup.

Parameters
configConfiguration parameters from input file
comm_petscMPI communicator for PETSc parallelization
comm_initMPI communicator for initial condition parallelization
quietmodeFlag for reduced output (default: false)

◆ ~Output()

Output::~Output ( )

Member Function Documentation

◆ closeTrajectoryDataFiles()

void Output::closeTrajectoryDataFiles ( )

Closes open time evolution data files.

Properly closes and flushes all output files after time-stepping completion.

◆ openTrajectoryDataFiles()

void Output::openTrajectoryDataFiles ( std::string  prefix,
int  initid 
)

Opens data files for time evolution output for one oscillator.

Prepares files for writing full state, expected energy, and population evolution data. Called before timestepping starts.

Parameters
prefixFilename prefix for output files
initidInitial condition identifier

◆ writeControls()

void Output::writeControls ( Vec  params,
MasterEq mastereq,
int  ntime,
double  dt 
)

Writes current control pulses per oscillator and control parameters.

Called every output_optimization_stride optimization iterations. Control pulses are written to <output_dir>/control<ioscillator>.dat Control parameters are written to <output_dir>/params.dat

Parameters
paramsCurrent parameter vector
mastereqPointer to master equation solver
ntimeTotal number of time steps
dtTime step size

◆ writeGradient()

void Output::writeGradient ( Vec  grad)

Writes gradient vector for debugging adjoint calculations.

Gradient is written to <output_dir>/grad.dat

Parameters
gradGradient vector to output

◆ writeOptimFile()

void Output::writeOptimFile ( int  optim_iter,
double  objective,
double  gnorm,
double  stepsize,
double  Favg,
double  cost,
double  tikh_regul,
double  penalty_leakage,
double  penalty_dpdm,
double  penalty_energy,
double  penalty_variation,
double  penalty_weightedcost 
)

Writes optimization progress to history file.

Called at every optimization iteration to log convergence data. Optimization history will be written to <output_dir>/optim_history.dat.

Parameters
optim_iterCurrent optimization iteration
objectiveTotal objective function value
gnormGradient norm
stepsizeOptimization step size
FavgAverage fidelity
costFinal-time cost term
tikh_regulTikhonov regularization term
penalty_leakagePenalty term for leakage
penalty_weightedcostWeighted cost penalty
penalty_dpdmSecond-order derivative penalty
penalty_energyEnergy penalty term
penalty_variationControl variation penalty

◆ writeTrajectoryDataFiles()

void Output::writeTrajectoryDataFiles ( int  timestep,
double  time,
const Vec  state,
MasterEq mastereq 
)

Writes time evolution data to files.

Outputs state vector, expected energies, and populations at current time step. Called at each time step

Parameters
timestepCurrent time step number
timeCurrent time value
stateCurrent state vector
mastereqPointer to master equation solver

Member Data Documentation

◆ expectedfile

std::vector<FILE *> Output::expectedfile
protected

Files for expected energy evolution per oscillator.

◆ expectedfile_comp

FILE* Output::expectedfile_comp
protected

File for expected energy evolution of the full composite system.

◆ mpirank_init

int Output::mpirank_init
protected

Rank of processor for initial condition parallelization.

◆ mpirank_petsc

int Output::mpirank_petsc
protected

Rank of processor for PETSc parallelization.

◆ mpirank_world

int Output::mpirank_world
protected

Rank of processor in MPI_COMM_WORLD.

◆ mpisize_petsc

int Output::mpisize_petsc
protected

Size of communicator for PETSc parallelization.

◆ noscillators

size_t Output::noscillators
protected

Number of oscillators in the system.

◆ optimfile

FILE* Output::optimfile
protected

Output file for logging optimization progress.

◆ output_dir

std::string Output::output_dir

Directory path for output data files.

◆ output_observables

std::vector<OutputType> Output::output_observables
protected

List of output types applied to all oscillators.

◆ output_optimization_stride

int Output::output_optimization_stride

Write output files every N optimization iterations.

◆ output_timestep_stride

int Output::output_timestep_stride
protected

Time domain output frequency (write every N time steps)

◆ populationfile

std::vector<FILE *> Output::populationfile
protected

Files for population evolution per oscillator.

◆ populationfile_comp

FILE* Output::populationfile_comp
protected

File for population evolution of the full composite system.

◆ quietmode

bool Output::quietmode
protected

Flag for reduced screen output.

◆ ufile

FILE* Output::ufile
protected

File for writing real part of fullstate evolution.

◆ vfile

FILE* Output::vfile
protected

File for writing imaginary part of fullstate evolution.

◆ writeExpectedEnergy

bool Output::writeExpectedEnergy
protected

Flag to determine if evolution of expected energy per oscillator should be written to files.

◆ writeExpectedEnergy_comp

bool Output::writeExpectedEnergy_comp
protected

Flag to determine if evolution of expected energy of the full composite system should be written to file.

◆ writeFullState

bool Output::writeFullState
protected

Flag to determine if evolution of full state vector should be written to file.

◆ writePopulation

bool Output::writePopulation
protected

Flag to determine if the evolution of the energy level occupations per oscillator should be written to files.

◆ writePopulation_comp

bool Output::writePopulation_comp
protected

Flag to determine if the evolution of the energy level occupations of the full composite system should be written to file.


The documentation for this class was generated from the following files: