OpenSourceEconomics / lcm

Solution and simulation of life cycle models in Python with GPU acceleration.
Apache License 2.0
16 stars 1 forks source link

ENH: Allow functions of _period as filter arguments #61

Closed buddejul closed 5 months ago

buddejul commented 7 months ago

Filter functions cannot take arguments that are functions of _period as arguments. Or at least if one other state is provided as argument (see below). Related to #60 which allows _period as an argument.

Examples

def age(_period):
    return _period + 20

# This works
def period_filter(_period):
    return jnp.logical_or(_period > 0, _period < 20)

# This works
def age_filter(age):
    return jnp.logical_or(age > 0, age < 20)

# This doesn't work
def failing_age_filter(age, no_of_kids):
    return jnp.logical_or(age > 0, no_of_kids == 0)

# This works
def workaround_age_filter(_period, no_of_kids):
    return jnp.logical_or(age(_period) > 0, no_of_kids == 0)

When trying to solve with failing_age_filter, lcm returns

ValueError: Not enough or too many arguments provided.