Skip to content

from cluster_experiments.inference.variant import *

Variant dataclass

A class used to represent a Variant with a name and a control flag.

Attributes

name : str The name of the variant is_control : bool A boolean indicating if the variant is a control variant

Source code in cluster_experiments/inference/variant.py
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
@dataclass
class Variant:
    """
    A class used to represent a Variant with a name and a control flag.

    Attributes
    ----------
    name : str
        The name of the variant
    is_control : bool
        A boolean indicating if the variant is a control variant
    """

    name: str
    is_control: bool

    def __post_init__(self):
        """
        Validates the inputs after initialization.
        """
        self._validate_inputs()

    def _validate_inputs(self):
        """
        Validates the inputs for the Variant class.

        Raises
        ------
        TypeError
            If the name is not a string or if is_control is not a boolean.
        """
        if not isinstance(self.name, str):
            raise TypeError("Variant name must be a string")
        if not isinstance(self.is_control, bool):
            raise TypeError("Variant is_control must be a boolean")

    @classmethod
    def from_metrics_config(cls, config: dict) -> "Variant":
        """
        Creates a Variant object from a configuration dictionary.

        Parameters
        ----------
        config : dict
            A dictionary containing the configuration for the Variant

        Returns
        -------
        Variant
            A Variant object
        """
        return cls(name=config["name"], is_control=config["is_control"])

__post_init__()

Validates the inputs after initialization.

Source code in cluster_experiments/inference/variant.py
20
21
22
23
24
def __post_init__(self):
    """
    Validates the inputs after initialization.
    """
    self._validate_inputs()

from_metrics_config(config) classmethod

Creates a Variant object from a configuration dictionary.

Parameters

config : dict A dictionary containing the configuration for the Variant

Returns

Variant A Variant object

Source code in cluster_experiments/inference/variant.py
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
@classmethod
def from_metrics_config(cls, config: dict) -> "Variant":
    """
    Creates a Variant object from a configuration dictionary.

    Parameters
    ----------
    config : dict
        A dictionary containing the configuration for the Variant

    Returns
    -------
    Variant
        A Variant object
    """
    return cls(name=config["name"], is_control=config["is_control"])