LLVMExecutableModel

class LLVMExecutableModel : public rr::ExecutableModel

LLVM executable model.

Interface to LLVM executable model.

Author

ETS

Public Functions

inline virtual std::string getExecutableModelDesc() const

Returns a human-readable description of the code generation backend, e.g. LLVM, legacy C, etc.

Author

JKM

Date

07/31/2015

LLVMExecutableModel()

the default ctor just zeros out all our private bits, then the main construction is handled by the model generator.

LLVMExecutableModel(const std::shared_ptr<ModelResources> &resources, LLVMModelData *modelData)

takes ownership of the LLVMModelData pointer.

LLVMExecutableModel(std::istream &in, uint modelGeneratorOpt)
virtual ~LLVMExecutableModel()
virtual std::string getModelName()

get the name of the model

virtual void setTime(double _time)
virtual double getTime()
void evalInitialConditions(uint32_t flags = 0)

evaluate the initial conditions specified in the sbml, this entails evaluating all InitialAssigments, AssigmentRules, initial values, etc…

Then the model state is fully set.

virtual void reset()

call reset(options) with defaut options.

virtual void reset(int options)

reset the model accordign to a bitfield specified by the SelectionRecord::SelectionType values.

virtual int getNumIndFloatingSpecies()

independent species do are not defined by rules, they typically participate in reactions and can have thier values set at any time.

virtual int getNumDepFloatingSpecies()

dependent species are defined by rules and the only way to change them is by changing the values on which they depend.

virtual int getNumFloatingSpecies()

total number of floating species.

virtual int getNumBoundarySpecies()

get the number of boundary species.

virtual int getNumGlobalParameters()

get the number of global parameters

virtual int getNumCompartments()
virtual int getCompartmentIndexForFloatingSpecies(size_t index)
virtual int getCompartmentIndexForBoundarySpecies(size_t index)
virtual int getGlobalParameterValues(size_t len, int const *indx, double *values)

get the global parameter values

Parameters:
  • len[in] the length of the indx and values arrays.

  • indx[in] an array of length len of boundary species to return.

  • values[out] an array of at least length len which will store the returned boundary species amounts.

virtual int setGlobalParameterValues(size_t len, int const *indx, const double *values)
virtual int setGlobalParameterValues(size_t len, int const *indx, const double *values, bool strict)
virtual int getNumReactions()

get the number of reactions the model has

virtual int getReactionRates(size_t len, int const *indx, double *values)

get the std::vector of reaction rates.

Parameters:
  • len – the length of the supplied buffer, must be >= reaction rates size.

  • indx – pointer to index array. If NULL, then it is ignored and the reaction rates are copied directly into the supplied buffer.

  • values – pointer to user supplied buffer where rates will be stored.

virtual int getCompartmentVolumes(size_t len, int const *indx, double *values)

get the compartment volumes

Parameters:
  • len[in] the length of the indx and values arrays.

  • indx[in] an array of length len of boundary species to return.

  • values[out] an array of at least length len which will store the returned boundary species amounts.

virtual int getNumRateRules()
virtual std::vector<std::string> getRateRuleSymbols() const

Gets the symbols defined by rate rules, i.e. returns all x such that x’ = f(x) is a rule which defines parameter x.

Author

JKM

Date

07/31/2015

virtual void getRateRuleValues(double *rateRuleValues)

copy (but do not evaluate) existing rate rules values into a buffer.

virtual std::string getStateVectorId(size_t index)

get the id of an element of the state std::vector.

virtual int getStateVector(double *stateVector)

copies the internal model state std::vector into the provided buffer.

Parameters:

stateVector[out] a buffer to copy the state std::vector into, if NULL, return the size required.

Returns:

the number of items coppied into the provided buffer, if stateVector is NULL, returns the length of the state std::vector.

virtual int setStateVector(const double *stateVector)

sets the internal model state to the provided packed state std::vector.

Parameters:

stateVector[in] an array which holds the packed state std::vector, must be at least the size returned by getStateVector.

Returns:

the number of items copied from the state std::vector, negative on failure.

virtual void getStateVectorRate(double time, const double *y, double *dydt = 0)

where most of the juicy bits occur.

the state std::vector y is the rate rule values and floating species concentrations concatenated. y is of length numFloatingSpecies + numRateRules.

The state std::vector is packed such that the first n raterule elements are the values of the rate rules, and the last n floatingspecies are the floating species values.

Parameters:
  • time[in] current simulator time

  • y[in] state std::vector, must be of size returned by getStateVector

  • dydt[out] calculated rate of change of the state std::vector, if null, it is ignored.

