Example #1
0
    def update_abstract_code(self, run_namespace):

        # Update the not_refractory variable for the refractory period mechanism
        self.abstract_code = self._get_refractory_code(run_namespace=run_namespace)

        # Get the names used in the refractory code
        _, used_known, unknown = analyse_identifiers(self.abstract_code, self.group.variables,
                                                     recursive=True)

        # Get all names used in the equations (and always get "dt")
        names = self.group.equations.names
        external_names = self.group.equations.identifiers | {'dt'}

        variables = self.group.resolve_all(used_known | unknown | names | external_names,
                                           # we don't need to raise any warnings
                                           # for the user here, warnings will
                                           # be raised in create_runner_codeobj
                                           set(),
                                           run_namespace=run_namespace)

        self.abstract_code += StateUpdateMethod.apply_stateupdater(self.group.equations,
                                                                   variables,
                                                                   self.method_choice)
        user_code = '\n'.join(['{var} = {expr}'.format(var=var, expr=expr)
                               for var, expr in
                               self.group.equations.substituted_expressions])
        self.user_code = user_code
Example #2
0
    def update_abstract_code(self, run_namespace=None, level=0):

        # Update the not_refractory variable for the refractory period mechanism
        self.abstract_code = self._get_refractory_code(run_namespace=run_namespace,
                                                       level=level+1)

        # Get the names used in the refractory code
        _, used_known, unknown = analyse_identifiers(self.abstract_code, self.group.variables,
                                                     recursive=True)

        # Get all names used in the equations (and always get "dt")
        names = self.group.equations.names
        external_names = self.group.equations.identifiers | {'dt'}

        variables = self.group.resolve_all(used_known | unknown | names | external_names,
                                           # we don't need to raise any warnings
                                           # for the user here, warnings will
                                           # be raised in create_runner_codeobj
                                           set(),
                                           run_namespace=run_namespace, level=level+1)

        # Since we did not necessarily no all the functions at creation time,
        # we might want to reconsider our numerical integration method
        self.method = StateUpdateMethod.determine_stateupdater(self.group.equations,
                                                               variables,
                                                               self.method_choice)
        self.abstract_code += self.method(self.group.equations, variables)
        user_code = '\n'.join(['{var} = {expr}'.format(var=var, expr=expr)
                               for var, expr in
                               self.group.equations.substituted_expressions])
        self.user_code = user_code
Example #3
0
    def update_abstract_code(self, run_namespace=None, level=0):

        self.method = StateUpdateMethod.determine_stateupdater(
            self.group.equations, self.group.variables, self.method_choice)

        self.abstract_code = self.method(self.group.equations,
                                         self.group.variables)
Example #4
0
    def update_abstract_code(self, run_namespace):

        # Update the not_refractory variable for the refractory period mechanism
        self.abstract_code = self._get_refractory_code(run_namespace=run_namespace)

        # Get the names used in the refractory code
        _, used_known, unknown = analyse_identifiers(self.abstract_code, self.group.variables,
                                                     recursive=True)

        # Get all names used in the equations (and always get "dt")
        names = self.group.equations.names
        external_names = self.group.equations.identifiers | {'dt'}

        variables = self.group.resolve_all(used_known | unknown | names | external_names,
                                           run_namespace,
                                           # we don't need to raise any warnings
                                           # for the user here, warnings will
                                           # be raised in create_runner_codeobj
                                           user_identifiers=set())
        if len(self.group.equations.diff_eq_names) > 0:
            self.abstract_code += StateUpdateMethod.apply_stateupdater(self.group.equations,
                                                                       variables,
                                                                       self.method_choice,
                                                                       group_name=self.group.name)
        user_code = '\n'.join(['{var} = {expr}'.format(var=var, expr=expr)
                               for var, expr in
                               self.group.equations.get_substituted_expressions(variables)])
        self.user_code = user_code
Example #5
0
    def update_abstract_code(self, run_namespace=None, level=0):

        # Update the not_refractory variable for the refractory period mechanism
        self.abstract_code = self._get_refractory_code(
            run_namespace=run_namespace, level=level + 1)

        # Get the names used in the refractory code
        _, used_known, unknown = analyse_identifiers(self.abstract_code,
                                                     self.group.variables,
                                                     recursive=True)

        # Get all names used in the equations (and always get "dt")
        names = self.group.equations.names
        external_names = self.group.equations.identifiers | {'dt'}

        variables = self.group.resolve_all(
            used_known | unknown | names | external_names,
            # we don't need to raise any warnings
            # for the user here, warnings will
            # be raised in create_runner_codeobj
            set(),
            run_namespace=run_namespace,
            level=level + 1)

        # Since we did not necessarily no all the functions at creation time,
        # we might want to reconsider our numerical integration method
        self.method = StateUpdateMethod.determine_stateupdater(
            self.group.equations, variables, self.method_choice)
        self.abstract_code += self.method(self.group.equations, variables)
        user_code = '\n'.join([
            '{var} = {expr}'.format(var=var, expr=expr)
            for var, expr in self.group.equations.substituted_expressions
        ])
        self.user_code = user_code
Example #6
0
    def update_abstract_code(self, run_namespace=None, level=0):

        # Update the not_refractory variable for the refractory period mechanism
        self.abstract_code = self._get_refractory_code(
            run_namespace=run_namespace, level=level + 1)

        # Get the names used in the refractory code
        _, used_known, unknown = analyse_identifiers(self.abstract_code,
                                                     self.group.variables,
                                                     recursive=True)

        # Get all names used in the equations (and always get "dt")
        names = self.group.equations.names
        external_names = self.group.equations.identifiers | set(['dt'])

        variables = self.group.resolve_all(used_known | unknown | names
                                           | external_names,
                                           run_namespace=run_namespace,
                                           level=level + 1)

        # Since we did not necessarily no all the functions at creation time,
        # we might want to reconsider our numerical integration method
        self.method = StateUpdateMethod.determine_stateupdater(
            self.group.equations, variables, self.method_choice)
        self.abstract_code += self.method(self.group.equations, variables)
Example #7
0
    def update_abstract_code(self):

        self.method = StateUpdateMethod.determine_stateupdater(
            self.group.equations, self.group.variables, self.method_choice)

        self.abstract_code = self.method(self.group.equations,
                                         self.group.variables)
Example #8
0
 def update_abstract_code(self):
     
     self.method = StateUpdateMethod.determine_stateupdater(self.group.equations,
                                                            self.group.variables,
                                                            self.method_choice)
     
     self.abstract_code = self.method(self.group.equations,
                                      self.group.variables)
Example #9
0
 def update_abstract_code(self, run_namespace=None, level=0):
     
     self.method = StateUpdateMethod.determine_stateupdater(self.group.equations,
                                                            self.group.variables,
                                                            self.method_choice)
     
     self.abstract_code = self.method(self.group.equations,
                                      self.group.variables)
Example #10
0
    def __init__(self, group, method):
        self.method_choice = method
        GroupCodeRunner.__init__(self, group,
                                 'stateupdate',
                                 when=(group.clock, 'groups'),
                                 name=group.name + '_stateupdater',
                                 check_units=False)

        self.method = StateUpdateMethod.determine_stateupdater(self.group.equations,
                                                               self.group.variables,
                                                               method)
Example #11
0
    def __init__(self, group, method):
        self.method_choice = method
        CodeRunner.__init__(self,
                            group,
                            'stateupdate',
                            when=(group.clock, 'groups'),
                            name=group.name + '_stateupdater',
                            check_units=False)

        self.method = StateUpdateMethod.determine_stateupdater(
            self.group.equations, self.group.variables, method)
Example #12
0
    def update_abstract_code(self, run_namespace):

        # Update the not_refractory variable for the refractory period mechanism
        self.abstract_code = self._get_refractory_code(
            run_namespace=run_namespace)

        # Get the names used in the refractory code
        _, used_known, unknown = analyse_identifiers(self.abstract_code,
                                                     self.group.variables,
                                                     recursive=True)

        # Get all names used in the equations (and always get "dt")
        names = self.group.equations.names
        external_names = self.group.equations.identifiers | {'dt'}

        variables = self.group.resolve_all(
            used_known | unknown | names | external_names,
            run_namespace,
            # we don't need to raise any warnings
            # for the user here, warnings will
            # be raised in create_runner_codeobj
            user_identifiers=set())
        if len(self.group.equations.diff_eq_names) > 0:
            stateupdate_output = StateUpdateMethod.apply_stateupdater(
                self.group.equations,
                variables,
                self.method_choice,
                method_options=self.method_options,
                group_name=self.group.name)
            if isinstance(stateupdate_output, basestring):
                self.abstract_code += stateupdate_output
            else:
                # Note that the reason to send self along with this method is so the StateUpdater
                # can be modified! i.e. in GSL StateUpdateMethod a custom CodeObject gets added
                # to the StateUpdater together with some auxiliary information
                self.abstract_code += stateupdate_output(self)

        user_code = '\n'.join([
            '{var} = {expr}'.format(var=var, expr=expr) for var, expr in
            self.group.equations.get_substituted_expressions(variables)
        ])
        self.user_code = user_code
