Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot treat model components as a list #10

Open
krosenfeld-IDM opened this issue Nov 27, 2024 · 0 comments
Open

Cannot treat model components as a list #10

krosenfeld-IDM opened this issue Nov 27, 2024 · 0 comments
Labels
invalid This doesn't seem right

Comments

@krosenfeld-IDM
Copy link
Collaborator

krosenfeld-IDM commented Nov 27, 2024

model.components does not act like a list and results in unpredictable (and buggy) behavior:

class Component_A:
    def __init__(self, model, verbose: bool = False) -> None:
        print("Initializing Component A")
    def __call__():
        pass

class Component_B:
    def __init__(self, model, verbose: bool = False) -> None:
        print("Initializing Component B")
    def __call__():
        pass

print("Creating model with components A and B simultaneously")
model = Model(scenario=scenario, parameters=parameters)    
model.components = [Component_A, Component_B]
# > Initializing Component A
# > Initializing Component B

print("Creating model with components A and then adding B")
model = Model(scenario=scenario, parameters=parameters)  
model.components = [Component_A]
model.components += [Component_B]
# Initializes A twice but ands up with both components
#>  Initializing Component A
#>  Initializing Component A
#>  Initializing Component B

# THIS DOES NOT WORK
print("Creating model with components A and then appending B")
model = Model(scenario=scenario, parameters=parameters)  
model.components = [Component_A]
model.components.append(Component_B)
#>  Initializing Component A
@krosenfeld-IDM krosenfeld-IDM added the invalid This doesn't seem right label Nov 27, 2024
@krosenfeld-IDM krosenfeld-IDM changed the title Cannot treat model as a list Cannot treat model components as a list Nov 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
invalid This doesn't seem right
Projects
None yet
Development

No branches or pull requests

1 participant