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

XMLSerializer ignores value of parameters #70

Open
tarelli opened this issue Jun 30, 2015 · 1 comment
Open

XMLSerializer ignores value of parameters #70

tarelli opened this issue Jun 30, 2015 · 1 comment

Comments

@tarelli
Copy link
Member

tarelli commented Jun 30, 2015

The following is inside a component:

ParamValue: delay(time, svalue = null, dvalue = NaN) = 2.2E-4
ParamValue: duration(time, svalue = null, dvalue = NaN) = 4.0E8
ParamValue: amplitude(current, svalue = null, dvalue = NaN) = 7.300000000000001E-10

however when doing

String serialisedModel = XMLSerializer.serialize(lems)

the file shows

<pulseGenerator id="pulseGen1" delay="0ms" duration="100000000s" amplitude="0.08nA"/>

I suspect the problem is caused by the following objects which are also inside the LEMS component model:

XMLAttribute(delay, 0ms) 
XMLAttribute(duration, 100000000s) 
XMLAttribute(amplitude, 0.08nA) 

which I suspect is what is getting used during serialization.
The same information seems to be stored in two places, if XMLAttribute are necessary for whatever reason then the library should reconcile them if the user changes the value of a parameter through the API

lemsParameter.setDoubleValue(...)

which is what we are doing to let the user change the parameters in the model.
Either that or there should be some method that can be called to update the XMLAttributes.
However ideally redundant information should probably be best avoided altogether.

@robertcannon
Copy link
Member

The problem here is commented at line 236 of XMLSerializer.java. ParamValue is dimensionless whereas the original attribute value is the only place we have the unit that was supplied with the quantity.

When you let the user change the values, you must be making them supply them in SI, or do you do unit conversions too? By the time you're into ParamValues there's no longer a 1:1 mapping back to XML so I'm not really sure what the solution is here: units get discarded as soon as possible in the pipeline and ParamValues shouldn't know about them as they don't affect the subsequent calculation.

One option would be to supply the attribute value from the UI (number and unit) rather than than accessing the ParamValue directly. Or we could use the ParamValues and add the SI units (so you'd read a model with "mV" and write it out and get with "V"). Or, we store a set of preferred units with each component for its parameter values which are just used for serializing. Maybe the last option is best?

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

No branches or pull requests

2 participants