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: add method to add child/children elements to objects #115

Merged
merged 29 commits into from
Nov 17, 2021

Conversation

sanjayankur31
Copy link
Contributor

@sanjayankur31 sanjayankur31 commented Oct 13, 2021

  • also adds a corresponding method to get some information about them

Opening this against the existing generateds PR since it'll cause conflicts otherwise. (#110)

TODO:

  • add tests
  • handle case where there may be multiple members that can accept objects of a particular class (like pre and post synaptic populations in synapses)
  • check overlap with methods in utils and remove what isn't required

@sanjayankur31 sanjayankur31 added the T: enhancement Type: enhancement label Oct 13, 2021
@sanjayankur31 sanjayankur31 self-assigned this Oct 13, 2021
- also adds a corresponding method to get some information about them

The function is added to `BaseWithoutId` and so should be inherited by
everything.

The `add` method:

- gets the list of the members defined by generateDS for each each class
- checks the type of the object being added to the types of the members
  to find the right member to add to. If a member with the type cannot
  be found, an Exception is raised.
- if a member is found, it can either be a child member (can only have
  one value) or a children member (can have multiple values in a list).
- For child members a check is made to see if a value is already set. If
  not, the value is set to the given object.
- For children members, a check is made to see if the object has already
  been added. If not, the object is added.
- If either test fails, an Exception is raised (since one does not need
  to re-add objects to update their value)
- A `force` option allows overwriting and readdition, but is set to
  `False` by default.

So, example usage would be of this type:

```
cell = neuroml.Cell(id="acell")
biprop = neuroml.BiophysicalProperties(id="biprop")
cell.add(biprop) # success
cell.add(biprop) # will throw an Exception unless `force=True`
cell.add("a string") # will throw an Exception since no member has a type "str"
```

Note: we have a few ComponentTypes which don't inherit from anywhere,
and we need to check if these are correctly defined in the XSD file
(Location is an example).
@sanjayankur31
Copy link
Contributor Author

Note: we could probably use a better name than "get_infofor the second function. Maybeshoworinfo? Additionally, we could also merge this with the addfunction so that if theadd` function is called without arguments, it gives information about the current contents of the particular NeuroML class container?

@sanjayankur31
Copy link
Contributor Author

tweaked the function names to:

  • add
  • info

if add is called without arguments, it also spews out the info output, so users can just use add religiously to confirm what the members of a NeuroML class should be.

@sanjayankur31 sanjayankur31 marked this pull request as draft October 28, 2021 10:13
Attempting to readd an object is harmless, so make this a warning.

Also fixes the comparison to not use `is` because it doesn't only
compare the reference, it also compares the value.
We want a copy of the object to add other inherited member_data_types_
to. If we use `=`, we get a reference to `self.member_data_types_`
object and end up modifying it, which we do not want to do. Not only
does that change the nml.py representation, it also means that all the
"expanded" lists of `member_data_types_` is held in memory for every
neuroml object which greatly increases the memory foot print of models.

So, calculate the complete list of member_data_types_ when required and
then forget about it, which will allow memory to be garbage collected
and freed up.
@sanjayankur31 sanjayankur31 marked this pull request as ready for review November 8, 2021 21:25
@sanjayankur31 sanjayankur31 merged commit 5afb7af into feat/dev-new-generateds Nov 17, 2021
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.

None yet

1 participant