Extensible components


Error metrics (or ErrorMetric instances) provide a general way to specify quality constraints. Each ErrorMetric represents a specific way of quantifying the errors produced by an approximated circuit in relation to the original circuit’s output. Each instance, however, specifies a concrete maximum bound for its metric to serve as candidate-specific quality constraint.

To create an abstract interface for working with error metrics of arbitrary types, the ErrorMetric class provides several methods for increasing or comparing error values independently of the respective error metric’s value representation.


__init__(id: String, max_value: Value, step: StepValue)

For identification and representation of different error metrics, each ErrorMetric must have a unique class-level ID, just like approximators. The max_value parameter specifies the maximum error bound for this instance. It has the abstract type Value which you can choose freely. The same applies to the step parameter, which defines the step size of a value increment.


Note that this method must call the superclass’s __init__ method, which takes an additional argument default_value of type Value. It specifies the initial value of a new ErrorMetric instance.

getNextValue(cur_value: Value): Value

This method calculates the next error value as the current value increased by exactly one step. The value is returned, even if it exceeds the maximum error bound of this instance.

greaterMax(value: Value): Boolean

A simple query method to check whether the given error value value exceeds the maximum error bound max_value of this instance.

getValueStr(value: Value): String

Returns a string representation of the given error value. This is used for ID generation of variants and circuit configurations, so different error values should always generate different string representations. Also make sure to keep the representation as short as possible to avoid overly long IDs.

Back to the Developer Guide