virtual void testConstraints()
virtual std::string getInfo()
virtual int getFloatingSpeciesIndex(const std::string&)
virtual std::string getFloatingSpeciesId(size_t index)
virtual int getBoundarySpeciesIndex(const std::string&)
virtual std::string getBoundarySpeciesId(size_t index)
virtual int getFloatingSpeciesAmounts(size_t len, int const *indx, double *values)

get the floating species amounts

Parameters:
  • len[in] the length of the indx and values arrays.

  • indx[in] an array of length len of boundary species to return.

  • values[out] an array of at least length len which will store the returned boundary species amounts.

virtual int getFloatingSpeciesAmountRates(size_t len, int const *indx, double *values)

get the floating species amount rates

Parameters:
  • len[in] the length of the indx and values arrays.

  • indx[in] an array of length len of floating species to return.

  • values[out] an array of at least length len which will store the returned floating species amount rates.

virtual int getFloatingSpeciesConcentrationRates(size_t len, int const *indx, double *values)

get the floating species concentration rates

Parameters:
  • len[in] the length of the indx and values arrays.

  • indx[in] an array of length len of floating species to return.

  • values[out] an array of at least length len which will store the returned floating species concentration rates.

virtual int getFloatingSpeciesConcentrations(size_t len, int const *indx, double *values)

get the floating species concentrations

Parameters:
  • len[in] the length of the indx and values arrays.

  • indx[in] an array of length len of boundary species to return.

  • values[out] an array of at least length len which will store the returned boundary species amounts.

virtual int setFloatingSpeciesConcentrations(size_t len, int const *indx, double const *values)

set the floating species concentrations

Parameters:
  • len[in] the length of the indx and values arrays.

  • indx[in] an array of length len of boundary species to return.

  • values[in] an array of at least length len which will store the returned boundary species amounts.

virtual int setFloatingSpeciesAmounts(size_t len, int const *indx, const double *values)
virtual int setFloatingSpeciesAmounts(size_t len, int const *indx, const double *values, bool strict)
virtual int getBoundarySpeciesAmounts(size_t len, int const *indx, double *values)

get the boundary species amounts

Parameters:
  • len[in] the length of the indx and values arrays.

  • indx[in] an array of length len of boundary species to return.

  • values[out] an array of at least length len which will store the returned boundary species amounts.

virtual int getBoundarySpeciesConcentrations(size_t len, int const *indx, double *values)

get the boundary species concentrations

Parameters:
  • len[in] the length of the indx and values arrays.

  • indx[in] an array of length len of boundary species to return.

  • values[out] an array of at least length len which will store the returned boundary species amounts.

virtual int setBoundarySpeciesConcentrations(size_t len, int const *indx, double const *values)

get the boundary species concentrations

Parameters:
  • len[in] the length of the indx and values arrays.

  • indx[in] an array of length len of boundary species to return.

  • values[in] an array of at least length len which will store the returned boundary species amounts.

virtual int setBoundarySpeciesAmounts(size_t len, int const *indx, double const *values)

get the boundary species amounts

Parameters:
  • len[in] the length of the indx and values arrays.

  • indx[in] an array of length len of boundary species to return.

  • values[in] an array of at least length len which will store the returned boundary species amounts.

virtual int setBoundarySpeciesAmounts(size_t len, int const *indx, double const *values, bool strict)
virtual int getGlobalParameterIndex(const std::string&)

index of the global parameter id, -1 if it does not exist.

virtual std::string getGlobalParameterId(size_t)

id of the indexed global parameter.

virtual int getCompartmentIndex(const std::string&)
virtual std::string getCompartmentId(size_t)
virtual int getReactionIndex(const std::string&)

get the index of a named reaction

Returns:

>= 0 on success, < 0 on failure.

virtual std::string getReactionId(size_t)

get the name of the specified reaction

virtual int getStoichiometryIndex(const std::string&)

get the index of a named stoichiometry

Returns:

>= 0 on success, < 0 on failure.

virtual int getStoichiometryIndex(const std::string &speciesId, const std::string &reactionId)

get the index of a named stoichiometry

Returns:

>= 0 on success, < 0 on failure.

virtual std::string getStoichiometryId(size_t)

get the name of the specified stoichiometry

