base.candidates module¶
-
class
base.candidates.
Candidate
(name, variants_path, orig_var, quality_constraints, app_methods)¶ Bases:
abc.ABC
Abstract Base Class for approximation candidate.
Stores all static information about a candidate in the original circuit that is to be approximated.
Parameters: - name (str) – The Candidate’s name used primarily for identification. Should be human-readable (e.g. module name if candidate is a module). name and type are used to create a unique identifier for the Candidate.
- variants_path (str) – Path to the directory in which the Candidate’s variant files will be stored.
- orig_var (
Variant
) – The Candidate’s initial instance from the input design. - quality_constraints (list of
ErrorMetric
) – A list of ErrorMetrics specifying the error metrics and bounds to be used when approximating the Candidate. - app_methods (list of
ApproxMethod
) – A list of ApproxMethods to execute the approximation of the Candidate.
Inheriting classes must implement the following methods:
-
__init__
()¶
-
generateOriginalVariant
()¶
Default implementations are provided for
-
hasApproxMethod
()¶
-
hasErrorMetric
()¶
-
getErrorMetric
()¶
-
__repr__
()¶
-
__str__
()¶
It is recommended to use the default implementations unless special behavior of these methods is required.
-
static
getTypeStr
()¶ Returns the Candidate type’s unique ID string.
-
name
¶ The Candidate’s name used primarily for identification.
Type: str
-
id
¶ Unique identifier of the Candidate; is generated from type ID and name attribute automatically.
Type: str
-
variants_path
¶ Path to the directory in which the Candidate’s variant files will be stored.
Type: str
-
orig_var
¶ The Candidate’s initial instance from the input design.
Type: Variant
-
quality_constraints
¶ A list of ErrorMetrics specifying the error metrics and bounds to be used when approximating this Candidate.
Type: list of ErrorMetric
-
app_methods
¶ A list of ApproxMethods to execute the approximation of the Candidate.
Type: list of ApproxMethod
-
pis
¶ A list of the Candidate’s primary inputs represented by Signal instances.
Type: ‘list’ of Signal
-
appendPi
(pi)¶ Appends a Signal to the list of primary inputs.
Parameters: pi ( Signal
) – A Signal instance representing a primary input of this Candidate.
-
pos
¶ A list of the Candidate’s primary outputs represented by Signal instances.
Type: ‘list’ of Signal
-
appendPo
(po)¶ Appends a Signal to the list of primary outputs.
Parameters: po ( Signal
) – A Signal instance representing a primary output of this Candidate.
-
generateOriginalVariant
(gen_info) Creates and returns the first Variant of this Candidate.
The original Variant’s error bounds will have the default values of this Candidate’s error metrics and its approximation method will be the first one on this Candidate’s app_methods list.
Note
This is an abstract method which must be implemented by inheriting classes.
Parameters: gen_info ( GeneralInformation
) – The framework’s GeneralInformation instance.
-
hasApproxMethod
(app_method_id) Does this Candidate have an ApproxMethod with the specified ID?
Parameters: app_method_id (str) – The unique identifier of the ApproxMethod subclass to look for. Returns: True
if an ApproxMethod instance with ID app_method_id is an element of this Candidate’s app_methods attribute, otherwiseFalse
.
-
getApproxMethod
(app_method_id)¶ Gets the ApproxMethod instance with the specified ID if it exists.
Parameters: app_method_id (str) – The unique identifier of the ApproxMethod subclass to look for. Returns: The ApproxMethod instance from this Candidate’s app_methods attribute with the specified ID if one exists, None
otherwise.
-
hasErrorMetric
(err_id) Does this Candidate have an ErrorMetric with the specified ID?
Parameters: err_id (str) – The unique identifier of the ErrorMetric subclass to look for. Returns: True
if an ErrorMetric instance with ID err_id is an element of this Candidate’s quality_constraints attribute, otherwiseFalse
.
-
getErrorMetric
(err_id) Gets the ErrorMetric instance with the specified ID if it exists.
Parameters: err_id (str) – The unique identifier of the ErrorMetric subclass to look for. Returns: The ErrorMetric instance from this Candidate’s quality_constraints attribute with the specified ID if one exists, None
otherwise.
-
class
base.candidates.
ModuleCand
(name, variants_path, orig_var, quality_constraints, app_methods)¶ Bases:
base.candidates.Candidate
Candidate representation of a module.
This Candidate subclass represents approximation candidates specified directly by a module from the input design. Approximation of ModuleCands results in the replacement of the original modules by their approximated variants and is therefore especially simple and configurable.
-
static
getTypeStr
()¶ Returns the Candidate type’s unique ID string.
-
generateOriginalVariant
(gen_info)¶ Overrides the superclass method.
Both Verilog and BLIF files of the generated Variant are created.
-
static
-
class
base.candidates.
CandidateSet
(cands=None, path='')¶ Bases:
object
Data structure to store all Candidates.
This class is only instantiated once and serves as universally accessible storage for the approximation candidates.
Parameters: -
path
¶ The path of the directory in which the Candidate files are stored.
Type: str
-
append
(cand)¶ Adds a Candidate to the set. Same semantics as
list.append()
.Parameters: cand ( Candidate
) – A Candidate instance to be added to the set.
-