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

Fixes #2331 hiearchy of parmaeter value does not work with distribute… #2332

Conversation

msevestre
Copy link
Member

…d parameters

Fixes #2331

Description

Well this was a tricky one! As I expected, the issue is because we are updating a NON_DISTRIBUTED Parameter by a DISTRIBUTED_PARAMETER. it works if the parameter does not exist because it's created. But in the case outlined by @PavelBal , the parameter was created by the other Module and therefore the update routine did not work. This PR removes the existing parameters if they don't have the same structure and add them again

Spent most of the time trying to reproduce the bug.. as always :)

Type of change

Please mark relevant options with an x in the brackets.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires documentation changes (link at least one user or developer documentation issue):
  • Algorithm update - updates algorithm documentation/questions/answers etc.
  • Other (please describe):

How Has This Been Tested?

Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration

  • Integration tests
  • Unit tests
  • Manual tests
  • No tests required

Reviewer checklist

Mark everything that needs to be checked before merging the PR.

  • Check if the code is well documented
  • Check if the behavior is what is expected
  • Check if the code is well tested
  • Check if the code is readable and well formatted
  • Additional checks (document below if any)
  • Check if documentation update issue(s) are created if the option This change requires a documentation update above is selected

Screenshots (if appropriate):

Questions (if appropriate):

@msevestre msevestre requested review from rwmcintosh and Yuri05 October 5, 2024 01:44
Copy link
Member Author

@msevestre msevestre left a comment

Choose a reason for hiding this comment

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

This should solve the issue

@@ -13,7 +13,8 @@ public DiscreteDistributionFormula() : base(DistributionType.Discrete)
protected override double CalculateFor(IReadOnlyList<IObjectReference> usedObjects, IUsingFormula dependentObject)
{
var distributedParameter = dependentObject.ConvertedTo<IDistributedParameter>();
return CalculateValueFromPercentile(distributedParameter.Percentile, distributedParameter);
//percentile not used in this formula
return CalculateValueFromPercentile(Constants.DEFAULT_PERCENTILE, distributedParameter);
Copy link
Member Author

Choose a reason for hiding this comment

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

the parameter is not used. might was well not retrieve it (not related to this error)

@@ -111,24 +111,44 @@ private IParameter getOrAddModelParameter(ValueUpdaterParams valueUpdater, Param
parameter = _parameterValueToParameterMapper.MapFrom(parameterValue);

simulationBuilder.AddBuilderReference(parameter, parameterValue);

//now we remove the parameter by name from the parent container just in case it already exists but with a different type (distributed vs not distributed)
var potentialParameter = parentContainer.Parameter(parameterValue.Name);
Copy link
Member Author

Choose a reason for hiding this comment

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

before we were only landing in this code if a parameter did not exist. Now we also land there if it exists but with a different type

public void should_overwrite_the_parameter_value_with_the_value_of_the_parameter()
{
var parameter = _model.Root.EntityAt<IParameter>("Liver", "Param");
parameter.Value.ShouldBeEqualTo(24.28, 1e-2);
Copy link
Member Author

Choose a reason for hiding this comment

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

value of the distribution using the percentile of 0.8 (assuming this is right, I did not verify...)

//now we remove the parameter by name from the parent container just in case it already exists but with a different type (distributed vs not distributed)
var potentialParameter = parentContainer.Parameter(parameterValue.Name);
parentContainer.RemoveChild(potentialParameter);

Copy link
Member

Choose a reason for hiding this comment

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

RemoveChild will not crash if potentialParameter is null?

Copy link
Member Author

Choose a reason for hiding this comment

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

I certainly hope not but this is something I just assumed lol

@rwmcintosh rwmcintosh merged commit c8ee38f into develop Oct 11, 2024
1 check passed
@rwmcintosh rwmcintosh deleted the 2331-hierarchy-of-parameter-value-application-when-are-the-values-from-individuals-applied branch October 11, 2024 05:46
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.

Hierarchy of parameter value application - when are the values from Individuals applied?
3 participants