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

Certain Ontologies models may share data via ptolemy.data.expr.Constants #316

Open
cxbrooks opened this issue Nov 16, 2012 · 1 comment
Open
Assignees

Comments

@cxbrooks
Copy link
Member

Note: the issue was created automatically with bugzilla2github tool

Original bug ID: BZ#522
From: @cxbrooks
Reported version: 9.1.devel
CC: [email protected]

@cxbrooks
Copy link
Member Author

There was a bug where running

$PTII/ptolemy/data/ontologies/test/auto/MonotonicityAnalysis.xml

and then running

$PTII/ptolemy/data/ontologies/test/auto/MultiplyDivideUnits.xml

resulted in a stack trace:

Caused by: ptolemy.kernel.util.InternalErrorException: Because:
Invalid dimension concept: Position
in .TestUnitsSolver.TestUnitsOntology.Velocity
at
ptolemy.data.ontologies.OntologySolver.invokeSolver(OntologySolver.java:201)

In turns out the problem was objects are being adding to the static Constants Hashtable

The constructor to
ptolemy/data/ontologies/lattice/adapters/monotonicityAnalysis/MonotonicityConceptFunction.java
calls
--start--
/** Add the concepts from the domain ontologies as constants
* for the parse tree evaluator.
*
* FIXME: Is there a better alternative?
*
* @ param domainOntology The domain ontology containing the concepts
* to add.
* @ exception IllegalActionException If there is a problem adding any
* of the concepts to the Constants hash table.
*/
private void _addConceptConstants(Ontology domainOntology)
throws IllegalActionException {
for (Object entity : domainOntology.allAtomicEntityList()) {
if (entity instanceof Concept) {
Constants.add(((Concept) entity).getName(), new ConceptToken(
(Concept) entity));
}
}
}
--end--

I updated OntologySolverBase to have:
public static void cleanConstants() {
RecordToken constants = Constants.constants();
System.out.println("OntologySolverBase: Constants: " + constants);
Set labels = constants.labelSet();
for (String label : labels) {
Token token = constants.get(label);
if (token instanceof ConceptToken) {
System.out.println("Found " + token + " Removing " + label);
Constants.remove(label);
}
}
System.out.println("OntologySolverBase: Constants after cleaning: " + Constants.constants());
}

The problem is that when we parse the second model, we check to see if a Constant is present.

For example, the two models share a Constant named "Position".

When I run the second model, I can see that parsing looks for Position:

java.lang.Exception: COnstant.get() Position
        at ptolemy.data.expr.Constants.get(Constants.java:127)
        at ptolemy.data.expr.ParseTreeEvaluator.visitLeafNode(ParseTreeEvaluator.java:708)
    at ptolemy.data.expr.ASTPtLeafNode.visit(ASTPtLeafNode.java:125)
        at ptolemy.data.expr.ParseTreeEvaluator.evaluateParseTree(ParseTreeEvaluator.java:105)
        at ptolemy.data.expr.Variable._evaluate(Variable.java:1650)
        at ptolemy.data.expr.Variable._propagate(Variable.java:1738)
        at ptolemy.data.expr.Variable.validate(Variable.java:1436)
        at ptolemy.moml.MoMLParser.endDocument(MoMLParser.java:802)
        at com.microstar.xml.XmlParser.doParse(XmlParser.java:162)
        at com.microstar.xml.XmlParser.parse(XmlParser.java:132)
        at ptolemy.moml.MoMLParser.parse(MoMLParser.java:1556)
        at ptolemy.moml.MoMLParser.parse(MoMLParser.java:1492)
        at ptolemy.moml.MoMLParser.parse(MoMLParser.java:1436)
        at ptolemy.moml.MoMLParser._findOrParse(MoMLParser.java:5002)
        at ptolemy.moml.MoMLParser._attemptToFindMoMLClass(MoMLParser.java:3870)
    at ptolemy.moml.MoMLParser._createEntity(MoMLParser.java:4093)
        at ptolemy.moml.MoMLParser.startElement(MoMLParser.java:2697)
        at com.microstar.xml.XmlParser.parseElement(XmlParser.java:921)
        at com.microstar.xml.XmlParser.parseContent(XmlParser.java:1104)
        at com.microstar.xml.XmlParser.parseElement(XmlParser.java:924)
        at com.microstar.xml.XmlParser.parseDocument(XmlParser.java:481)
        at com.microstar.xml.XmlParser.doParse(XmlParser.java:159)
        at com.microstar.xml.XmlParser.parse(XmlParser.java:132)
        at ptolemy.moml.MoMLParser.parse(MoMLParser.java:1540)
        at ptolemy.moml.MoMLParser.parse(MoMLParser.java:1492)
        at ptolemy.moml.MoMLParser.parse(MoMLParser.java:1436)
        at ptolemy.moml.MoMLModelAttribute.configure(MoMLModelAttribute.java:179)
        at ptolemy.data.ontologies.OntologySolver.configure(OntologySolver.java:131)
        at ptolemy.moml.MoMLModelAttribute.attributeChanged(MoMLModelAttribute.java:135)
    at ptolemy.data.expr.Variable._setTokenAndNotify(Variable.java:1998)
        at ptolemy.data.expr.Variable._evaluate(Variable.java:1652)
        at ptolemy.data.expr.Variable._propagate(Variable.java:1738)
        at ptolemy.data.expr.Variable.validate(Variable.java:1436)
        at ptolemy.moml.MoMLParser.endDocument(MoMLParser.java:802)
        at com.microstar.xml.XmlParser.doParse(XmlParser.java:162)
        at com.microstar.xml.XmlParser.parse(XmlParser.java:132)
        at ptolemy.moml.MoMLParser.parse(MoMLParser.java:1540)
        at ptolemy.moml.MoMLParser.parse(MoMLParser.java:1492)
        at ptolemy.moml.MoMLParser.parse(MoMLParser.java:1436)
        at ptolemy.moml.MoMLSimpleApplication.<init>(MoMLSimpleApplication.java:115)
        at ptolemy.moml.MoMLSimpleApplication.main(MoMLSimpleApplication.java:280)

ptolemy.data.ontologies.OntologySolver.configure(OntologySolver.java:131)

is the only ontology class in the stack trace.
It seems wrong to clear the Constants in that method, but it works.

Ben Lickly correctly pointed out that it is still the case
that if two Ontology models are opened, then they will share data
via the static Constants object.

Probably we should have a separate Constants object that is
contained by the Workspace.

@cxbrooks cxbrooks self-assigned this May 15, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant