Skip to content

🔠 Enums

Enums can be used to represent a set of named values that can be assigned to a field.

Protobuf provides a dedicated syntax for defining enums.

// enum_demo.proto
syntax = "proto3";

package enum_demo;

// Activation function
enum Activation {
    // ReLU activation
    RELU = 0;
    // Gelu activation
    GELU = 1;
}

// MLP configuration
message MLP {
    // Activation function
    Activation activation = 1;
    // Number of layers
    uint32 num_layers = 2;
}

The generated code will look like this:

# Autogenerated code. DO NOT EDIT.
import enum

import py_gen_ml as pgml


class Activation(str, enum.Enum):
    """Activation function"""

    RELU = "RELU"
    """ReLU activation"""

    GELU = "GELU"
    """Gelu activation"""


class MLP(pgml.YamlBaseModel):
    """MLP configuration"""

    activation: Activation
    """Activation function"""

    num_layers: int
    """Number of layers"""