Skip to content

Conversation

@jlnav
Copy link
Collaborator

@jlnav jlnav commented Aug 1, 2025

This won't pass all the tests as-is; it's a proposed interface but it does work with additional small adjustments to vocs.py.

    var0 = Variable(
        default_value=1.0,
        dtype=float,
    )
    assert isinstance(var0, Variable)

    var1 = Variable(
        default_value=2.0,
        domain=[0.0, 4.0],
    )
    assert isinstance(var1, ContinuousVariable)

    var2 = Variable(
        dtype=int,
        default_value=2,
        values={1, 2, 3},
    )
    assert isinstance(var2, DiscreteVariable)

    vocs = VOCS(variables={"x0": var0, "x1": var1, "x2": var2})
    assert vocs.n_variables == 3

Making the Variable base class also a factory class that produces the corresponding subclass when parameterized accordingly. Each subclass naturally validates itself. VOCS loses some validation responsibilities.

Each variable itself also has a name and dtype as discussed. dtype, default_value's type, and the values within DiscreteVariable should naturally match, and validation logic should be written for this.

This kind of factory-logic can be extended for the other objects that are currently accepted by VOCS.

@jlnav jlnav changed the title [wont pass tests] Proposed factory / auto-subclassing Variable [wont pass tests yet] Proposed factory / auto-subclassing Variable Aug 20, 2025
@jlnav jlnav closed this Dec 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants