Skip to content

Commit

Permalink
1772 ensure that output mapping are exported (#1775)
Browse files Browse the repository at this point in the history
* Ensure that WeightedObservedData is also in domain

* Fixes #1772 ensure that output mapping are exported

* Fixes tests

* Fixes tests also that was hard coding number of pk parameters"
  • Loading branch information
msevestre authored and rwmcintosh committed Nov 29, 2022
1 parent b331c3e commit a2f7aad
Show file tree
Hide file tree
Showing 37 changed files with 142 additions and 75 deletions.
1 change: 0 additions & 1 deletion src/OSPSuite.Core/Domain/ISimulation.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System.Collections.Generic;
using OSPSuite.Core.Chart;
using OSPSuite.Core.Domain.Data;
using OSPSuite.Core.Domain.ParameterIdentifications;

namespace OSPSuite.Core.Domain
{
Expand Down
9 changes: 4 additions & 5 deletions src/OSPSuite.Core/Domain/OutputMapping.cs
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
using OSPSuite.Core.Domain.Data;
using OSPSuite.Core.Domain.ParameterIdentifications;
using OSPSuite.Core.Domain.UnitSystem;

namespace OSPSuite.Core.Domain
{
public class OutputMapping
{
public virtual WeightedObservedData WeightedObservedData { get; set; }

public virtual SimulationQuantitySelection OutputSelection { get; set; }

public virtual Scalings Scaling { get; set; }

public float Weight { get; set; } = Constants.DEFAULT_WEIGHT;

/// <summary>
Expand All @@ -29,7 +28,7 @@ public class OutputMapping
/// </summary>
public virtual IQuantity Output => OutputSelection?.Quantity;

public virtual ISimulation Simulation => OutputSelection?.Simulation;
public virtual IModelCoreSimulation Simulation => OutputSelection?.Simulation;

public IDimension Dimension => OutputSelection?.Quantity?.Dimension;

Expand Down
12 changes: 10 additions & 2 deletions src/OSPSuite.Core/Domain/OutputMappings.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
using System.Collections.Generic;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using OSPSuite.Core.Domain.Data;
using OSPSuite.Core.Domain.Services;
using OSPSuite.Utility.Extensions;

namespace OSPSuite.Core.Domain
{
public class OutputMappings : IUpdatable
public class OutputMappings : IUpdatable, IEnumerable<OutputMapping>
{
private readonly List<OutputMapping> _allOutputMappings = new List<OutputMapping>();

Expand Down Expand Up @@ -76,5 +77,12 @@ public bool Contains(OutputMapping outputMapping)
{
return _allOutputMappings.Contains(outputMapping);
}

public IEnumerator<OutputMapping> GetEnumerator() => _allOutputMappings.GetEnumerator();

IEnumerator IEnumerable.GetEnumerator()
{
return GetEnumerator();
}
}
}
4 changes: 2 additions & 2 deletions src/OSPSuite.Core/Domain/ParameterSelection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ public ParameterSelection()
{
}

public ParameterSelection(ISimulation simulation, QuantitySelection quantitySelection) : base(simulation, quantitySelection)
public ParameterSelection(IModelCoreSimulation simulation, QuantitySelection quantitySelection) : base(simulation, quantitySelection)
{
}

public ParameterSelection(ISimulation simulation, string parameterPath) : this(simulation, new QuantitySelection(parameterPath, QuantityType.Parameter))
public ParameterSelection(IModelCoreSimulation simulation, string parameterPath) : this(simulation, new QuantitySelection(parameterPath, QuantityType.Parameter))
{
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using System.Collections.Generic;
using System.Linq;
using OSPSuite.Utility.Collections;
using OSPSuite.Core.Domain.Data;
using OSPSuite.Core.Domain.Services;
using OSPSuite.Utility.Collections;

namespace OSPSuite.Core.Domain.Repositories
{
Expand Down Expand Up @@ -37,7 +37,7 @@ public DataRepository FindFor(UsedObservedData usedObservedData)

public IEnumerable<DataRepository> AllObservedDataUsedBy(IUsesObservedData observedDataUser)
{
return All().Where(observedDataUser.UsesObservedData);
return observedDataUser == null ? Enumerable.Empty<DataRepository>() : All().Where(observedDataUser.UsesObservedData);
}

public IEnumerable<DataRepository> AllObservedDataUsedBy(IEnumerable<IUsesObservedData> observedDataUsers)
Expand Down
4 changes: 2 additions & 2 deletions src/OSPSuite.Core/Domain/Services/ISetParameterTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ public interface ISetParameterTask
/// Sets the <paramref name="value"/> into <paramref name="parameter"/> defined in <paramref name="simulation"/>
/// </summary>
/// <returns>The executed command representing the value being set in the parameter</returns>
ICommand SetParameterValue(IParameter parameter, double value, ISimulation simulation);
ICommand SetParameterValue(IParameter parameter, double value, IModelCoreSimulation simulation);


/// <summary>
/// Updates the parameter value origin in the <paramref name="parameter"/> defined in <paramref name="simulation"/>
/// </summary>
/// <returns>The executed command representing the <see cref="ValueOrigin"/> being set in the parameter</returns>
ICommand UpdateParameterValueOrigin(IParameter parameter, ValueOrigin valueOrigin, ISimulation simulation);
ICommand UpdateParameterValueOrigin(IParameter parameter, ValueOrigin valueOrigin, IModelCoreSimulation simulation);
}
}
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
using System;
using System.Collections.Generic;
using System.Linq;
using OSPSuite.Utility.Collections;
using OSPSuite.Utility.Extensions;
using OSPSuite.Core.Domain.Data;
using OSPSuite.Core.Domain.ParameterIdentifications;
using OSPSuite.Utility.Extensions;

namespace OSPSuite.Core.Domain.Services.ParameterIdentifications
{
public interface IJacobianMatrixCalculator
{
JacobianMatrix CalculateFor(ParameterIdentification parameterIdentification, OptimizationRunResult runResult, IDictionary<ISimulation, ISimModelBatch> simModelBatches);
JacobianMatrix CalculateFor(ParameterIdentification parameterIdentification, OptimizationRunResult runResult, IDictionary<IModelCoreSimulation, ISimModelBatch> simModelBatches);
}

public class JacobianMatrixCalculator : IJacobianMatrixCalculator
{
public JacobianMatrix CalculateFor(ParameterIdentification parameterIdentification, OptimizationRunResult runResult, IDictionary<ISimulation, ISimModelBatch> simModelBatches)
public JacobianMatrix CalculateFor(ParameterIdentification parameterIdentification, OptimizationRunResult runResult, IDictionary<IModelCoreSimulation, ISimModelBatch> simModelBatches)
{
var allVariableIdentificationParameters = parameterIdentification.AllVariableIdentificationParameters.ToList();
var matrix = new JacobianMatrix(allVariableIdentificationParameters.AllNames());
Expand Down Expand Up @@ -76,6 +75,7 @@ private static double retrievePartialDerivativeFor(IdentificationParameter ident

sensitivityValue += sensitivityForParameter;
}

return sensitivityValue;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public class ParameterIdentificationRun : IParameterIdentificationRun
private readonly IOutputSelectionUpdater _outputSelectionUpdater;
private readonly ICoreUserSettings _coreUserSettings;
private readonly IJacobianMatrixCalculator _jacobianMatrixCalculator;
private readonly ConcurrentDictionary<ISimulation, ISimModelBatch> _allSimModelBatches = new ConcurrentDictionary<ISimulation, ISimModelBatch>();
private readonly ConcurrentDictionary<IModelCoreSimulation, ISimModelBatch> _allSimModelBatches = new ConcurrentDictionary<IModelCoreSimulation, ISimModelBatch>();
private readonly List<float> _totalErrorHistory = new List<float>();

private readonly Cache<string, IdentificationParameterHistory> _parametersHistory =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ private IEnumerable<ICommand> updateParameterValue(IdentificationParameter ident
return new[] {setValueCommand, updateValueOriginCommand(identificationParameter, parameter, linkedParameter.Simulation).AsHidden()};
}

private ICommand updateValueOriginCommand(IdentificationParameter identificationParameter, IParameter parameter, ISimulation simulation)
private ICommand updateValueOriginCommand(IdentificationParameter identificationParameter, IParameter parameter, IModelCoreSimulation simulation)
{
var isoDate = SystemTime.Now().ToIsoFormat();
var valueOrigin = new ValueOrigin
Expand Down
9 changes: 5 additions & 4 deletions src/OSPSuite.Core/Domain/SimulationQuantitySelection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,19 @@ public class SimulationQuantitySelection
{
private IQuantity _quantity;
private string _fullQuantityPath;
public virtual ISimulation Simulation { get; private set; }

public virtual string SimulationId { get; set; }

public virtual IModelCoreSimulation Simulation { get; private set; }

public virtual QuantitySelection QuantitySelection { get; }

public virtual IDimension Dimension => Quantity?.Dimension;

[Obsolete("For serialization")]
public SimulationQuantitySelection()
{
}

public SimulationQuantitySelection(ISimulation simulation, QuantitySelection quantitySelection)
public SimulationQuantitySelection(IModelCoreSimulation simulation, QuantitySelection quantitySelection)
{
Simulation = simulation;
QuantitySelection = quantitySelection;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using OSPSuite.Core.Domain.Data;
using OSPSuite.Core.Extensions;

namespace OSPSuite.Core.Domain.ParameterIdentifications
namespace OSPSuite.Core.Domain
{
public class WeightedObservedData
{
Expand Down
21 changes: 8 additions & 13 deletions src/OSPSuite.Core/Serialization/Exchange/SimulationTransfer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,15 @@ namespace OSPSuite.Core.Serialization.Exchange
{
public class SimulationTransfer : IWithId
{
public string Id { get; set; } = ShortGuid.NewGuid();

public IModelCoreSimulation Simulation { get; set; }
public IList<DataRepository> AllObservedData { get; set; }
public int PkmlVersion { get; set; }
public string Id { get; set; }
public Favorites Favorites { get; set; }
public string JournalPath { get; set; }
public OutputMappings OutputMappings { get; set; } = new OutputMappings();
public IList<DataRepository> AllObservedData { get; set; } = new List<DataRepository>();

public SimulationTransfer()
{
AllObservedData = new List<DataRepository>();
PkmlVersion = Constants.PKML_VERSION;
Id = ShortGuid.NewGuid();
Favorites = new Favorites();
JournalPath = string.Empty;
}
//MetaData about the export
public int PkmlVersion { get; set; } = Constants.PKML_VERSION;
public Favorites Favorites { get; set; } = new Favorites();
public string JournalPath { get; set; } = string.Empty;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,12 @@ public override void PerformMapping()
Map(x => x.Simulation);
Map(x => x.JournalPath);
Map(x => x.Favorites);
MapEnumerable(x => x.AllObservedData, x => x.AllObservedData.Add);
Map(x => x.PkmlVersion).WithMappingName(Constants.Serialization.Attribute.VERSION);

MapEnumerable(x => x.AllObservedData, x => x.AllObservedData.Add);
//This needs to be done after observed data serialization to ensure that the observed data were deserialized
Map(x => x.OutputMappings);

}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.Globalization;
using System.Xml.Linq;
using OSPSuite.Core.Domain;
using OSPSuite.Core.Domain.Data;
using OSPSuite.Serializer.Xml.Extensions;
using OSPSuite.Core.Domain.ParameterIdentifications;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Xml.Linq;
using OSPSuite.Core.Domain;
using OSPSuite.Core.Domain.Data;

Expand All @@ -25,5 +26,11 @@ private Action<IExtendedProperty> addFunction(DataRepository dataRepository)
{
return dataRepository.ExtendedProperties.Add;
}

protected override void TypedDeserialize(DataRepository dataRepository, XElement outputToDeserialize, SerializationContext serializationContext)
{
base.TypedDeserialize(dataRepository, outputToDeserialize, serializationContext);
serializationContext.Register(dataRepository);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using OSPSuite.Core.Domain.ParameterIdentifications;
using OSPSuite.Core.Domain;

namespace OSPSuite.Core.Serialization.Xml
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ namespace OSPSuite.Presentation.DTO
public class SimulationQuantitySelectionDTO : ValidatableDTO, IPathRepresentableDTO
{
public virtual QuantitySelectionDTO QuantitySelectionDTO { get; }
public virtual ISimulation Simulation { get; }
public virtual IModelCoreSimulation Simulation { get; }
public virtual string DisplayString { get; }

public SimulationQuantitySelectionDTO(ISimulation simulation, QuantitySelectionDTO quantitySelectionDTO, string displayString)
public SimulationQuantitySelectionDTO(IModelCoreSimulation simulation, QuantitySelectionDTO quantitySelectionDTO, string displayString)
{
DisplayString = displayString;
QuantitySelectionDTO = quantitySelectionDTO;
Expand All @@ -25,7 +25,7 @@ public override string ToString()

public PathElements PathElements
{
get { return QuantitySelectionDTO?.PathElements; }
get => QuantitySelectionDTO?.PathElements;
set
{
if (QuantitySelectionDTO != null)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System.Data;
using System.Linq;
using OSPSuite.Assets;
using OSPSuite.Core.Domain;
using OSPSuite.Core.Domain.Data;
using OSPSuite.Core.Domain.ParameterIdentifications;
using OSPSuite.Core.Domain.Services;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace OSPSuite.Presentation.Mappers
{
public interface IQuantityToSimulationQuantitySelectionDTOMapper
{
SimulationQuantitySelectionDTO MapFrom(ISimulation simulation, IQuantity quantity);
SimulationQuantitySelectionDTO MapFrom(IModelCoreSimulation simulation, IQuantity quantity);
}

public class QuantityToSimulationQuantitySelectionDTOMapper : AbstractQuantityToSimulationQuantitySelectionDTOMapper, IQuantityToSimulationQuantitySelectionDTOMapper
Expand All @@ -21,7 +21,7 @@ public QuantityToSimulationQuantitySelectionDTOMapper(IQuantityToQuantitySelecti
_quantityDisplayPathMapper = quantityDisplayPathMapper;
}

public SimulationQuantitySelectionDTO MapFrom(ISimulation simulation, IQuantity quantity)
public SimulationQuantitySelectionDTO MapFrom(IModelCoreSimulation simulation, IQuantity quantity)
{
var quantitySelectionDTO = _quantitySelectionDTOMapper.MapFrom(quantity);
if (quantitySelectionDTO == null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,8 @@ private IEnumerable<DataRepository> allPossibleObservedDataForOutput(SimulationQ
if (outputSelectionDTO == null)
return Enumerable.Empty<DataRepository>();

return _observedDataRepository.AllObservedDataUsedBy(outputSelectionDTO.Simulation)
var usesObservedData = outputSelectionDTO.Simulation as IUsesObservedData;
return _observedDataRepository.AllObservedDataUsedBy(usesObservedData)
.Distinct()
.OrderBy(x => x.Name);
}
Expand All @@ -184,7 +185,7 @@ public void ObservedDataSelectionChanged(OutputMappingDTO dto, DataRepository ne
raiseObservedDataMappedFor(dto.WeightedObservedData);
}

public int? nextUniqueIdFor(List<OutputMappingDTO> outputMappings)
private int? nextUniqueIdFor(List<OutputMappingDTO> outputMappings)
{
if (!outputMappings.Any())
return null;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.Collections.Generic;
using System.Linq;
using OSPSuite.Core.Domain;
using OSPSuite.Core.Domain.ParameterIdentifications;
using OSPSuite.Presentation.Core;
using OSPSuite.Presentation.Views;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using OSPSuite.Core.Domain.Data;
using OSPSuite.Core.Domain;
using OSPSuite.Core.Domain.Data;
using OSPSuite.Core.Domain.ParameterIdentifications;
using OSPSuite.Core.Events;
using OSPSuite.Presentation.Presenters.Charts;
Expand Down
Loading

0 comments on commit a2f7aad

Please sign in to comment.