# base.variants module¶

class base.variants.Variant(candidate, app_method, error_bounds)

Bases: object

This class represents a specific version of an approximated candidate.

Variants are used to synthesize approximated circuits by replacing the Candidates’ original Variants with approximated Variants.

Parameters: candidate (Candidate) – The Candidate this Variant belongs to. app_method (ApproxMethod) – An ApproxMethod instance that is used to generate the approximated circuit file specified by this Variant’s quality constraints. error_bounds (Dictionary) – A dictionary containing ErrorMetric IDs as keys and error value bounds as values.
id

A unique string identifying this Variant. It is generated using the Candidate’s ID and this Variant’s quality constraints.

Type: str
candidate
path

The absolute path to the directory in which the Variant files of this Variant’s Candidate are stored, i.e. the directory in which this Variant’s files are probably stored.

Type: str
file_name

The absolute path to this Variant’s circuit file without file extension.

Type: str
file_verilog

The absolute path to this Variant’s Verilog circuit file.

Type: str
file_blif

The absolute path to this Variant’s Blif circuit file.

Type: str
app_method
error_bounds
hasErrorMetric(err_id)

Returns whether an ErrorMetric with the given ID is in this Variant’s error bounds.

Parameters: err_id (str) – The ID of the desired ErrorMetric type. True if an ErrorMetric of the type with the given ID err_id is contained in this Variant’s error_bounds attribute, otherwise False.
generateChildren()

Returns a list of Variants so that for each approximation method and error metric there is exactly one Variant where either exactly one error bound is increased by one step or the approximation method is different. The error bounds of the metrics are not increased beyond their maximum value and approximation methods are chosen from this Variant’s Candidate.

generateParents()

Returns a list of Variants so that for each approximation method and error metric there is exactly one Variant where either exactly one error bound is decreased by one step or the approximation method is different. The error bounds of the metrics are not decreased beyond their minimum value and approximation methods are chosen from this Variant’s Candidate.

generateNeighbors()

Returns a list of Variants so that for each approximation method there is exactly one Variant with another approximation method and for each error metric there are two Variants where the error bound is increased or decreased by one step. The error bounds are not increased beyond their maximum value and not decreased beyond their minimum value. Approximation methods are chosen from this Variant’s Candidate.

static generateVariantFromConfiguration(cand, conf)

Generates a Variant instance of a Candidate based on a configuration string that specifies error metric values and/or the approximation method. Each non-specified setting will be set as for the Candidate’s original Variant.

Parameters: cand (Candidate) – The Candidate instance of which to create a Variant. conf (str) – A configuration string specifying the new Variant’s quality constraints and/or approximation methods. It consists of semicolon separated key=value pairs where key is either the key word ApproxMethod or the ID of an ErrorMetric and value is the ID of an ApproxMethod or an error value as upper bound. Example ApproxMethod=PS; BF=2
class base.variants.VariantSet(cand_set)

Bases: object

Globally accessible data structure storing all approximated Variants.

Parameters: cand_set (CandidateSet) – The framework’s final CandidateSet instance.
path

The absolute path to the directory in which the Variant files are stored.

Type: str
append(variant)

Adds a Variant to the set. Same semantics as list.append().

Parameters: variant (Variant) – A Variant instance to be added to the set.
extend(variants)

Adds a list of Variants to the set. Same semantics as list.extend().

Parameters: variants (list of Variant) – A list of Variant instances to be added to the set.
findVariant(variant)

Returns True if and only if the given Variant is contained in this VariantSet.