Example #13
0
    def __init__(self, group, method):
        self.method_choice = method
        
        GroupCodeRunner.__init__(self, group,
                                       'stateupdate',
                                       when=(group.clock, 'groups'),
                                       name=group.name + '_stateupdater*',
                                       check_units=False)

        self.method = StateUpdateMethod.determine_stateupdater(self.group.equations,
                                                               self.group.variables,
                                                               method)

        # Generate the full abstract code to catch errors in the refractoriness
        # formulation. However, do not fail on KeyErrors since the
        # refractoriness might refer to variables that don't exist yet
        try:
            self.update_abstract_code()
        except KeyError as ex:
            logger.debug('Namespace not complete (yet), ignoring: %s ' % str(ex),
                         'StateUpdater')
Example #14
0
    def __init__(self, group, method):
        self.method_choice = method

        GroupCodeRunner.__init__(self,
                                 group,
                                 'stateupdate',
                                 when=(group.clock, 'groups'),
                                 name=group.name + '_stateupdater*',
                                 check_units=False)

        self.method = StateUpdateMethod.determine_stateupdater(
            self.group.equations, self.group.variables, method)

        # Generate the full abstract code to catch errors in the refractoriness
        # formulation. However, do not fail on KeyErrors since the
        # refractoriness might refer to variables that don't exist yet
        try:
            self.update_abstract_code()
        except KeyError as ex:
            logger.debug(
                'Namespace not complete (yet), ignoring: %s ' % str(ex),
                'StateUpdater')
Example #15
0
    def update_abstract_code(self, run_namespace=None, level=0):

        # Update the not_refractory variable for the refractory period mechanism
        self.abstract_code = self._get_refractory_code(run_namespace=run_namespace,
                                                       level=level+1)

        # Get the names used in the refractory code
        _, used_known, unknown = analyse_identifiers(self.abstract_code, self.group.variables,
                                                     recursive=True)

        # Get all names used in the equations (and always get "dt")
        names = self.group.equations.names
        external_names = self.group.equations.identifiers | set(['dt'])

        variables = self.group.resolve_all(used_known | unknown | names | external_names,
                                           run_namespace=run_namespace, level=level+1)

        # Since we did not necessarily no all the functions at creation time,
        # we might want to reconsider our numerical integration method
        self.method = StateUpdateMethod.determine_stateupdater(self.group.equations,
                                                               variables,
                                                               self.method_choice)
        self.abstract_code += self.method(self.group.equations, variables)
Example #16
0
    def update_abstract_code(self, run_namespace):

        # Update the not_refractory variable for the refractory period mechanism
        self.abstract_code = self._get_refractory_code(run_namespace=run_namespace)

        # Get the names used in the refractory code
        _, used_known, unknown = analyse_identifiers(self.abstract_code, self.group.variables,
                                                     recursive=True)

        # Get all names used in the equations (and always get "dt")
        names = self.group.equations.names
        external_names = self.group.equations.identifiers | {'dt'}

        variables = self.group.resolve_all(used_known | unknown | names | external_names,
                                           run_namespace,
                                           # we don't need to raise any warnings
                                           # for the user here, warnings will
                                           # be raised in create_runner_codeobj
                                           user_identifiers=set())
        if len(self.group.equations.diff_eq_names) > 0:
            stateupdate_output = StateUpdateMethod.apply_stateupdater(self.group.equations,
                                                                      variables,
                                                                      self.method_choice,
                                                                      method_options=self.method_options,
                                                                      group_name=self.group.name)
            if isinstance(stateupdate_output, basestring):
                self.abstract_code += stateupdate_output
            else:
                # Note that the reason to send self along with this method is so the StateUpdater
                # can be modified! i.e. in GSL StateUpdateMethod a custom CodeObject gets added
                # to the StateUpdater together with some auxiliary information
                self.abstract_code += stateupdate_output(self)

        user_code = '\n'.join(['{var} = {expr}'.format(var=var, expr=expr)
                               for var, expr in
                               self.group.equations.get_substituted_expressions(variables)])
        self.user_code = user_code