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

Python crash with idlist.at() #306

Closed
luciansmith opened this issue Mar 21, 2023 · 3 comments · Fixed by #308
Closed

Python crash with idlist.at() #306

luciansmith opened this issue Mar 21, 2023 · 3 comments · Fixed by #308
Labels
bug Something isn't working

Comments

@luciansmith
Copy link
Member

The following Python program crashes Python entirely:

import libsbml

doc = libsbml.readSBMLFromFile("BIOMD0000000001_url.xml")
model = doc.getModel()
metaIdList = model.getAllElementMetaIdList()
print(metaIdList.size())
metaIdList.at(0)

Same with the similar:

import libsbml

doc = libsbml.readSBMLFromFile("BIOMD0000000001_url.xml")
model = doc.getModel()
idList = model.getAllElementIdList()
print(idList.size())
idList.at(0)

The particular model doesn't matter, but it does have many elements with both IDs and with metaids. The lists claim to be of size zero, however, so there's a couple issues:

  • Those functions should presumably return a list of all the metaids/ids in the model.
  • The 'at' function shouldn't crash Python when called with an invalid argument.
@luciansmith luciansmith added the bug Something isn't working label Mar 21, 2023
@luciansmith
Copy link
Member Author

(Alternatively, the functions could just be scrapped, but if so, it would be nice if 'getAllElements' was added to the Python interface. Or if there was some way of getting all the elements of a document and/or model.)

@fbergmann
Copy link
Member

accessing an idlist past its end, does throw an STL exception, that we can catch. As for why you dont get elements returned. Thats the way it is implemented, since those operations are expensive, these lists have to be populated before being accessed. that way people can decide when to populate / clear / get them.

 /**
   * Clears the internal list of the identifiers of all elements within this Model object.
   *
   * @see populateAllElementIdList()
   * @see isPopulatedAllElementIdList()
   */
  void clearAllElementIdList();


  /**
   * Populates the internal list of the metaids of all elements within this Model object.
   *
   * This method tells libSBML to retrieve the identifiers of all elements
   * of the enclosing Model object.  The result is stored in an internal list
   * of metaids.  Users can access the resulting data by calling the method
   * getAllElementMetaIdList().
   *
   * @warning Retrieving all elements within a model is a time-consuming operation.
   * Callers may want to call isPopulatedAllElementMetaIdList() to determine
   * whether the metaid list may already have been populated.
   *
   * @see isPopulatedAllElementMetaIdList()
   */
  void populateAllElementMetaIdList();


  /**
   * Predicate returning @c true if libSBML has a list of the metaids of all 
   * components of this model.
   *
   * @return @c true if the metaid list has already been populated, @c false
   * otherwise.
   */
  bool isPopulatedAllElementMetaIdList() const;


  /**
   * Returns the internal list of the metaids of all elements within this Model object.
   *
   * @return an IdList of all the metaids in the model.
   *
   * @see populateAllElementMetaIdList()
   * @see isPopulatedAllElementMetaIdList()
   */
  IdList getAllElementMetaIdList() const;


  /**
   * Clears the internal list of the metaids of all elements within this Model object.
   *
   * @see populateAllElementMetaIdList()
   * @see isPopulatedAllElementMetaIdList()
   */
  void clearAllElementMetaIdList();

it does describe that in python as well:

In [3]: ? m.getAllElementIdList
Signature:  m.getAllElementIdList()
Docstring:
getAllElementIdList(Model self) -> IdList

Returns the internal list of the identifiers of all elements within
this Model object.

Returns an IdList of all the identifiers in the model.

See also populateAllElementIdList(), isPopulatedAllElementIdList().

@luciansmith
Copy link
Member Author

Is there any use case for someone calling 'getAllElementMetaIdList' and not wanting to populate it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants