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

feat: throw runtime error for dimensional check failures #122

Merged
merged 2 commits into from
Jun 13, 2024

Conversation

sanjayankur31
Copy link
Contributor

No description provided.

@sanjayankur31 sanjayankur31 force-pushed the feat/fail-on-dimensional-errors branch from fe74196 to 1c54c44 Compare June 12, 2024 13:15
@sanjayankur31 sanjayankur31 marked this pull request as ready for review June 12, 2024 13:18
@sanjayankur31
Copy link
Contributor Author

All the LEMS examples in the NeuroML2 repo passed, but it'll be good to check if any of our existing models fail because of this (and correct them?).

@pgleeson pgleeson changed the base branch from development to experimental June 13, 2024 16:46
@pgleeson pgleeson merged commit 7acefc0 into experimental Jun 13, 2024
16 checks passed
@sanjayankur31
Copy link
Contributor Author

sanjayankur31 commented Jun 14, 2024

@pgleeson : just ran into this fall out from the dimensional fixes while re-building the java stack in experimental: python getNeuroML.py experimental:

[ERROR] Tests run: 6, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0.965 s <<< FAILURE! -- in org.neuroml.importer.test.SBMLImporterTest
[ERROR] org.neuroml.importer.test.SBMLImporterTest.testIzhikevich -- Time elapsed: 0.038 s <<< ERROR!
org.lemsml.jlems.core.expression.ParseError:
Error checking equations of ComponentType: ComponentType, name=Izhikevicha (none)
b (none)
c (none)
d (none)
Vthresh (none)
i_amp (none)
i_del (none)
tscale (per_time)  = 1per_s
cell (none)  = 1.0

(Dimension mismatch in the equation: time = 1. Residual dimension: ExprDimensional[t=1]
Dimension of time: Dimension[none dimensionless], multiplier=Dimension[per_time t=-1], left=Dimension[ t=-1], rhs=ExprDimensional[dimensionless]
All:{vv=Dimension[none dimensionless], a=Dimension[none dimensionless], i_del=Dimension[none dimensionless], b=Dimension[none dimensionless], c=Dimension[none dimensionless], tscale=Dimension[per_time t=-1], d=Dimension[none dimensionless], i=Dimension[none dimensionless], Vthresh=Dimension[none dimensionless], cell=Dimension[none dimensionless], t=ExprDimensional[t=1], U=Dimension[none dimensionless], i_amp=Dimension[none dimensionless], time=Dimension[none dimensionless]})
        at org.lemsml.jlems.core.type.Lems.resolve(Lems.java:176)
        at org.neuroml.importer.test.SBMLImporterTest.convertSBMLtoLEMSFile(SBMLImporterTest.java:83)
        at org.neuroml.importer.test.SBMLImporterTest.testIzhikevich(SBMLImporterTest.java:40)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.base/java.lang.reflect.Method.invoke(Method.java:568)
        at junit.framework.TestCase.runTest(TestCase.java:177)
        at junit.framework.TestCase.runBare(TestCase.java:142)
        at junit.framework.TestResult$1.protect(TestResult.java:122)
        at junit.framework.TestResult.runProtected(TestResult.java:142)
        at junit.framework.TestResult.run(TestResult.java:125)
        at junit.framework.TestCase.run(TestCase.java:130)
        at junit.framework.TestSuite.runTest(TestSuite.java:241)
        at junit.framework.TestSuite.run(TestSuite.java:236)
        at org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:90)
        at org.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:316)
        at org.apache.maven.surefire.junit4.JUnit4Provider.executeWithRerun(JUnit4Provider.java:240)
        at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:214)
        at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:155)
        at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:385)
        at org.apache.maven.surefire.booter.ForkedBooter.execute(ForkedBooter.java:162)
        at org.apache.maven.surefire.booter.ForkedBooter.run(ForkedBooter.java:507)
        at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:495)
Caused by: org.lemsml.jlems.core.sim.ContentError: Dimension mismatch in the equation: time = 1. Residual dimension: ExprDimensional[t=1]
Dimension of time: Dimension[none dimensionless], multiplier=Dimension[per_time t=-1], left=Dimension[ t=-1], rhs=ExprDimensional[dimensionless]
All:{vv=Dimension[none dimensionless], a=Dimension[none dimensionless], i_del=Dimension[none dimensionless], b=Dimension[none dimensionless], c=Dimension[none dimensionless], tscale=Dimension[per_time t=-1], d=Dimension[none dimensionless], i=Dimension[none dimensionless], Vthresh=Dimension[none dimensionless], cell=Dimension[none dimensionless], t=ExprDimensional[t=1], U=Dimension[none dimensionless], i_amp=Dimension[none dimensionless], time=Dimension[none dimensionless]}
        at org.lemsml.jlems.core.type.dynamics.AbstractStateChange.checkDimensions(AbstractStateChange.java:98)
        at org.lemsml.jlems.core.type.dynamics.Dynamics.checkEquations(Dynamics.java:578)
        at org.lemsml.jlems.core.type.ComponentType.checkEquations(ComponentType.java:682)
        at org.lemsml.jlems.core.type.Lems.resolve(Lems.java:173)
        ... 23 more

[INFO]
[INFO] Results:
[INFO]
[ERROR] Errors:
[ERROR]   SBMLImporterTest.testIzhikevich:40->convertSBMLtoLEMSFile:83 » Parse Error checking equations of ComponentType: ComponentType, name=Izhikevicha (none)
b (none)
c (none)
d (none)
Vthresh (none)
i_amp (none)
i_del (none)
tscale (per_time)  = 1per_s
cell (none)  = 1.0

(Dimension mismatch in the equation: time = 1. Residual dimension: ExprDimensional[t=1]
Dimension of time: Dimension[none dimensionless], multiplier=Dimension[per_time t=-1], left=Dimension[ t=-1], rhs=ExprDimensional[dimensionless]
All:{vv=Dimension[none dimensionless], a=Dimension[none dimensionless], i_del=Dimension[none dimensionless], b=Dimension[none dimensionless], c=Dimension[none dimensionless], tscale=Dimension[per_time t=-1], d=Dimension[none dimensionless], i=Dimension[none dimensionless], Vthresh=Dimension[none dimensionless], cell=Dimension[none dimensionless], t=ExprDimensional[t=1], U=Dimension[none dimensionless], i_amp=Dimension[none dimensionless], time=Dimension[none dimensionless]})
[INFO]
[ERROR] Tests run: 8, Failures: 0, Errors: 1, Skipped: 0
 

Still debugging to see what's causing it.

Edit: added complete traceback

@sanjayankur31
Copy link
Contributor Author

Here's the LEMS file that is generated that it doesn't like:

Izhikevich_LEMS.xml.txt

@sanjayankur31
Copy link
Contributor Author

This is the dynamics block:

        <Dynamics simultaneous="false">
            <StateVariable name="i" dimension="none" exposure="i"/>
            <StateVariable name="vv" dimension="none" exposure="vv"/>
            <StateVariable name="U" dimension="none" exposure="U"/>
            <StateVariable name="time" dimension="none"/>
            <TimeDerivative variable="i" value="tscale * 0"/>
            <TimeDerivative variable="vv" value="tscale * ((((((0.04 * (vv ^ 2.0)) + (5.0 * vv)) + 140.0) - U) + i))"/>
            <TimeDerivative variable="U" value="tscale * ((a * ((b * vv) - U)))"/>
            <TimeDerivative variable="time" value="1"/>
            <OnStart>
                <StateAssignment variable="i" value="0.0"/>
                <StateAssignment variable="vv" value="-70.0"/>
                <StateAssignment variable="U" value="-14.0"/>
            </OnStart>
            <OnCondition test="vv .gt. Vthresh">
                <StateAssignment variable="vv" value="c"/>
                <StateAssignment variable="U" value="(U + d)"/>
            </OnCondition>
            <OnCondition test="(t * tscale)  .gt. i_del">
                <StateAssignment variable="i" value="i_amp"/>
            </OnCondition>
        </Dynamics>
        <Constant name="tscale" value="1per_s" dimension="per_time"/>
        <Constant name="cell" value="1.0" dimension="none"/>

the error is pointing to this line:

            <TimeDerivative variable="time" value="1"/>

I think the RHS needs to be value = "tscale * 1" perhaps?

@pgleeson
Copy link
Member

@sanjayankur31 Yes, probably that's the issue. Note the age of those files though, they predate the sbml showcase and probably izh in nml2... If it's a quick fix then fix it, otherwise they're not needed...

@sanjayankur31
Copy link
Contributor Author

Cool, wasn't too hard to figure out luckily, opened a one line PR here: NeuroML/org.neuroml.import#24

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.

2 participants