core sub-package modules

Main Program (skpar.core.skpar)

Main environment of SKPAR

class skpar.core.skpar.SKPAR(infile='skpar_in.yaml', verbose=True)[source]

Bases: object

The main executable object.

Input handler (skpar.core.input)

Routines to handle the input file of skpar

skpar.core.input.get_config(userinp, report=True)[source]

Parse the arguments of ‘config’ key in user input

skpar.core.input.get_input(filename)[source]

Read input; Exception for non-existent file.

skpar.core.input.parse_input(filename, verbose=True)[source]

Parse input filename and return the setup

Tasks (skpar.core.tasks)

Tasks module, defining relevant classes and functions

class skpar.core.tasks.Task(name, func, fargs)[source]

Bases: object

Generic wrapper over functions or executables.

skpar.core.tasks.check_taskdict(tasklist, taskdict)[source]

Check task names are in the task dictionary; quit otherwise.

skpar.core.tasks.get_tasklist(userinp)[source]

Return a list of tuples of task names and task arguments.

skpar.core.tasks.initialise_tasks(tasklist, taskdict, report=False)[source]

Transform a tasklist into a list of callables as per taskdict.

Parameters:
  • tasklist (list) – a list of (task-name, user-arguments) pairs
  • taskdict (dict) – a dictionary mapping task names to actual functions
Returns:

callable objects, instances of Task class

Return type:

tasks(list)

Task Dictionary (skpar.core.taskdict)

Dictionary with default tasks and their underlying functions.

class skpar.core.taskdict.PlotTask(func, plotname, objectives, abscissa_key=None, **kwargs)[source]

Wrapper for skparplot; extracts data from objectives prior to plotting.

This is a callable object that plots to file the model and reference data associated with one or more objectives. The model and reference data constitute the Y-coordinates (ordinates). The X-coordinates (abscissas) are potentially held in a separate field of the model data dictionary, and implicitly it is assumed that the X-coordinates of the reference data are the same (else the model-vs-reference comparison would make no sense). The fundamental concept is that we want to visualise our objectives. So the ordinate can be obtained by the user’s stating which objectives is to be visualised. The challenge is that a definition of objective contains no info about the abscissa, so it has to be explicitly specified by the user or else the default indexing of the reference or model data items will be used as abscissa. The whole mechanism must work with the simplest possible (default) plotting routine, as well as with a more specialised plotter object. The initialisation of the PlotTask should establish what dictionary items are to be plotted as abscissas and ordinates and from which model dictionary, and how the latter are matched to the corresponding reference data. Note however, that objectives may not be visible at the time the task is initialised. So at init time, we merely record the user’s directions. Later – at call time – we do the data queries and call the plot function with the latest model data.

pick_objectives(objectives, database)[source]

Get the references corresponding to the objective tags.

This function acquired the reference data that must be plotted, by analysing the objectives referred to in the definition of the plot task. It is not called within the init of the plot task itself, since at the time the plot task is being declared, the objectives may not yet be. So a separate agency is suppoosed to call this method once both objectives and task are declared. Currently this happens within input.py – at the end of processing of the input file.

skpar.core.taskdict.execute(implargs, database, cmd, workdir='.', outfile='run.log', purge_workdir=False, **kwargs)[source]

Execute external command in workdir, streaming output/error to outfile.

Parameters:
  • implargs (dict) – caller environment variables
  • database (dict-like) – not used, but needed to maintain a task-signature
  • cmd (str) – command; executed in implargs[‘workroot’]+workir; if it contains $ or *-globbing, these are shell-expanded
  • workdir (path-like) – execution directory relative to workroot
  • outfile (str) – output file for the stdout/stderr stream; continuously updated during execution
  • purge_workdir (bool) – if true, any existing working directory is purged
  • kwargs (dict) – passed directly to the underlying subprocess.call()
Returns:

None

Raises:
  • OSError – if cmd cannot be executed
  • RuntimeError – if cmd returncode is nonzero
  • SubprocessError – other possible circumstances
skpar.core.taskdict.get_model_data(implargs, database, item, source, model, rm_columns=None, rm_rows=None, scale=1.0, **kwargs)[source]

Get data from file and put it in a database under a given key.

Use numpy.loadtxt to get the data from source file and write the data to database under dst.`key` field. If dst does not exist, it is created. All kwargs are directly passed to numpy.loadtxt. Additionally, some post-processing can be done (removing rows or columns and scaling).

Parameters:
  • implargs (dict) – dictionary of implicit arguments from caller
  • database (object) – must support dictionary-like get/update()
  • source (str) – file name source of data; path relative to implargs[workroot]
  • model (str) – model name to be updated in database
  • key (str) – key under which to store the data in under dst
  • rm_columns – [ index, index, [ilow, ihigh], otherindex, [otherrange]]
  • rm_rows – [ index, index, [ilow, ihigh], otherindex, [otherrange]]
  • scale (float) – multiplier of the data
skpar.core.taskdict.parse_cmd(cmd)[source]

Parse shell command for globbing and environment variables.

skpar.core.taskdict.prepare_for_plotsave(iteration, filename)[source]

Ensure directory of filename exists and embed iteration number

skpar.core.taskdict.substitute_parameters(implargs, database, templatefiles, **kwargs)[source]

Substitute parameters (within implicit arguments) in given templates.

skpar.core.taskdict.wrapper_PlotTask(env, database, *args, **kwargs)[source]

Wrapper around the legacy PlotTask

Objectives (skpar.core.objectives)

Classes and functions related to the:

  • parsing the definition of objectives in the input file,
  • setting the objectives for the optimizer, and,
  • evaluation of objectives.
class skpar.core.objectives.ObjBands(spec, **kwargs)[source]

Bases: skpar.core.objectives.Objective

get(database)[source]

Return the value of the objective function.

class skpar.core.objectives.ObjKeyValuePairs(spec, **kwargs)[source]

Bases: skpar.core.objectives.Objective

get(database)[source]

Return the corresponding model data, reference data, and sub-weights. This method must be overloaded in a child-class if a more specific way to yield the model data in required.

class skpar.core.objectives.ObjValues(spec, **kwargs)[source]

Bases: skpar.core.objectives.Objective

get(database)[source]

Get the model data, align/mask it etc, and return calculated cost.

class skpar.core.objectives.ObjWeightedSum(spec, **kwargs)[source]

Bases: skpar.core.objectives.Objective

get(database)[source]
class skpar.core.objectives.Objective(spec, **kwargs)[source]

Bases: object

Decouples the declaration of an objective from its evaluation.

Objectives are declared by human input data that defines:
  • reference data,
  • models - from which to obtain model data, and possibly model weights,
  • query - the way to obtaining data
  • model weights - relative contribution factor of each model,
  • options, e.g. to specify sub-weights of individual reference items,
  • relative weight of the objective, in the context of multi-objective optimisation.

Instances are callable, and return a triplet of model data, reference data, and sub-weights of relative importance of the items within each data.

evaluate(database=None)[source]

Evaluate objective, i.e. fitness of the current model against the reference.

get()[source]

Return the corresponding model data, reference data, and sub-weights. This method must be overloaded in a child-class if a more specific way to yield the model data in required.

summarise()[source]
skpar.core.objectives.get_models(models)[source]

Return the models (names) and corresponding weights if any.

Parameters:(str, list of str, list of [str (models) – float] items): The string is always a model name. If [str: float] items are given, the float has the meaning of weight, associated with the model.
Returns:
(model_names, model_weights). Weights
are set to 1.0 if not found in models. Elements of the tuple are lists if models is a list.
Return type:tuple
skpar.core.objectives.get_objective(spec, **kwargs)[source]

Return an instance of an objective, as defined in the input spec.

Parameters:spec (dict) – a dictionary with a single entry, being query: {dict with the spec of the objective}
Returns:
an instance of the Objective sub-class, corresponding
an appropriate objective type.
Return type:list
skpar.core.objectives.get_refdata(data)[source]

Parse the input data and return a corresponding array.

Parameters:data (array or array-like, or a dict) – Data, being the reference data itself, or a specification of how to get the reference data. If dictionary, it should either contain key-value pairs of reference items, or contain a ‘file’ key, storing the reference data.
Returns:
an array of reference data array, subject to all loading
and post-processing of a data file, or pass data itself, transforming it to an array as necessary.
Return type:array
skpar.core.objectives.get_refval(bands, align, ff={'max': <function amax>, 'min': <function amin>})[source]

Return a reference (alignment) value selected from a 2D array.

Parameters:
  • bands (2D numpy array) – data from which to obtain a reference value.
  • align – specifier that could be (band-index, k-point), or (band-index, function), e.g. (3, ‘min’), or (‘7, ‘max’)
  • ff (dict) – Dictionary mapping strings names to functions that can operate on an 1D array.
Returns:

the selected value

Return type:

value (float)

skpar.core.objectives.get_refval_1d(array, align, ff={'max': <function amax>, 'min': <function amin>})[source]

Return a reference (alignment) value selected from an array.

Parameters:
  • array (1D numpy array) – data from which to obtain a reference value.
  • align – specifier that could be and index, e.g. 3, or ‘min’, ‘max’
  • ff (dict) – Dictionary mapping string names to functions that can operate on an 1D array.
Returns:

the selected value

Return type:

value (float)

skpar.core.objectives.get_subset_ind(rangespec)[source]

Return an index array based on a spec – a list of ranges.

skpar.core.objectives.get_type(n_models, ref, dflt_type='values')[source]

Establish the type of objective from attributes of reference and models.

skpar.core.objectives.parse_weights(spec, refdata=None, nn=1, shape=None, i0=0, normalised=True, ikeys=None, rikeys=None, rfkeys=None)[source]

Parse the specification defining weights corresponding to some data.

The data may or may not be specified, depending on the type of specification that is provided. Generally, the specification would enumerate either explicit indexes in the data, or a range of indexes in the data or a range of values in the data, and would associate a weight with the given range. A list of floats is also accepted, and an array view is returned, for cases where weights are explicitly enumerated, but no check for length.

To give freedom of the user (i.e. the caller), the way that ranges are specified is enumerated by the caller by optional arguments – see ikeys, rikeys and rfkeys below.

Parameters:
  • spec (array-like or dict) –

    values or specification of the subweights, for example:

    spec = dflt: 1.0 # default value of subweights indexes: # explicit [index, weight] for 1d-array data

    • [0, 1]
    • [4, 4]
    • [2, 1]
    ranges: # ranges for 1d-array
    • [[1,3], 2]
    • [[3,4], 5]
    bands: # ranges of bands (indexes) in bands (refdata)
    • [[-3, 0], 1.0] # all valence bands
    • [[0, 1], 2.0] # top VB and bottom CB with higher weight
    values: # ranges of energies (values) in bands (refdata)
    • [[-0.1, 0.], 4.0]
    • [[0.2, 0.5], 6.0]
    indexes: # explicit (band, k-point) pair (indexes) for bands (refdata)
    • [[3, 4], 2.5]
    • [[1, 2], 3.5]
  • refdata (numpy.array) – Reference data; mandatory only when range of values must be specified
  • nn (int) – length of refdata (and corresponding weights)
  • shape (tuple) – shape of reference data, if it is array but not given
  • i0 (int) – index to be assumed as a reference, i.e. 0, when enumerating indexes explicitly or by a range specification.
  • ikeys (list of strings) – list of keys to be parsed for explicit index specification, e.g. [‘indexes’, ‘Ek’]
  • rikeys (list of strings) – list of keys to be parsed for range of indexes specification, e.g. [‘ranges’, ‘bands’]
  • rfkeys (list of strings) – list of keys to be parsed for range of values specification, e.g. [‘values’, ‘eV’]
Returns:

the weight to be associated with each data item.

Return type:

numpy.array

skpar.core.objectives.parse_weights_keyval(spec, data, normalised=True)[source]

Parse the weights corresponding to key-value type of data.

Parameters:
  • spec (dict) –

    Specification of weights, in a key-value fashion. It is in the example format:

    { 'dflt': 0., 'key1': w1, 'key3': w3}
    

    with w1, w3, etc. being float values.

  • data (structured numpy array) –

    Data to be weighted.

    Typical way of obtaining data in this format is to use:

    loader_args = {'dtype': [('keys', 'S15'), ('values', 'float')]}
    data = numpy.loadtxt(file, **loader_args)
    
Returns:

weights corresponding to each key in data,

with the same length as data.

Return type:

numpy.array

skpar.core.objectives.set_objectives(spec, verbose=True, **kwargs)[source]

Parse user specification of Objectives, and return a list of Objectives for evaluation.

Parameters:spec (list) – List of dictionaries, each dictionary being a, specification of an objective of a recognised type.
Returns:
a List of instances of the Objective sub-class, each
corresponding to a recognised objective type.
Return type:list

Query (skpar.core.query)

Evaluator (skpar.core.evaluate)

Evaluator engine of SKPAR.

class skpar.core.evaluate.Evaluator(objectives, tasklist, taskdict, parameternames, config=None, costf=<function cost_rms>, utopia=None, verbose=False)[source]

Bases: object

Evaluator

The evaluator is the only thing visible to the optimiser. It has several things to do:

  1. Accept a list of parameter values (or key-value pairs), and an iteration number (or a tuple: (e.g. generation,particle_index)).
  2. Update tasks (and underlying models) with new parameter values.
  3. Execute the tasks to obtain model data with the new parameters.
  4. Evaluate fitness for individual objectives.
  5. Evaluate global fitness (cost) and return the value. It may be good to also return the max error, to be used as a stopping criterion.
evaluate(parametervalues, iteration=None)[source]

Evaluate the global fitness of a given point in parameter space.

This is the only object accessible to the optimiser, therefore only two arguments can be passed.

Parameters:
  • parametervalues (list) – current point in design/parameter space
  • iteration – (int or tupple): current iteration or current generation and individual index within generation
Returns:

global fitness of the current design point

Return type:

fitness (float)

skpar.core.evaluate.abserr(ref, model)[source]

Return the per-element difference model and reference.

skpar.core.evaluate.cost_rms(ref, model, weights, errf=<function abserr>)[source]

Return the weighted-RMS deviation

skpar.core.evaluate.create_workdir(workdir, templatedir)[source]

Create a new and clean work directory tree from template

skpar.core.evaluate.destroy_workdir(workdir)[source]

Remove the entire work directory tree

skpar.core.evaluate.eval_objectives(objectives, database)[source]

Evaluate fitness/cost

skpar.core.evaluate.get_workdir(iteration, workroot)[source]

Find what is the root of the work-tree at a given iteration

skpar.core.evaluate.relerr(ref, model)[source]

Return the per-element relative difference between model and reference.

To handle cases where ref vanish, and possibly model vanish at the same time, we:

  • translate directly a vanishing absolute error into vanishing relative error (where both ref and model vanish.
  • take the model as a denominator, thus yielding 1, where ref vanishes but model is non zero

Optimiser (skpar.core.optimise)

Defines a wrapper around user selectable optimisation engines.

class skpar.core.optimise.Optimiser(algo, parameters, evaluate, options=None, verbose=True)[source]

Bases: object

Wrapper for different optimization engines.

report(*args, **kwargs)[source]

Report optimiser state.

skpar.core.optimise.get_optargs(userinp)[source]

Parse user input for optimisation related arguments.

Parameters (skpar.core.parameters)

*Parameters*

Module for handling parameters in the context of optimisation.

The following assumptions are made:

  • parameters have no meaning to the optimiser engine
  • for the optimiser, parameters are just a list of values to be manipulated
  • the user must create an OrderedDict of parameter name:value pairs; the OrderedDict eliminates automatically duplicate definitions of parameters, yielding the minimum possible number of degrees of freedom for the optimiser
  • the OrderedDictionary is built by parsing an skdefs.template file that contains parameter-strings (conveying the name, initial value and range).
  • skdefs.template is parsed by functions looking for a given format from which parameter-strings are extracted
  • the Class Parameter is initialised from a parameter-string.
  • a reduced skdefs.template is obtained, by removing the initial value and range from the input skdefs.template which is ready for creating the final skdefs file by string.format(dict(zip(ParNames,Parvalues)) substitution.
class skpar.core.parameters.Parameter(string, **kwargs)[source]

Bases: object

A parameter object, that is initialised from a string.

ParameterName InitialValue MinValue Maxvalue [ParameterType] ParameterName MinValue Maxvalue [ParameterType] ParameterName InitialValue [ParameterType] ParameterName [ParameterType]

ParameterName must be alphanumeric, allowing _ too. Iinit/Min/MaxValue can be integer or float ParameterType is optional (float by default), and indicated by either ‘i’(int) or ‘f’(float) White space separation is mandatory.

typedict = {'f': <class 'float'>, 'i': <class 'int'>}
skpar.core.parameters.get_parameters(userinp)[source]

Parse user input for definitions of parameters.

The definitions should be of the form (‘name’, ‘optionally_something’). The optional part could in principle be one or more str/float/int.

skpar.core.parameters.substitute_template(parameters, parnames, templatefile, resultfile)[source]

Substitute a template with actual parameter values.

Parameters:
  • parameters (list) – Parameter list, items being either floats or objects with .value and .name attributes.
  • parnames (list) – If parameters is a list of floats, then parnames is the list of corresponding names.
  • templatefile (str) – Name of template file with substitution patterns.
  • resultfile (str) – Name of file to contain the substituted result.
skpar.core.parameters.update_parameters(workroot, templates, parameters, parnames=None)[source]

Update relevant templates with new parameter values.

Parameters:
  • workroot (str) – Root working directory, template names are relative to this directory.
  • templates (list) – List of ascii filenames containing placeholders for inserting parameter values. The place holders must follow the old string formatting of Python: %(ParameterName)ParameterType.
  • parameters (list) – Either a list of floats, or a list of objects (each having .value and .name attributes)
  • parnames (list) – If parameters is a list of floats, then parnames is the list of corresponding names.
skpar.core.parameters.update_template(template, pardict)[source]

Makes variable substitution in a template.

Parameters:
  • template (str) – Template with old style Python format strings.
  • pardict (dict) – Dictionary of parameters to substitute.
Returns:

String with substituted content.

Return type:

str

PSO (skpar.core.pso)

Particle Swarm Optimizer (PSO)

Particles

In PSO, a particle represents a set of parameters to be optimised. Each parameter is therefore a degree of freedom of the particle. Each particle is represented by its coordinate value. Additionally it needs several attributes:

  • fitness – the quality of the set of parameters
  • speed – how much the position of the particle changes from one generation to the next
  • smin/smax – speed limits (observed only initially, in the current implementation)
  • best – particles own best position (i.e. with best fitness)

Particle normalisaton/re-normalisation

Additionally to the above generic PSO-related attributes, we need to introduce position normalisation as follows. The parameters giving the particle coordinates may be with different physical meaning, magnitudes and units. However, to keep the PSO generic, it is best to impose identical scale in each dimension, so that particle range is the same in each direction. This is achieved by normalising the parameters so that the particle position in each dimension is between -1 and +1. However, when evaluating the fitness of the particle, we need the renormalized values (i.e. the true values of the parameters).

Hence we introduce three additional attributes:

  • norm – a list with the scaling factors for each dimension (\(\eta\)),
  • shift – offset of the parameter range from 0 (\(\sigma\)),
  • renormalized – the true value of the parameters (\(\lambda\)) represented by the particle.

The user must supply only the true range of the particle in the form of a tuple, per dimension, e.g. \((\lambda_{min}, \lambda_{max})\).

Then \((\lambda_{max}-\lambda_{min})\eta = 2.0\), or, \(\eta = 2.0/(\lambda_2-\lambda_1)\), and \(\sigma = 0.5*(\lambda_{max}+\lambda_{min})\).

So, the true particle position (for evaluations) is \(\lambda = P/\eta + \sigma\), where \(P\) is the normalised position of the particle.

## Using particles

Below, we have the declaration of the particle class and a couple of methods for creation and evolution of the particle based on the PSO algorithm.

Note that the evaluation of the fitness of the particle is problem specific and the user must supply its own evaluation function and register it under the name evaluate with the toolbox.

Particle Swarm

The swarm is a a list of particles, with a couple of additional attributes:

  • gbest – globally the best particle (position) ever (i.e. accross any generation so far)
  • gbestfit – globally the best fitness (i.e. the quality value of gbest)

The swarm is declared, created and let to evolve with the help of the PSO class.

class skpar.core.pso.PSO(parameters, evaluate, npart=10, ngen=100, objective_weights=(-1, ), ErrTol=0.001, *args, **kwargs)[source]

Bases: object

Class defining Particle-Swarm Optimizer.

halloffame = <deap.tools.support.HallOfFame object>
nBestKept = 10
optimise(ngen=None, ErrTol=None)[source]

Let the swarm evolve for ngen (or self.ngen) generations.

pAcceleration = 2.9922
pInertia = 0.7298
report()[source]
toolbox = <deap.base.Toolbox object>
skpar.core.pso.createParticle(prange, strict_bounds=True)[source]

Create particle of dimensionality len(prange), assigning initial particle coordinate in the i-th dimension within the prange[i] tuple. Note that the range is normalised and shifted, so that the result is a coordinate within -1 to 1 for each dimension, and initial speed between -.5 and +.5. To get the true (i.e. physical) coordinates of the particle, one must use part.renormalized field. :param prange – list of tuples. each tuple is a range of _initial_ coord.:

Returns:
particle – an instance of the Particle class, with initialized coordinates both
normalized (the instance itself) and true, physical coords (self.renormalized).
skpar.core.pso.declareTypes(weights)[source]

Declare Particle class with fitting objectives (-1: minimization; +1 maximization). Each particle consists of a set of normalised coordinates, returned by the particle’s instance itself. The true (physical) coordinates of the particle are stored in the field ‘renormalized’. The field ‘best’ contains the best fitness-wise position that the particle has ever had (in normalized coords). Declare also Swarm class; inherit from list + PSO specific attributes gbest and gbestfit. :param weights – tupple, e.g.: (+1,+0.5) for two objective maximization, etc. :type weights – tupple, e.g.: -1,

skpar.core.pso.evolveParticle(part, best, inertia=0.7298, acceleration=2.9922, degree=2)[source]

A method to update the position and speed of a particle (part), according to the generalized formula of Eq(3) in J.Kennedy, “Particle Swarm Optimization” in “Encyclopedia of Machine Learning” (2010), which is equivalent to Eqs(3-4) of ‘Particle swarm optimization: an overview’. Swarm Intelligence. 2007; 1: 33-57. :param * part – instance of the particle class, the particle to be updated: :param * best – the best known particle ever: :type * best – the best known particle ever: within the life of the swarm :param * inertia – factor scaling the persistence of the particle: :param * acceleration – factor scaling the influence of particle connection: :param * degree – unused right now; should serve for a fully informed particle swarm: :type * degree – unused right now; should serve for a fully informed particle swarm: FIPS :param but this requires best to become a list of neighbours best;: :param also u1,u2 and v_u1, v_u2 should be transformed into a Sum over neighbours:

Returns the updated particle

skpar.core.pso.evolveParticle_0(part, best, phi1=2, phi2=2)[source]

This is the implementation shown in the examples of the DEAP library. The inertial factor is 1.0 (implicit) and seems to be too big. Phi1/2 are also somewhat bigger than the Psi/Ki resulting from the optimal Psi = 2.9922 A method to update the position and speed of a particle (part), according to the original PSO algorithm of Ricardo Poli, James Kennedy and Tim Blackwell, ‘Particle swarm optimization: an overview’. Swarm Intelligence. 2007; 1: 33-57. :param part – instance of the particle class, the particle to be updated: :param best – the best known particle ever: :type best – the best known particle ever: within the life of the swarm :param phi1,phi2 – connectivity coefficients:

skpar.core.pso.pformat(part)[source]

Return a formatted string for printing all particle info.

skpar.core.pso.pso_args(**kwargs)[source]
skpar.core.pso.report_stats(stats)[source]

Utilities (skpar.core.utils)

skpar.core.utils.arr2s(aa, precision=3, suppress_small=True, max_line_width=75)[source]

Helper for compact string representation of numpy arrays.

skpar.core.utils.configure_logger(name, filename='skpar.log', verbosity=20)[source]

Get parent logger: logging INFO on the console and DEBUG to file.

skpar.core.utils.f2prange(rng)[source]

Convert fortran range definition to a python one.

Parameters:rng (2-sequence) – [low, high] index range boundaries, inclusive, counting starts from 1.
Returns:(low-1, high)
Return type:2-tuple
skpar.core.utils.flatten(dd)[source]

Take a dictionary or list of dictionaries/lists dd, and produce a lists of values corresponding, dropping the keys.

skpar.core.utils.flatten_two(d1, d2)[source]

Take two dictionaries or lists of dictionaries/lists d1 and d2, and produce two lists of values corresponding to the keys/order in d1. d2 is optional. Assume that the keys of d1 are a subset of the keys of d2. Assume nesting, i.e. some of the items in d1 are dictionaries and some are lists, numpy arrays, or a non-sequence type. The assumption is again: nested dictionaries in d2 must have at least the keys of the corresponding nested dictionaries in d1, and the lists in d1 must be no shorter than the lists in d2. …some assertions may help here…

skpar.core.utils.get_logger(name, filename=None, verbosity=20)[source]

Return a named logger with file and console handlers.

Get a name-logger. Check if it is(has) a parent logger. If parent logger is not configured, configure it, and if a child logger is needed, return the child. The check for parent logger is based on name: a child if it contains ‘.’, i.e. looking for ‘parent.child’ form of name. A parent logger is configured by defining a console handler at verbosity level, and a file handler at DEBUG level, writing to filename.

skpar.core.utils.get_ranges(data)[source]

Return list of tuples ready to use as python ranges.

Parameters:data (int, list of int, list of lists of int) – A single index, a list of indexes, or a list of 2-tuple range of indexes in Fortran convention, i.e. from low to high, counting from 1, and inclusive
Returns:list of lists of 2-tuple ranges, in Python convention - from 0, exclusive.
skpar.core.utils.is_monotonic(x)[source]
skpar.core.utils.islistoflists(arg)[source]

Return True if item is a list of lists.

skpar.core.utils.normalise(a)[source]

Normalise the given array so that sum of its elements yields 1.

Parameters:a (array) – input array
Returns:The norm is the sum of all elements across all dimensions.
Return type:a/norm (array)
skpar.core.utils.normaliseWeights(weights)[source]

normalise weights so that their sum evaluates to 1