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

chore: move expression evaluator to components #776

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

frodehk
Copy link
Contributor

@frodehk frodehk commented Jan 27, 2025

Why is this pull request needed?

Make components able to evaluate expressions. It is a part of the preparation for refactoring of e.g. results.

What does this pull request change?

Sending expression evaluator to all components.

@frodehk frodehk self-assigned this Jan 27, 2025
@frodehk frodehk requested a review from a team as a code owner January 27, 2025 16:42
Copy link
Contributor

@jsolaas jsolaas left a comment

Choose a reason for hiding this comment

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

Looks good. I think we should make some changes to make sure expression_evaluator and pydantic isn't something we have to deal with in domain/application.

I think this change is a good idea as long as expression evaluator isn't meant to be changed. I don't like the idea of having a setter for expression_evaluator, instead I think we should create a new consumer with another expression_evaluator if that is needed.

The domain classes will then be a "locked" representation of the yaml model. The yaml model describes a single expression_evaluator, so the need to change it in the domain classes seems unnecessary to me. (Probably useful for testing, but we should just use a factory instead).

src/libecalc/application/energy/emitter.py Outdated Show resolved Hide resolved
src/libecalc/application/energy/emitter.py Outdated Show resolved Hide resolved
src/libecalc/common/variables.py Outdated Show resolved Hide resolved
@TeeeJay
Copy link
Collaborator

TeeeJay commented Jan 28, 2025

Looks good. I think we should make some changes to make sure expression_evaluator and pydantic isn't something we have to deal with in domain/application.

I think this change is a good idea as long as expression evaluator isn't meant to be changed. I don't like the idea of having a setter for expression_evaluator, instead I think we should create a new consumer with another expression_evaluator if that is needed.

The domain classes will then be a "locked" representation of the yaml model. The yaml model describes a single expression_evaluator, so the need to change it in the domain classes seems unnecessary to me. (Probably useful for testing, but we should just use a factory instead).

I noticed this. Not entirely sure how it works, but is it always the same instance that is being used everywhere? In that case we can create a singleton, that is accessible everywhere, instead of injecting it explicitly. To e.g consider it as a service; "ExpressionEvaluatorService"?

src/libecalc/application/energy/emitter.py Outdated Show resolved Hide resolved
Comment on lines +83 to +84
def set_consumer_results(self, consumer_results: dict[str, EcalcModelResult]):
self.consumer_results = consumer_results
Copy link
Contributor

Choose a reason for hiding this comment

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

Remove set_consumer_result?

Comment on lines +132 to +135
if self.volume.rate.type == RateType.CALENDAR_DAY:
oil_rates = Rates.to_stream_day(
calendar_day_rates=np.asarray(oil_rates), regularity=self.regularity_evaluated
).tolist()
Copy link
Contributor

Choose a reason for hiding this comment

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

Use get_oil_rates here?

energy_context: ComponentEnergyContext,
energy_model: EnergyModel,
) -> Optional[dict[str, EmissionResult]]:
self._regularity = energy_model.get_regularity(self.id)
Copy link
Contributor

Choose a reason for hiding this comment

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

Pass regularity into init instead?

If I remember correctly get_regularity for EcalcModel was kind of a workaround since we didn't have the flexibility in these classes as we have now. I don't think we have to pass energy_model into evaluate_emissions any more.

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