use of org.vcell.util.Issue in project vcell by virtualcell.
the class ParameterContext method gatherIssues.
public void gatherIssues(IssueContext issueContext, List<Issue> issueList, ParameterRoleEnum userDefinedRole) {
//
for (int i = 0; fieldUnresolvedParameters != null && i < fieldUnresolvedParameters.length; i++) {
issueList.add(new Issue(fieldUnresolvedParameters[i], issueContext, IssueCategory.UnresolvedParameter, "Unresolved parameter '" + fieldUnresolvedParameters[i].getName(), Issue.SEVERITY_ERROR));
}
//
for (int i = 0; fieldParameters != null && i < fieldParameters.length; i++) {
if (fieldParameters[i].getRole() == userDefinedRole) {
try {
if (!isReferenced(fieldParameters[i], 0)) {
issueList.add(new Issue(fieldParameters[i], issueContext, IssueCategory.KineticsUnreferencedParameter, "Unreferenced Kinetic Parameter '" + fieldParameters[i].getName(), Issue.SEVERITY_WARNING));
}
} catch (ExpressionException e) {
issueList.add(new Issue(fieldParameters[i], issueContext, IssueCategory.KineticsExpressionError, "error resolving expression " + e.getMessage(), Issue.SEVERITY_WARNING));
}
}
}
//
if (fieldParameters != null) {
for (LocalParameter parameter : this.fieldParameters) {
if (parameter.getExpression() == null) {
issueList.add(new Issue(parameter, issueContext, IssueCategory.KineticsExpressionMissing, "expression is missing", Issue.SEVERITY_INFO));
} else {
Expression exp = parameter.getExpression();
String[] symbols = exp.getSymbols();
String issueMessagePrefix = "parameter '" + parameter.getName() + "' ";
if (symbols != null) {
for (int j = 0; j < symbols.length; j++) {
SymbolTableEntry ste = exp.getSymbolBinding(symbols[j]);
if (ste instanceof LocalProxyParameter) {
ste = ((LocalProxyParameter) ste).getTarget();
}
if (ste == null) {
issueList.add(new Issue(parameter, issueContext, IssueCategory.KineticsExpressionUndefinedSymbol, issueMessagePrefix + "references undefined symbol '" + symbols[j] + "'", Issue.SEVERITY_ERROR));
// } else if (ste instanceof SpeciesContext) {
// if (!getReactionStep().getModel().contains((SpeciesContext)ste)) {
// issueList.add(new Issue(parameter,issueContext,IssueCategory.KineticsExpressionUndefinedSymbol, issueMessagePrefix + "references undefined species '"+symbols[j]+"'",Issue.SEVERITY_ERROR));
// }
// if (reactionStep.countNumReactionParticipants((SpeciesContext)ste) == 0){
// issueList.add(new Issue(parameter,issueContext,IssueCategory.KineticsExpressionNonParticipantSymbol, issueMessagePrefix + "references species context '"+symbols[j]+"', but it is not a reactant/product/catalyst of this reaction",Issue.SEVERITY_WARNING));
// }
// } else if (ste instanceof ModelParameter) {
// if (!getReactionStep().getModel().contains((ModelParameter)ste)) {
// issueList.add(new Issue(parameter,issueContext,IssueCategory.KineticsExpressionUndefinedSymbol, issueMessagePrefix + "references undefined global parameter '"+symbols[j]+"'",Issue.SEVERITY_ERROR));
// }
}
}
}
}
}
// looking for local param which masks a global and issueing a warning
for (LocalParameter parameter : fieldParameters) {
String name = parameter.getName();
SymbolTableEntry ste = nameScope.getExternalEntry(name, this);
String steName;
if (ste != null) {
if (ste instanceof Displayable) {
steName = ((Displayable) ste).getDisplayType() + " " + ste.getName();
} else {
steName = ste.getClass().getSimpleName() + " " + ste.getName();
}
String msg = steName + " is overriden by a local parameter " + name;
issueList.add(new Issue(parameter, issueContext, IssueCategory.Identifiers, msg, Issue.SEVERITY_WARNING));
}
}
}
try {
//
// determine unit consistency for each expression
//
VCUnitSystem unitSystem = unitSystemProvider.getUnitSystem();
VCUnitEvaluator unitEvaluator = new VCUnitEvaluator(unitSystem);
for (int i = 0; i < fieldParameters.length; i++) {
if (fieldParameters[i].getExpression() == null) {
continue;
}
try {
VCUnitDefinition paramUnitDef = fieldParameters[i].getUnitDefinition();
VCUnitDefinition expUnitDef = unitEvaluator.getUnitDefinition(fieldParameters[i].getExpression());
if (paramUnitDef == null) {
issueList.add(new Issue(fieldParameters[i], issueContext, IssueCategory.Units, "defined unit is null", Issue.SEVERITY_WARNING));
} else if (paramUnitDef.isTBD()) {
issueList.add(new Issue(fieldParameters[i], issueContext, IssueCategory.Units, "undefined unit " + unitSystem.getInstance_TBD().getSymbol(), Issue.SEVERITY_WARNING));
} else if (expUnitDef == null) {
issueList.add(new Issue(fieldParameters[i], issueContext, IssueCategory.Units, "computed unit is null", Issue.SEVERITY_WARNING));
} else if (paramUnitDef.isTBD() || (!paramUnitDef.isEquivalent(expUnitDef) && !expUnitDef.isTBD())) {
issueList.add(new Issue(fieldParameters[i], issueContext, IssueCategory.Units, "inconsistent units, defined=[" + fieldParameters[i].getUnitDefinition().getSymbol() + "], computed=[" + expUnitDef.getSymbol() + "]", Issue.SEVERITY_WARNING));
}
} catch (VCUnitException e) {
issueList.add(new Issue(fieldParameters[i], issueContext, IssueCategory.Units, e.getMessage(), Issue.SEVERITY_WARNING));
} catch (ExpressionException e) {
issueList.add(new Issue(fieldParameters[i], issueContext, IssueCategory.Units, e.getMessage(), Issue.SEVERITY_WARNING));
}
}
} catch (Throwable e) {
issueList.add(new Issue(parameterPolicy.getIssueSource(), issueContext, IssueCategory.Units, "unexpected exception: " + e.getMessage(), Issue.SEVERITY_INFO));
}
//
for (int i = 0; i < fieldParameters.length; i++) {
RealInterval simpleBounds = parameterPolicy.getConstraintBounds(fieldParameters[i].getRole());
if (simpleBounds != null) {
String parmName = fieldParameters[i].getName();
issueList.add(new SimpleBoundsIssue(fieldParameters[i], issueContext, simpleBounds, "parameter " + parmName + ": must be within " + simpleBounds.toString()));
}
}
}
use of org.vcell.util.Issue in project vcell by virtualcell.
the class SimulationWarning method analyzeDiffusion.
/**
* make sure diffusion expressions are constants, store for later use
* @throws ExpressionException
*/
private static Map<MembraneSubDomain, List<DiffusionValue>> analyzeDiffusion(Simulation simulation, double timeStep, IssueContext issueContext, List<Issue> issueList) throws ExpressionException {
Map<MembraneSubDomain, List<DiffusionValue>> diffusionValuesMap = new IdentityHashMap<>();
diffusionValuesMap.clear();
MutableDouble value = new MutableDouble();
MathDescription cm = simulation.getMathDescription();
Objects.requireNonNull(cm);
MathDescription localMath = new MathDescription(cm);
SimulationSymbolTable symTable = new SimulationSymbolTable(simulation, 0);
Map<MembraneSubDomain, List<DiffusionValue>> dvMap = new HashMap<>();
double maxDiffValue = Double.MIN_VALUE;
List<DiffusionValue> diffusionList = new ArrayList<>();
for (SubDomain sd : localMath.getSubDomainCollection()) {
final boolean isMembrane = sd instanceof MembraneSubDomain;
diffusionList.clear();
for (ParticleProperties pp : sd.getParticleProperties()) {
String name = pp.getVariable().getName();
Expression diffExp = pp.getDiffusion();
Expression flattened = MathUtilities.substituteFunctions(diffExp, symTable).flatten();
if (isConstant(flattened, value)) {
if (isMembrane) {
DiffusionValue dv = new DiffusionValue(name, value.doubleValue());
maxDiffValue = Math.max(maxDiffValue, dv.value);
diffusionList.add(dv);
}
} else {
String s = "Smoldyn only supports constant diffusion, " + name + " is variable";
Issue i = new Issue(simulation, issueContext, IssueCategory.SMOLYDN_DIFFUSION, s, s, Severity.ERROR);
issueList.add(i);
}
}
if (isMembrane && !diffusionList.isEmpty()) {
dvMap.put((MembraneSubDomain) sd, diffusionList);
}
}
diffusionValuesMap.putAll(dvMap);
MeshSpecification ms = simulation.getMeshSpecification();
Geometry g = ms.getGeometry();
int dim = g.getDimension();
double minDelta = Double.MAX_VALUE;
switch(dim) {
case 3:
minDelta = Math.min(minDelta, ms.getDz(true));
// fall-through
case 2:
minDelta = Math.min(minDelta, ms.getDy(true));
// fall-through
case 1:
minDelta = Math.min(minDelta, ms.getDx(true));
break;
default:
throw new RuntimeException("Invalid dimension " + dim + " for smoldyn solver");
}
double minArea = minDelta * minDelta / 2;
double limit = PRECHECK_LIMIT_ADJUST * minArea / maxDiffValue;
boolean warn = (timeStep > limit);
if (lg.isDebugEnabled()) {
lg.debug("Min delta " + minDelta + ", min area " + minArea + " time limit " + limit + " timeStep " + timeStep + " -> warn = " + warn);
}
if (warn) {
String s = "Time step " + timeStep + " may be too large, performing further analysis ...";
Issue i = new Issue(simulation, issueContext, IssueCategory.SMOLYDN_DIFFUSION, s, s, Severity.WARNING);
issueList.add(i);
}
lg.debug("end of diffusion analysis");
return diffusionValuesMap;
}
use of org.vcell.util.Issue in project vcell by virtualcell.
the class MathOverrides method hasUnusedOverrides.
public boolean hasUnusedOverrides() {
ArrayList<Issue> issueList = new ArrayList<Issue>();
IssueContext issueContext = new IssueContext(ContextType.Simulation, getSimulation(), null);
gatherIssues(issueContext, issueList);
for (Issue issue : issueList) {
if (issue.getSeverity() == Issue.SEVERITY_ERROR && (issue.getCategory().equals(IssueCategory.Simulation_Override_NotFound) || issue.getCategory().equals(IssueCategory.Simulation_Override_NotSupported))) {
return true;
}
}
return false;
}
use of org.vcell.util.Issue in project vcell by virtualcell.
the class ModelOptimizationSpec method gatherIssues.
public void gatherIssues(IssueContext issueContext, java.util.List<Issue> issueList) {
if (!hasSelectedParameters()) {
issueList.add(new Issue(this, issueContext, IssueCategory.ParameterEstimationNoParameterSelected, "No parameters are selected for optimization.", Issue.SEVERITY_INFO));
}
boolean bExperimentalDataMapped = true;
if (fieldReferenceDataMappingSpecs != null) {
for (ReferenceDataMappingSpec rms : fieldReferenceDataMappingSpecs) {
if (rms.getModelObject() == null) {
bExperimentalDataMapped = false;
break;
}
}
}
if (!bExperimentalDataMapped) {
issueList.add(new Issue(this, issueContext, IssueCategory.ParameterEstimationRefereceDataNotMapped, "There is unmapped experimental data column.", Issue.SEVERITY_WARNING));
}
issueList.addAll(localIssueList);
}
use of org.vcell.util.Issue in project vcell by virtualcell.
the class OptimizationService method optimize.
public static OptimizationResultSet optimize(ParameterEstimationTask parameterEstimationTask) throws Exception {
// if (OperatingSystemInfo.getInstance().isMac()){
// throw new RuntimeException("parameter estimation not currently available on Mac\n\n try Windows or Linux.\n\n coming soon on Mac.");
// }
copasiOptCallbacks.reset();
updateMath(parameterEstimationTask.getSimulationContext(), NetworkGenerationRequirements.ComputeFullStandardTimeout);
StringBuffer issueText = new StringBuffer();
java.util.Vector<Issue> issueList = new java.util.Vector<Issue>();
IssueContext issueContext = new IssueContext();
parameterEstimationTask.gatherIssues(issueContext, issueList);
boolean bFailed = false;
for (int i = 0; i < issueList.size(); i++) {
Issue issue = (Issue) issueList.elementAt(i);
issueText.append(issue.getMessage() + "\n");
if (issue.getSeverity() == Issue.SEVERITY_ERROR) {
bFailed = true;
break;
}
}
if (bFailed) {
throw new OptimizationException(issueText.toString());
}
parameterEstimationTask.refreshMappings();
OptimizationResultSet optResultSet = CopasiOptimizationSolver.solveLocalPython(new ParameterEstimationTaskSimulatorIDA(), parameterEstimationTask, copasiOptCallbacks, callback);
return optResultSet;
}
Aggregations