Counters

OptimizationModels.CounterType
Counter

A counter for partial evaluations of typical quantities used in solving optimization problems. These counters can be used in a number of contexts:

  • Block Selection: For evaluations of objective information (e.g., objective functions, gradient functions, etc.) that only make use of a subset of the parameters.
  • Batch Selection: For evaluations of objective information (e.g., objective fucntions, gradient functions, etc.) that is written as the sum of multiple components, but only a subset of the components are used.
  • Block and Batch Selection: Simultaneously doing both of the above situations.

Fields

  • block_total::Int64, the number of parameters
  • batch_total::Int64, the number of additive terms in the objective function
  • block_equivalent::Float64, the equivalent number of batch_total evaluations given a certain number of coordinate evaluations
  • batch_equivalent::Float64, the equivalent number of block_total evaluations given evaluations of objective information using only a subset of the additive terms.

Constructor(s)

Counter(;block_total::Int64=1, batch_total::Int64=1)

Creates a Counter object with block_equivalent and batch_equivalent set to zero. The optional block_total and batch_total are set to 1.

source

Incrementing Counters

OptimizationModels.increment!Function
increment!(counter::Counter; batch_size::Int64=0, block_size::Int64=0)

Increments the counter.block_equivalent and counter.batch_equivalent by block_size/counter.block_total and batch_size/counter.batch_total.

source

Resetting Counters

Validating Counters

Allowed counters are defined within the module as an element of

[
    :obj, 
    :grad, 
    :hess, 
    :residual,
    :jacobian,
]

The following function can be used to validate a dictionary of counters.

OptimizationModels.validate_countersFunction
validate_counters(counters::Dict{Symbol, Counter})

Validates that counter names are in the allowable list. Throws an error if the list is invalid. Returns nothing if valid.

source

Printing

Counters and dictionaries of counters can be printed using the print or println functions.