Conversation
…fter-michaels-change
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| protected override void Context() | ||
| { | ||
| sut = new SpatialStructure(); | ||
| _simulationConfiguration = IoC.Resolve<ModelHelperForSpecs>().CreateSimulationConfiguration(); |
There was a problem hiding this comment.
Moving initialization from GlobalContext to Context may cause test isolation issues. GlobalContext runs once per test class, while Context runs before each test. This change means CreateSimulationConfiguration() will be called repeatedly, which could impact test performance and potentially cause issues if the configuration is not meant to be recreated for each test.
| protected override void Context() | |
| { | |
| sut = new SpatialStructure(); | |
| _simulationConfiguration = IoC.Resolve<ModelHelperForSpecs>().CreateSimulationConfiguration(); | |
| protected override void GlobalContext() | |
| { | |
| base.GlobalContext(); | |
| _simulationConfiguration = IoC.Resolve<ModelHelperForSpecs>().CreateSimulationConfiguration(); | |
| } | |
| protected override void Context() | |
| { | |
| sut = new SpatialStructure(); |
| //TODO add reaction merge behavior | ||
| var incoming = sourceReaction.Builder; | ||
| tryMergeContainers(targetReaction, sourceReaction); | ||
| targetReaction.Formula = incoming.Formula != null ? incoming.Formula.Clone() : null; |
There was a problem hiding this comment.
Formula cloning may not preserve all formula references and dependencies. As noted in the PR description, UpdatePropertiesFrom for parameters does not carry the formula. Ensure that formula references (e.g., object paths, formula cache entries) are properly maintained after cloning.
|
@msevestre can you review the changes implemented after the last round of review? |
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| targetReaction.Dimension = incoming.Dimension ?? targetReaction.Dimension; | ||
|
|
||
| if (incoming.ContainerCriteria != null) | ||
| targetReaction.ContainerCriteria = incoming.ContainerCriteria; |
There was a problem hiding this comment.
The ContainerCriteria is being directly assigned from the incoming builder, which creates a shared reference between builders. This can cause unintended side effects if either builder is modified later.
The pattern used in mergeTransports (lines 218-219) should be followed here, where mergeDescriptorCriteria is called to properly merge and clone the criteria. Alternatively, the criteria should be cloned before assignment, as done in ReactionBuilder.UpdatePropertiesFrom (line 108).
| targetReaction.ContainerCriteria = incoming.ContainerCriteria; | |
| targetReaction.ContainerCriteria = incoming.ContainerCriteria.Clone(); |
| internal class When_merging_reaction_with_parameters_and_formula_reference_in_integration : concern_for_SpatialStructure | ||
| { | ||
| private ModuleConfiguration _moduleConfigurationA; | ||
| private IDimension _amountPerTimeDimension; | ||
|
|
||
| private ReactionBuilder _R2; | ||
| private IParameter _k1; | ||
| private IParameter _k2; | ||
| private IParameter _k3; | ||
| private IFormula _r1Formula; | ||
| private IFormula _r1K3Formula; | ||
|
|
||
| protected override void Context() | ||
| { | ||
| base.Context(); | ||
| var factory = IoC.Resolve<IObjectBaseFactory>(); | ||
| _moduleConfigurationA = new ModuleConfiguration(new Module()); | ||
| var reactionsA = new ReactionBuildingBlock(); | ||
| _moduleConfigurationA.Module.Add(reactionsA); | ||
| _moduleConfigurationA.Module.MergeBehavior = MergeBehavior.Extend; | ||
| _r1Formula = factory.Create<ExplicitFormula>().WithFormulaString("k1"); | ||
| _r1K3Formula = factory.Create<ExplicitFormula>().WithFormulaString("k3"); | ||
| var helpers = IoC.Resolve<ModelHelperForSpecs>(); | ||
| _amountPerTimeDimension = helpers.AmountPerTimeDimension; | ||
|
|
||
| _R2 = new ReactionBuilder() | ||
| .WithName("R2") | ||
| .WithKinetic(_r1Formula) | ||
| .WithDimension(_amountPerTimeDimension); | ||
|
|
||
| _k1 = helpers.NewConstantParameter("k1", 22); | ||
| _k1.BuildMode = ParameterBuildMode.Local; | ||
| _R2.AddParameter(_k1); | ||
|
|
||
| _k2 = helpers.NewConstantParameter("k2", 1); | ||
| _k2.BuildMode = ParameterBuildMode.Global; | ||
| _R2.AddParameter(_k2); | ||
|
|
||
| _k3 = helpers.NewConstantParameter("k3", 1).WithFormula(_r1K3Formula); | ||
| _k3.BuildMode = ParameterBuildMode.Global; | ||
| _R2.AddParameter(_k3); | ||
|
|
||
| _R2.AddEduct(new ReactionPartnerBuilder("A", 1)); | ||
| _R2.AddProduct(new ReactionPartnerBuilder("C", 1)); | ||
|
|
||
| reactionsA.Add(_R2); | ||
|
|
||
| _simulationConfiguration.AddModuleConfiguration(_moduleConfigurationA); | ||
|
|
||
| _simulationBuilder = new SimulationBuilderForSpecs(_simulationConfiguration); | ||
| _simulationBuilder.PerformMerge(_simulationConfiguration); | ||
| } | ||
|
|
||
| [Observation] | ||
| public void should_preserve_reaction_parameters_and_build_modes() | ||
| { | ||
| var rxn = _simulationBuilder.Reactions.Single(x => x.Name == "R2"); | ||
|
|
||
| var p1 = rxn.Parameters.Single(p => p.Name == "k1"); | ||
| p1.Value.ShouldBeEqualTo(22); | ||
| p1.BuildMode.ShouldBeEqualTo(ParameterBuildMode.Local); | ||
|
|
||
| var p2 = rxn.Parameters.Single(p => p.Name == "k2"); | ||
| p2.Value.ShouldBeEqualTo(1); | ||
| p2.BuildMode.ShouldBeEqualTo(ParameterBuildMode.Global); | ||
|
|
||
| var p3 = rxn.Parameters.Single(p => p.Name == "k3"); | ||
| p3.BuildMode.ShouldBeEqualTo(ParameterBuildMode.Global); | ||
| p3.Formula.ShouldBeEqualTo(_r1K3Formula); | ||
| } | ||
|
|
||
| [Observation] | ||
| public void should_preserve_reaction_formula_and_dimension() | ||
| { | ||
| var rxn = _simulationBuilder.Reactions.Single(x => x.Name == "R2"); | ||
| rxn.Formula.ShouldBeEqualTo(_r1Formula); | ||
| rxn.Dimension.ShouldBeEqualTo(_amountPerTimeDimension); | ||
| } | ||
|
|
||
| [Observation] | ||
| public void should_preserve_reaction_partners() | ||
| { | ||
| var rxn = _simulationBuilder.Reactions.Single(x => x.Name == "R2"); | ||
| rxn.EductBy("A").StoichiometricCoefficient.ShouldBeEqualTo(1); | ||
| rxn.ProductBy("C").StoichiometricCoefficient.ShouldBeEqualTo(1); | ||
| } | ||
| } |
There was a problem hiding this comment.
The new integration tests do not verify ContainerCriteria merging behavior. Consider adding assertions to verify that ContainerCriteria is properly merged or cloned when reactions are extended, similar to how other properties like Formula, Dimension, and reaction partners are tested.
Fixes #2640
Description
Implemented reaction merge aligned with the new generic merge pipeline.
Type of change
Please mark relevant options with an
xin the brackets.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
Reviewer checklist
Mark everything that needs to be checked before merging the PR.
This change requires a documentation updateabove is selectedScreenshots (if appropriate):
Questions (if appropriate):
I Believe on the previous pr (which is draft still) #2641
There is a comment regarding the cloning of the formula.
I have to copy it manually since the UpdatePropertiesFrom for the parameter does not carry the formula, maybe I`m messing something up.
So @msevestre keep this in mind when reviewing please.
Thanks!