<s> """<STR_LIT>""" <EOL> from collections import OrderedDict <EOL> from sqlitedict import SqliteDict <EOL> from openmdao . recorders . base_recorder import BaseRecorder <EOL> from openmdao . util . record_util import format_iteration_coordinate <EOL> from openmdao . core . mpi_wrap import MPI <EOL> class SqliteRecorder ( BaseRecorder ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , out , ** sqlite_dict_args ) : <EOL> super ( SqliteRecorder , self ) . __init__ ( ) <EOL> if MPI and MPI . COMM_WORLD . rank > <NUM_LIT:0> : <EOL> self . _open_close_sqlitedict = False <EOL> else : <EOL> self . _open_close_sqlitedict = True <EOL> if self . _open_close_sqlitedict : <EOL> sqlite_dict_args . setdefault ( '<STR_LIT>' , True ) <EOL> sqlite_dict_args . setdefault ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> self . out = SqliteDict ( filename = out , flag = '<STR_LIT:n>' , ** sqlite_dict_args ) <EOL> else : <EOL> self . out = None <EOL> def record_metadata ( self , group ) : <EOL> """<STR_LIT>""" <EOL> params = group . params . iteritems ( ) <EOL> resids = group . resids . iteritems ( ) <EOL> unknowns = group . unknowns . iteritems ( ) <EOL> data = OrderedDict ( [ ( '<STR_LIT>' , dict ( params ) ) , <EOL> ( '<STR_LIT>' , dict ( unknowns ) ) , <EOL> ] ) <EOL> self . out [ '<STR_LIT>' ] = data <EOL> def record_iteration ( self , params , unknowns , resids , metadata ) : <EOL> """<STR_LIT>""" <EOL> data = OrderedDict ( ) <EOL> iteration_coordinate = metadata [ '<STR_LIT>' ] <EOL> timestamp = metadata [ '<STR_LIT>' ] <EOL> group_name = format_iteration_coordinate ( iteration_coordinate ) <EOL> data [ '<STR_LIT>' ] = timestamp <EOL> data [ '<STR_LIT:success>' ] = metadata [ '<STR_LIT:success>' ] <EOL> data [ '<STR_LIT>' ] = metadata [ '<STR_LIT>' ] <EOL> if self . options [ '<STR_LIT>' ] : <EOL> data [ '<STR_LIT>' ] = self . _filter_vector ( params , '<STR_LIT:p>' , iteration_coordinate ) <EOL> if self . options [ '<STR_LIT>' ] : <EOL> data [ '<STR_LIT>' ] = self . _filter_vector ( unknowns , '<STR_LIT:u>' , iteration_coordinate ) <EOL> if self . options [ '<STR_LIT>' ] : <EOL> data [ '<STR_LIT>' ] = self . _filter_vector ( resids , '<STR_LIT:r>' , iteration_coordinate ) <EOL> self . out [ group_name ] = data <EOL> def record_derivatives ( self , derivs , metadata ) : <EOL> """<STR_LIT>""" <EOL> data = OrderedDict ( ) <EOL> iteration_coordinate = metadata [ '<STR_LIT>' ] <EOL> timestamp = metadata [ '<STR_LIT>' ] <EOL> group_name = format_iteration_coordinate ( iteration_coordinate ) <EOL> group_name = '<STR_LIT>' % group_name <EOL> data [ '<STR_LIT>' ] = timestamp <EOL> data [ '<STR_LIT:success>' ] = metadata [ '<STR_LIT:success>' ] <EOL> data [ '<STR_LIT>' ] = metadata [ '<STR_LIT>' ] <EOL> data [ '<STR_LIT>' ] = derivs <EOL> self . out [ group_name ] = data <EOL> def close ( self ) : <EOL> """<STR_LIT>""" <EOL> if self . _open_close_sqlitedict : <EOL> if self . out is not None : <EOL> self . out . close ( ) <EOL> self . out = None </s>
