Skip to content

utils

utils ¤

default_literal_input_factory(negated=False) ¤

Input factory for a boolean logic circuit input realized using a Categorical Layer constantly parametrized by a tensor [x, y] where x is the probability of being False and y the probability of being True.

Parameters:

Name Type Description Default
negated bool

If True returns the input factory for the negated literal, else return a regular input factory.

False

Returns:

Name Type Description
InputLayerFactory InputLayerFactory

The input layer factory.

Source code in cirkit/templates/logic/utils.py
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
def default_literal_input_factory(negated: bool = False) -> InputLayerFactory:
    """Input factory for a boolean logic circuit input realized using a
    Categorical Layer constantly parametrized by a tensor [x, y] where x is
    the probability of being False and y the probability of being True.

    Args:
        negated (bool): If True returns the input factory for the negated literal,
            else return a regular input factory.

    Returns:
        InputLayerFactory: The input layer factory.
    """

    def input_factory(scope: Scope, num_units: int) -> InputLayer:
        param = np.array([1.0, 0.0]) if negated else np.array([0.0, 1.0])
        initializer = ConstantTensorInitializer(param)
        return CategoricalLayer(
            scope,
            num_categories=2,
            num_output_units=num_units,
            probs=Parameter.from_input(TensorParameter(1, 2, initializer=initializer)),
        )

    return input_factory