virtual void print(std::ostream &stream)
virtual int getNumConservedMoieties()
virtual int getConservedMoietyIndex(const std::string &name)
virtual std::string getConservedMoietyId(size_t index)
virtual int getConservedMoietyValues(size_t len, int const *indx, double *values)
virtual int setConservedMoietyValues(size_t len, int const *indx, const double *values)
virtual int setCompartmentVolumes(size_t len, int const *indx, const double *values)
virtual int setCompartmentVolumes(size_t len, int const *indx, const double *values, bool strict)
virtual int setStoichiometries(size_t len, int const *indx, const double *values)
virtual int setStoichiometries(size_t len, int const *indx, const double *values, bool strict)
virtual int setStoichiometry(int index, double value)
virtual int setStoichiometry(int speciesIndex, int reactionIndex, double value)
virtual double getStoichiometry(int index)

Get the current stiochiometry value with the given index.

If either are not valid, NaN is returned.

virtual double getStoichiometry(int speciesIndex, int reactionIndex)

Get the current stiochiometry value for the given species / reaction.

If either are not valid, NaN is returned.

virtual int setFloatingSpeciesInitConcentrations(size_t len, const int *indx, double const *values)

Set the initial concentrations of the floating species.

Takes the same indices as the other floating species methods.

Note, if a floating species has an initial assignment rule, than the initial conditions value can only be set by updating the values on which it depends, it can not be set directly.

virtual int setBoundarySpeciesInitConcentrations(size_t len, const int *indx, double const *values)

Set the initial concentrations of the boundary species.

Takes the same indices as the other boundary species methods.

Note, if a boundary species has an initial assignment rule, than the initial conditions value can only be set by updating the values on which it depends, it can not be set directly.

virtual int getFloatingSpeciesInitConcentrations(size_t len, const int *indx, double *values)

Get the initial concentrations of the floating species, uses the same indexing as the other floating species methods.

virtual int getBoundarySpeciesInitConcentrations(size_t len, const int *indx, double *values)

Get the initial concentrations of the boundary species, uses the same indexing as the other boundary species methods.

virtual int setFloatingSpeciesInitAmounts(size_t len, const int *indx, double const *values)

Set the initial amounts of the floating species.

Takes the same indices as the other floating species methods.

Note, if a floating species has an initial assignment rule, than the initial conditions value can only be set by updating the values on which it depends, it can not be set directly.

virtual int setBoundarySpeciesInitAmounts(size_t len, const int *indx, double const *values)

Set the initial amounts of the boundary species.

Takes the same indices as the other boundary species methods.

Note, if a boundary species has an initial assignment rule, than the initial conditions value can only be set by updating the values on which it depends, it can not be set directly.

virtual int getFloatingSpeciesInitAmounts(size_t size_t, const int *indx, double *values)

Get the initial amounts of the floating species, uses the same indexing as the other floating species methods.

virtual int getBoundarySpeciesInitAmounts(size_t size_t, const int *indx, double *values)

Get the initial amounts of the boundary species, uses the same indexing as the other boundary species methods.

virtual int setCompartmentInitVolumes(size_t len, const int *indx, double const *values)

Set the initial volumes of the compartments.

Takes the same indices as the other compartment methods.

Note, if a compartment has an initial assignment rule, than the initial conditions value can only be set by updating the values on which it depends, it can not be set directly.

virtual int getCompartmentInitVolumes(size_t len, const int *indx, double *values)

Get the initial volume of the compartments, uses the same indexing as the other compartment methods.

virtual int setGlobalParameterInitValues(size_t len, const int *indx, double const *values)

Set the initial value of the global parameter.

Takes the same indices as the other global parameter methods.

virtual int getGlobalParameterInitValues(size_t len, const int *indx, double *values)

Get the initial amounts of the global parameter, uses the same indexing as the other global parameter methods.

virtual void getIds(int types, std::list<std::string> &ids)

populates a given list with all the ids that this class can accept.

virtual int getSupportedIdTypes()

returns a bit field of the ids that this class supports.

virtual double getValue(const std::string &id)

gets the value for the given id std::string.

The std::string must be a SelectionRecord std::string that is accepted by this class.

virtual void setValue(const std::string &id, double value)

sets the value coresponding to the given selection stringl

virtual void setRandomSeed(int64_t)

set the seed used by the random number generator.

This will by definition reset the RNG.

virtual int64_t getRandomSeed()

get the seed used by the RNG.

virtual double getRandom()

Get a uniform random number between 0 and 1 created by the RNG.

The type of RNG can be specified in the config file with the RANDOM_GENERATOR_TYPE key.

virtual int getNumEvents()
virtual int getEventTriggers(size_t len, const int *indx, unsigned char *eventState)

Get status of event triggers.

When len <= 0, returns number of events. Otherwise, sets bits in eventState to the corresponding trigger.

Author

ETS

Parameters:
  • len[in] The length of indx

  • indx[in] An index into eventState

  • eventState[out] The state of the event triggers

virtual int applyEvents(double timeEnd, const unsigned char *previousEventState, const double *initialState, double *finalState)

erases expired events, and applies ripe events as long as we have ripe events.

virtual void getEventRoots(double time, const double *y, double *gdot)

evaluate the event ‘roots’ &#8212; when events transition form triggered - non-triggered or triggered to non-triggered state.

Simplest method is to return 1 for triggered, -1 for not-triggered, so long as there is a zero crossing.

Parameters:
  • time[in] current time

  • y[in] the state std::vector

  • gdot[out] result event roots, this is of length numEvents.

virtual void getPiecewiseTriggerRoots(double time, const double *y, double *gdot)
virtual double getNextPendingEventTime(bool pop)
virtual int getPendingEventSize()
virtual void resetEvents()
inline double getEventDelay(size_t event)
inline double getEventPriority(size_t event)
bool getEventTrigger(size_t event)
inline bool getEventUseValuesFromTriggerTime(size_t event)
inline bool getEventInitialValue(size_t event)
inline bool getEventPersistent(size_t event)
inline size_t getEventBufferSize(size_t event)
inline void getEventData(size_t eventId, double *data)
inline void assignEvent(size_t eventId, double *data)

assign or apply the event using the given data.

bool getEventTieBreak(size_t eventA, size_t eventB)
virtual int getEventIndex(const std::string &eid)

Gets the index for an event id.

If there is no event with this id, returns -1.

virtual std::string getEventId(size_t index)
virtual void getEventIds(std::list<std::string> &out)
virtual int getNumPiecewiseTriggers()

We do root-finding for ‘piecewise triggers’: those times in a piecewise function that transition from one condition to the next.

virtual void getAssignmentRuleIds(std::list<std::string> &out)
virtual void getRateRuleIds(std::list<std::string> &out)
virtual void getInitialAssignmentIds(std::list<std::string> &out)
virtual void setEventListener(size_t index, rr::EventListenerPtr eventHandler)
virtual rr::EventListenerPtr getEventListener(size_t index)
virtual double getFloatingSpeciesAmountRate(size_t index, const double *reactionRates)

Get the amount rate of change for the i’th floating species given a reaction rates std::vector.

TODO: This should be merged with getFloatingSpeciesAmountRates, but that will break inteface, will do in next point release.

TODO: If the conversion factor changes in between getting the reaction rates std::vector via getReactionRates

Parameters:
  • index – index of the desired floating speceis rate.

  • reactionRates – pointer to buffer of reaction rates.

virtual int getRateRuleRates(size_t len, int const *indx, double *values)

calculate rate rule values.

TODO redo this function, not very effecient.

inline virtual uint32_t getFlags() const

Get the current set of flags.

inline virtual void setFlags(uint32_t val)

Set certain options that determine the state of the ExecutableModel, these are listed in.

virtual void saveState(std::ostream &out)

Private Types

enum [anonymous]

Values:

enumerator DIRTY_INIT_SPECIES
enumerator DIRTY_CONSERVED_MOIETIES
enumerator DIRTY_REACTION_RATES
typedef unsigned long long TieBreakKey
typedef std::map<TieBreakKey, bool> TieBreakMap
typedef std::string (LLVMExecutableModel::* GetNameFuncPtr)(size_t)
typedef cxx11_ns::unordered_map<std::string, rr::SelectionRecord> SelectionMap

cache the selection records

Private Functions

const rr::SelectionRecord &getSelection(const std::string &sel)

get a selection record for a given stirng.

if the std::string is valid, the SelectionRecord is created and cached.

if the std::string is invalid, and exception is thrown.

bool applyEvents(unsigned char *prevEventState, unsigned char *currEventState)

previous state get current state current state becomes previous state for next itteration evaluate first pending event

void resetOneType(int &opt, int thistype, int independents, int total, int (LLVMExecutableModel::* getInit)(size_t, const int*, double*), int (LLVMExecutableModel::* setCurrent)(size_t, const int*, const double*), string (LLVMModelDataSymbols::* getTypeId)(size_t) const, double *buffer, std::map<std::string, int> &inits, std::map<std::string, double> &initvals)
int getValues(double (*funcPtr)(LLVMModelData*, size_t), size_t len, const int *indx, double *values)

get the values from the model struct and populate the given values array.

int setValues(bool (*funcPtr)(LLVMModelData*, int, double), GetNameFuncPtr, size_t len, const int *indx, const double *values, bool strict = true)

set the model struct values from the given array.

Private Members

rrllvm::EventQueue pendingEvents
std::vector<double> eventAssignTimes

the time delayed events were triggered.

TieBreakMap tieBreakMap
LLVMModelData *modelData

the model generator maintians a cache of generated models.

cxx11_ns::shared_ptr<ModelResources> resources
const LLVMModelDataSymbols *symbols
EvalReactionRatesCodeGen::FunctionPtr evalReactionRatesPtr
EvalInitialConditionsCodeGen::FunctionPtr evalInitialConditionsPtr
GetBoundarySpeciesAmountCodeGen::FunctionPtr getBoundarySpeciesAmountPtr
GetFloatingSpeciesAmountCodeGen::FunctionPtr getFloatingSpeciesAmountPtr
GetBoundarySpeciesConcentrationCodeGen::FunctionPtr getBoundarySpeciesConcentrationPtr
GetFloatingSpeciesConcentrationCodeGen::FunctionPtr getFloatingSpeciesConcentrationPtr
GetCompartmentVolumeCodeGen::FunctionPtr getCompartmentVolumePtr
GetGlobalParameterCodeGen::FunctionPtr getGlobalParameterPtr
EvalRateRuleRatesCodeGen::FunctionPtr evalRateRuleRatesPtr
GetEventTriggerCodeGen::FunctionPtr getEventTriggerPtr
GetEventPriorityCodeGen::FunctionPtr getEventPriorityPtr
GetEventDelayCodeGen::FunctionPtr getEventDelayPtr
EventTriggerCodeGen::FunctionPtr eventTriggerPtr
EventAssignCodeGen::FunctionPtr eventAssignPtr
GetPiecewiseTriggerCodeGen::FunctionPtr getPiecewiseTriggerPtr
EvalVolatileStoichCodeGen::FunctionPtr evalVolatileStoichPtr
EvalConversionFactorCodeGen::FunctionPtr evalConversionFactorPtr
SetBoundarySpeciesAmountCodeGen::FunctionPtr setBoundarySpeciesAmountPtr
SetFloatingSpeciesAmountCodeGen::FunctionPtr setFloatingSpeciesAmountPtr
SetBoundarySpeciesConcentrationCodeGen::FunctionPtr setBoundarySpeciesConcentrationPtr
SetFloatingSpeciesConcentrationCodeGen::FunctionPtr setFloatingSpeciesConcentrationPtr
SetCompartmentVolumeCodeGen::FunctionPtr setCompartmentVolumePtr
SetGlobalParameterCodeGen::FunctionPtr setGlobalParameterPtr
SetFloatingSpeciesInitConcentrationCodeGen::FunctionPtr setFloatingSpeciesInitConcentrationsPtr
SetBoundarySpeciesInitConcentrationCodeGen::FunctionPtr setBoundarySpeciesInitConcentrationsPtr
GetFloatingSpeciesInitConcentrationCodeGen::FunctionPtr getFloatingSpeciesInitConcentrationsPtr
GetBoundarySpeciesInitConcentrationCodeGen::FunctionPtr getBoundarySpeciesInitConcentrationsPtr
SetFloatingSpeciesInitAmountCodeGen::FunctionPtr setFloatingSpeciesInitAmountsPtr
GetFloatingSpeciesInitAmountCodeGen::FunctionPtr getFloatingSpeciesInitAmountsPtr
SetBoundarySpeciesInitAmountCodeGen::FunctionPtr setBoundarySpeciesInitAmountsPtr
GetBoundarySpeciesInitAmountCodeGen::FunctionPtr getBoundarySpeciesInitAmountsPtr
SetCompartmentInitVolumeCodeGen::FunctionPtr setCompartmentInitVolumesPtr
GetCompartmentInitVolumeCodeGen::FunctionPtr getCompartmentInitVolumesPtr
GetGlobalParameterInitValueCodeGen::FunctionPtr getGlobalParameterInitValuePtr
SetGlobalParameterInitValueCodeGen::FunctionPtr setGlobalParameterInitValuePtr
SelectionMap selectionRecordCache
std::vector<rr::EventListenerPtr> eventListeners

event handlers, we don’t own these, just borrow them

array of modelData.numEvents length.

double conversionFactor

the sbml conversion factor.

TODO: this has issues in that its possible for the conversion factor to change. This needs to be moved into an LLVM generated function instead of a class variable.

uint32_t dirty

what items are dirty

uint32_t flags

Private Static Functions

static LLVMExecutableModel *dummy()

Friends

friend class LLVMModelGenerator
template<typename a_type, typename b_type>
friend void copyCachedModel(a_type *src, b_type *dst)

copy the cached model fields between a cached model, and a executable model.

We don’t want to have ExecutableModel inherit from CahcedModel because they do compleltly different things, and have completly differnt deletion semantics