Changeset 27744


Ignore:
Timestamp:
05/12/23 13:44:31 (23 months ago)
Author:
jdquinn
Message:

CHG: MATLAB -> Python; typo

Location:
issm/trunk-jpl/src/m/classes
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • TabularUnified issm/trunk-jpl/src/m/classes/autodiff.py

    r27458 r27744  
    99
    1010class autodiff(object):
    11     """
    12     AUTODIFF class definition
    13 
    14        Usage:
    15           autodiff = autodiff()
     11    """autodiff class definition
     12
     13    Usage:
     14        autodiff = autodiff()
    1615    """
    1716    def __init__(self, *args):  # {{{
     
    2019        self.independents = []
    2120        self.driver = 'fos_forward'
    22         self.obufsize = float('NaN')
    23         self.lbufsize = float('NaN')
    24         self.cbufsize = float('NaN')
    25         self.tbufsize = float('NaN')
    26         self.gcTriggerMaxSize = float('NaN')
    27         self.gcTriggerRatio = float('NaN')
    28         self.tapeAlloc = float('NaN')
     21        self.obufsize = np.nan
     22        self.lbufsize = np.nan
     23        self.cbufsize = np.nan
     24        self.tbufsize = np.nan
     25        self.gcTriggerMaxSize = np.nan
     26        self.gcTriggerRatio = np.nan
     27        self.tapeAlloc = np.nan
    2928        if not len(args):
    3029            self.setdefaultparameters()
     
    3433
    3534    def __repr__(self):  # {{{
    36         s = "      automatic differentiation parameters:\n"
    37         s += "%s\n" % fielddisplay(self, 'isautodiff', "indicates if the automatic differentiation is activated")
    38         s += "%s\n" % fielddisplay(self, 'dependents', "list of dependent variables")
    39         s += "%s\n" % fielddisplay(self, 'independents', "list of independent variables")
    40         s += "%s\n" % fielddisplay(self, 'driver', "ADOLC driver ('fos_forward' or 'fov_forward')")
    41         s += "%s\n" % fielddisplay(self, 'obufsize', "Number of operations per buffer (== OBUFSIZE in usrparms.h)")
    42         s += "%s\n" % fielddisplay(self, 'lbufsize', "Number of locations per buffer (== LBUFSIZE in usrparms.h)")
    43         s += "%s\n" % fielddisplay(self, 'cbufsize', "Number of values per buffer (== CBUFSIZE in usrparms.h)")
    44         s += "%s\n" % fielddisplay(self, 'tbufsize', "Number of taylors per buffer (<=TBUFSIZE in usrparms.h)")
    45         s += "%s\n" % fielddisplay(self, 'gcTriggerRatio', "free location block sorting / consolidation triggered if the ratio between allocated and used locations exceeds gcTriggerRatio")
    46         s += "%s\n" % fielddisplay(self, 'gcTriggerMaxSize', "free location block sorting / consolidation triggered if the allocated locations exceed gcTriggerMaxSize)")
    47         s += "%s\n" % fielddisplay(self, 'tapeAlloc', 'Iteration count of a priori memory allocation of the AD tape')
     35        s = '      automatic differentiation parameters:\n'
     36        s += '{}\n'.format(fielddisplay(self, 'isautodiff', "indicates if the automatic differentiation is activated"))
     37        s += '{}\n'.format(fielddisplay(self, 'dependents', "list of dependent variables"))
     38        s += '{}\n'.format(fielddisplay(self, 'independents', "list of independent variables"))
     39        s += '{}\n'.format(fielddisplay(self, 'driver', "ADOLC driver ('fos_forward' or 'fov_forward')"))
     40        s += '{}\n'.format(fielddisplay(self, 'obufsize', "Number of operations per buffer (== OBUFSIZE in usrparms.h)"))
     41        s += '{}\n'.format(fielddisplay(self, 'lbufsize', "Number of locations per buffer (== LBUFSIZE in usrparms.h)"))
     42        s += '{}\n'.format(fielddisplay(self, 'cbufsize', "Number of values per buffer (== CBUFSIZE in usrparms.h)"))
     43        s += '{}\n'.format(fielddisplay(self, 'tbufsize', "Number of taylors per buffer (<=TBUFSIZE in usrparms.h)"))
     44        s += '{}\n'.format(fielddisplay(self, 'gcTriggerRatio', "free location block sorting / consolidation triggered if the ratio between allocated and used locations exceeds gcTriggerRatio"))
     45        s += '{}\n'.format(fielddisplay(self, 'gcTriggerMaxSize', "free location block sorting / consolidation triggered if the allocated locations exceed gcTriggerMaxSize)"))
     46        s += '{}\n'.format(fielddisplay(self, 'tapeAlloc', 'Iteration count of a priori memory allocation of the AD tape'))
    4847
    4948        return s
     
    6261
    6362    def checkconsistency(self, md, solution, analyses):  # {{{
    64         #Early return
     63        # Early return
    6564        if not self.isautodiff:
    6665            return md
     
    7473        md = checkfield(md, 'fieldname', 'autodiff.tapeAlloc', '>=', 0)
    7574
    76     #Driver value:
     75        # Driver value
    7776        md = checkfield(md, 'fieldname', 'autodiff.driver', 'values', ['fos_forward', 'fov_forward', 'fov_forward_all', 'fos_reverse', 'fov_reverse', 'fov_reverse_all'])
    7877
    79     #go through our dependents and independents and check consistency:
     78        # Go through our dependents and independents and check consistency
    8079        for dep in self.dependents:
    8180            dep.checkconsistency(md, solution, analyses)
     
    9089        WriteData(fid, prefix, 'object', self, 'fieldname', 'driver', 'format', 'String')
    9190
    92         #early return
     91        # Early return
    9392        if not self.isautodiff:
    9493            WriteData(fid, prefix, 'data', False, 'name', 'md.autodiff.mass_flux_segments_present', 'format', 'Boolean')
     
    9695            return
    9796
    98         #buffer sizes {{{
     97        # Buffer sizes
    9998        WriteData(fid, prefix, 'object', self, 'fieldname', 'obufsize', 'format', 'Double')
    10099        WriteData(fid, prefix, 'object', self, 'fieldname', 'lbufsize', 'format', 'Double')
     
    104103        WriteData(fid, prefix, 'object', self, 'fieldname', 'gcTriggerMaxSize', 'format', 'Double')
    105104        WriteData(fid, prefix, 'object', self, 'fieldname', 'tapeAlloc', 'format', 'Integer')
    106         # }}}
    107         #process dependent variables {{{
     105
     106        # Process dependent variables
    108107        num_dependent_objects = len(self.dependents)
    109108        WriteData(fid, prefix, 'data', num_dependent_objects, 'name', 'md.autodiff.num_dependent_objects', 'format', 'Integer')
     
    111110        if num_dependent_objects:
    112111            names = []
    113             indices = np.zeros(num_dependent_objects)
    114 
    115112            for i, dep in enumerate(self.dependents):
    116113                names.append(dep.name)
    117                 indices[i] = dep.index
    118114
    119115            WriteData(fid, prefix, 'data', names, 'name', 'md.autodiff.dependent_object_names', 'format', 'StringArray')
    120             WriteData(fid, prefix, 'data', indices, 'name', 'md.autodiff.dependent_object_indices', 'format', 'IntMat', 'mattype', 3)
    121             # }}}
    122         #process independent variables {{{
     116
     117        # Process independent variables
    123118        num_independent_objects = len(self.independents)
    124119        WriteData(fid, prefix, 'data', num_independent_objects, 'name', 'md.autodiff.num_independent_objects', 'format', 'Integer')
    125120
    126         if num_independent_objects:
    127             names = [None] * num_independent_objects
    128             types = np.zeros(num_independent_objects)
    129 
    130             for i, indep in enumerate(self.independents):
    131                 names[i] = indep.name
    132                 types[i] = indep.typetoscalar()
    133 
    134             WriteData(fid, prefix, 'data', names, 'name', 'md.autodiff.independent_object_names', 'format', 'StringArray')
    135             WriteData(fid, prefix, 'data', types, 'name', 'md.autodiff.independent_object_types', 'format', 'IntMat', 'mattype', 3)
    136             # }}}
    137         #if driver is fos_forward, build index:  {{{
     121        for indep in self.independents:
     122            WriteData(fid, prefix, 'data', indep.name, 'name', 'md.autodiff.independent_name', 'format', 'String')
     123            WriteData(fid, prefix, 'data', indep.typetoscalar(), 'name', 'md.autodiff.independent_type', 'format', 'Integer')
     124            WriteData(fid, prefix, 'data', indep.min_parameters, 'name','md.autodiff.independent_min_parameters','format', 'DoubleMat', 'mattype', 3)
     125            WriteData(fid, prefix, 'data', indep.max_parameters, 'name', 'md.autodiff.independent_max_parameters', 'format', 'DoubleMat', 'mattype', 3)
     126            WriteData(fid, prefix, 'data', indep.control_scaling_factor, 'name', 'md.autodiff.independent_scaling_factor', 'format', 'Double')
     127            WriteData(fid, prefix, 'data', indep.control_size, 'name', 'md.autodiff.independent_control_size', 'format', 'Integer')
     128
     129        # If driver is fos_forward, build index
    138130        if strcmpi(self.driver, 'fos_forward'):
    139131            index = 0
     
    149141                        index += indep.nods
    150142
    151             index -= 1  #get c - index numbering going
     143            index -= 1  # get c-index numbering going
    152144            WriteData(fid, prefix, 'data', index, 'name', 'md.autodiff.fos_forward_index', 'format', 'Integer')
    153             # }}}
    154         #if driver is fos_reverse, build index:  {{{
     145
     146        # If driver is fos_reverse, build index
    155147        if strcmpi(self.driver, 'fos_reverse'):
    156148            index = 0
     
    163155                    index += 1
    164156
    165             index -= 1  #get c - index numbering going
     157            index -= 1  # get c-index numbering going
    166158            WriteData(fid, prefix, 'data', index, 'name', 'md.autodiff.fos_reverse_index', 'format', 'Integer')
    167             # }}}
    168         #if driver is fov_forward, build indices:  {{{
     159
     160        # If driver is fov_forward, build indices
    169161        if strcmpi(self.driver, 'fov_forward'):
    170162            indices = 0
     
    180172                        indices += indep.nods
    181173
    182             indices -= 1  #get c - indices numbering going
     174            indices -= 1  # get c-indices numbering going
    183175            WriteData(fid, prefix, 'data', indices, 'name', 'md.autodiff.fov_forward_indices', 'format', 'IntMat', 'mattype', 3)
    184             # }}}
    185         #deal with mass fluxes:  {{{
     176
     177        # Deal with mass fluxes
    186178        mass_flux_segments = [dep.segments for dep in self.dependents if strcmpi(dep.name, 'MassFlux')]
    187179
     
    192184            flag = False
    193185        WriteData(fid, prefix, 'data', flag, 'name', 'md.autodiff.mass_flux_segments_present', 'format', 'Boolean')
    194         # }}}
    195         #deal with trace keep on: {{{
     186
     187        # Deal with trace keep on
    196188        keep = False
    197189
    198         #From ADOLC userdoc:
    199         # The optional integer argument keep of trace on determines whether the numerical values of all active variables are
    200         # recorded in a buffered temporary array or file called the taylor stack. This option takes effect if keep = 1 and
    201         # prepares the scene for an immediately following gradient evaluation by a call to a routine implementing the reverse
    202         # mode as described in the Section 4 and Section 5.
     190        # From ADOLC userdoc:
     191        # The optional integer argument keep of trace on determines whether the
     192        # numerical values of all active variables are recorded in a buffered
     193        # temporary array or file called the taylor stack. This option takes
     194        # effect if keep = 1 and prepares the scene for an immediately
     195        # following gradient evaluation by a call to a routine implementing the
     196        # reverse mode as described in the Section 4 and Section 5.
    203197        #
    204198        if len(self.driver) <= 3:
    205             keep = False  #there is no "_reverse" string within the driver string:
     199            keep = False  # there is no "_reverse" string within the driver string
    206200        else:
    207201            if strncmpi(self.driver[3:], '_reverse', 8):
  • TabularUnified issm/trunk-jpl/src/m/classes/independent.m

    r25551 r27744  
    6666                        fielddisplay(self,'name','variable name (must match corresponding String)');
    6767                        fielddisplay(self,'type','type of variable (''vertex'' or ''scalar'')');
    68                         fielddisplay(self,'nods','size of dependent variables');
     68                        fielddisplay(self,'nods','size of independent variables');
    6969                        fielddisplay(self,'control_size','number of timesteps');
    7070                        fielddisplay(self,'min_parameters','absolute minimum acceptable value of the inversed parameter on each vertex');
  • TabularUnified issm/trunk-jpl/src/m/classes/independent.py

    r24213 r27744  
    77
    88class independent(object):
    9     """
    10     INDEPENDENT class definition
     9    """independent class definition
    1110
    12        Usage:
    13           independent = independent()
     11    Usage:
     12        independent = independent()
    1413    """
    1514
     
    1716        self.name = ''
    1817        self.type = ''
    19         self.fos_forward_index = float('NaN')
     18        self.fos_forward_index = np.nan
    2019        self.fov_forward_indices = np.array([])
    2120        self.nods = 0
     21        self.min_parameters = np.nan
     22        self.max_parameters = np.nan
     23        self.control_scaling_factor = np.nan
     24        self.control_size = 0
    2225
    23     #set defaults
     26        # Set defaults
    2427        self.setdefaultparameters()
    2528
    26     #use provided options to change fields
     29        # Use provided options to change fields
    2730        options = pairoptions(*args)
    2831
    29     #OK get other fields
     32        # Get other fields
    3033        self = options.AssignObjectFields(self)
     34
     35        if self.control_size == 0:
     36            self.control_size = 1
    3137    # }}}
    3238
    3339    def __repr__(self):  # {{{
    34         s = "   independent variable:\n"
     40        s = '   independent variable:\n'
    3541
    36         s += "%s\n" % fielddisplay(self, 'name', "variable name (must match corresponding String)")
    37         s += "%s\n" % fielddisplay(self, 'type', "type of variable ('vertex' or 'scalar')")
     42        s += '{}\n'.format(fielddisplay(self, 'name', 'variable name (must match corresponding String)'))
     43        s += '{}\n'.format(fielddisplay(self, 'type', 'type of variable (\'vertex\' or \'scalar\')'))
     44        s += '{}\n'.format(fielddisplay(self, 'nods', 'size of independent variables'))
     45        s += '{}\n'.format(fielddisplay(self, 'control_size', 'number of timesteps'))
     46        s += '{}\n'.format(fielddisplay(self, 'min_parameters', 'absolute minimum acceptable value of the inversed parameter on each vertex'))
     47        s += '{}\n'.format(fielddisplay(self, 'max_parameters', 'absolute maximum acceptable value of the inversed parameter on each vertex'))
     48        s += '{}\n'.format(fielddisplay(self, 'control_scaling_factor', 'order of magnitude of each control (useful for multi-parameter optimization)'))
    3849        if not np.isnan(self.fos_forward_index):
    39             s += "%s\n" % fielddisplay(self, 'fos_forward_index', "index for fos_foward driver of ADOLC")
     50            s += '{}\n'.format(fielddisplay(self, 'fos_forward_index', 'index for fos_foward driver of ADOLC'))
    4051        if np.any(np.logical_not(np.isnan(self.fov_forward_indices))):
    41             s += "%s\n" % fielddisplay(self, 'fov_forward_indices', "indices for fov_foward driver of ADOLC")
     52            s += '{}\n'.format(fielddisplay(self, 'fov_forward_indices', 'indices for fov_foward driver of ADOLC'))
    4253
    4354        return s
     
    4556
    4657    def setdefaultparameters(self):  # {{{
    47         #do nothing
     58        # Do nothing
    4859        return self
    4960    # }}}
     
    5263        if not np.isnan(self.fos_forward_index):
    5364            if not strcmpi(driver, 'fos_forward'):
    54                 raise TypeError("cannot declare an independent with a fos_forward_index when the driver is not fos_forward!")
     65                raise TypeError('cannot declare an independent with a fos_forward_index when the driver is not fos_forward!')
    5566            if self.nods == 0:
    56                 raise TypeError("independent checkconsistency error: nods should be set to the size of the independent variable")
     67                raise TypeError('independent checkconsistency error: nods should be set to the size of the independent variable')
    5768
    5869        if len(self.fov_forward_indices) > 0:
    5970            if not strcmpi(driver, 'fov_forward'):
    60                 raise TypeError("cannot declare an independent with fov_forward_indices when the driver is not fov_forward!")
     71                raise TypeError('cannot declare an independent with fov_forward_indices when the driver is not fov_forward!')
    6172            if self.nods == 0:
    62                 raise TypeError("independent checkconsistency error: nods should be set to the size of the independent variable")
    63             md = checkfield(md, 'fieldname', "autodiff.independents[%d].fov_forward_indices" % i, '>=', 1, '<=', self.nods)
     73                raise TypeError('independent checkconsistency error: nods should be set to the size of the independent variable')
     74            md = checkfield(md, 'fieldname', 'autodiff.independents[%d].fov_forward_indices' % i, '>=', 1, '<=', self.nods)
    6475
    6576        return md
     
    6879    def typetoscalar(self):  # {{{
    6980        if strcmpi(self.type, 'scalar'):
    70             scalar = 0
     81            scalartype = 0
    7182        elif strcmpi(self.type, 'vertex'):
    72             scalar = 1
     83            scalartype = 1
     84        elif strcmpi(self.type, 'matrix'):
     85            scalartype = 1
     86        else:
     87            raise TypeError('{} not supported yet!'.format(self.type))
    7388
    74         return scalar
     89        return scalartype
    7590    # }}}
Note: See TracChangeset for help on using the changeset viewer.