Skip to content

Conversation

@UsamaEquinorAFK
Copy link
Collaborator

@UsamaEquinorAFK UsamaEquinorAFK commented Jan 14, 2026

Wip

@UsamaEquinorAFK UsamaEquinorAFK marked this pull request as draft January 14, 2026 13:11
@UsamaEquinorAFK UsamaEquinorAFK self-assigned this Jan 14, 2026
Co-authored-by: Zohar Malamant <git@wah.pink>
Co-authored-by: Lars Petter Hauge <lars-petter-hauge@users.noreply.github.com>
}

if not hasattr(self, "_concentrations"):
self.concentrations = {}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's this for?

Comment on lines +77 to +82
if adapter.category != "Primary":
adapter.concentrations = {
k: v
for k, v in concentrations.items()
if k in adapter.valid_substances
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This business logic relating to the adapter doesn't need to be in this file. BaseAdapter should instead have:

  • validate_concentrations which throws an exception
  • set_concentrations which does this

Remove the setter property.

raise e

try:
adapters[0].concentrations = create_simulation.concentrations
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move this up before creating the simulation row in db. No need to schedule a simulation that we know will fail.

}


def test_chain(client, dummy_model):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing tests for the following cases:

  1. Empty case
  2. Single model
  3. Different models
  4. Parameters passed to the correct model
  5. What happens if you run 2 models, but first model throws an exception? Does the /result correctly show that the simulation is no longer running?

[model_input.id for model_input in simulation.model_inputs],
)
except BaseException as e:
raise e
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This try-catch doesn't seem to do anything interesting.

ModelResult(
concentrations=db_result.concentrations,
panels=[
TypeAdapter(AnyPanel).validate_python(panel)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why use TypeAdapter? panel is already a pydantic.BaseModel. Does this code ensure that the effect of this is the same as converting all the panels to JSON, including the changing from snake_case to camelCase?

if result is None:
return RunResponse(status="pending", model_input=model_input)
elif result.error is not None:
db_results = [mi.result for mi in simulation.model_inputs]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we know that the order of the results is correct? If you submit arcs -> solubility, could you get the results reversed: [result_of_solubility, result_of_arcs]? If yes, how do we avoid this; if not, why not?

}
else:
adapter.concentrations = concentrations
except InputError:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When do we expect there to be an InputError? Are there any other exceptions that may occur here, if any?

"results",
sa.Column("simulation_id", sa.UUID(), autoincrement=False, nullable=False),
)
op.drop_constraint(None, "results", type_="foreignkey") # type: ignore # Alembic accepts contraint name as string or None
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this line. Comment is incorrect: The constraint name must be a str and cannot be None. Which, of course, makes sense: Why would drop_constraint allow you not to specify which constraint you want to drop?

Copy link
Collaborator

@pinkwah pinkwah left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whoops, I meant not to approve

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.

4 participants