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: support addition of new LEMS Components to NeuroML models #195

Closed
wants to merge 5 commits into from

Conversation

sanjayankur31
Copy link
Contributor

These will not be validated since they're not part of the schema, but this will allow users to use Components of newly defined ComponentTypes in Python, without having to resort to editing XML later.

This contains the id and type fields as compulsory, but uses
"anyAttribute" to allow other attributes that are not required to be
included in the schema. This will an element in BaseWithoutId which is
inherited by all elements, meaning that all elements can now have
children of the form: `<Component id=.. type=.. more_attributes=...>`
This can have any number of attributes that are not mentioned in the
schema, so we need to handle it differently.

https://www.w3.org/TR/xmlschema11-1/#Wildcards
@sanjayankur31
Copy link
Contributor Author

@pgleeson this seems to allow the addition of "<Component ..>" bits to the other elements. For ex:

        cell = component_factory("Cell", id="simple_cell")  # type: neuroml.Cell
        cell.set_spike_thresh("40mV")
        cell.set_init_memb_potential("-70mV")
        cell.set_specific_capacitance("1 uF_per_cm2")
        cell.add_membrane_property(
            "Component", id="test_comp", type="test_type", value="10 mV"
        )
        cell_str = str(cell)
        print(cell_str)

generates:

<Cell id="simple_cell">
    <morphology id="morphology">
        <segmentGroup id="soma_group" neuroLexId="GO:0043025">
            <notes>Default soma segment group for the cell</notes>
        </segmentGroup>
        <segmentGroup id="all">
            <notes>Default segment group for all segments in the cell</notes>
        </segmentGroup>
    </morphology>
    <biophysicalProperties id="biophys">
        <membraneProperties>
            <Component value="10 mV" id="test_comp" type="test_type"/>
            <spikeThresh value="40mV"/>
            <specificCapacitance value="1 uF_per_cm2"/>
            <initMembPotential value="-70mV"/>
        </membraneProperties>
        <intracellularProperties/>
    </biophysicalProperties>
</Cell>

The "Component" class requires an id and type, and then can take any other arguments---these extra ones won't be validated against the schema, but LEMS will throw errors if they are wrong/missing.

What do you think? Testing to see if LEMS is happy with this.

(If this is OK, I'll update the schema in the NeuroML2 repo too. Haven't changed that yet.)

@sanjayankur31 sanjayankur31 marked this pull request as ready for review August 1, 2024 08:45
@sanjayankur31 sanjayankur31 added the T: enhancement Type: enhancement label Aug 1, 2024
@pgleeson
Copy link
Member

pgleeson commented Aug 1, 2024

Hrmmm, am unsure about all this... Seems to be making the schema more complex than it needs to be to fix some issues with just one of the APIs. Need to think about it a bit and discuss next time in the office...

Note there are a lot of whitespace changes in the schema which should be updated separately..?

@sanjayankur31
Copy link
Contributor Author

Cool, sounds good.

I think this should propagate to all APIs that properly support the anyAttribute XSD construct, since it's part of the XSD standard:

https://www.w3.org/TR/xmlschema11-1/#Wildcards

The change to generatedssuper is just me making this also accessible via the component factory framework for consistency. People can also do:

from neuroml import Component

newcomp = Component(id="something", type="something else")
newcomp.anyAttributes_ = {"att1": "1mV"} # generateDS does not handle these in the constructor for some reason

Basically each element has gained an optional "Component" child element that may be used to refer to new ComponentTypes. NeuroML files with Components are now valid against the schema too. Then LEMS will do the final checks on whether the Component refers to the right ComponentType and if it has the necessary parameters etc.

In addition to making stuff with Components valid NeuroML, the main advantage is that people don't have to manually edit XML (or JSON/YAML if we also start supporting them) files---for large cells and so on, that's tedious and error prone, and it disconnects the XML serialization from the API based model description.

Yeh, the whitespaces are because of pre-commit removing trailing whitespaces, we'll get rid of those changes before merging. We'll probably want this to bump the schema version anyway (I'll go see if there's a way of disabling that pre-commit hook for the xsd files in the meantime)

@sanjayankur31 sanjayankur31 marked this pull request as draft August 13, 2024 11:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T: enhancement Type: enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants