def __init__(self, profile=None):
     PrettyPrinter.__init__(self, profile)
     try:
         self.__ppMatrix = self._print_Matrix
     except AttributeError:
         # renamed in 0.7.2
         self.__ppMatrix = self._print_MatrixBase
Beispiel #2
0
 def __init__(self, profile=None):
     PrettyPrinter.__init__(self, profile)
     try:
         self.__ppMatrix = self._print_Matrix
     except AttributeError:
         # renamed in 0.7.2
         self.__ppMatrix = self._print_MatrixBase
Beispiel #3
0
    def _print_Symbol(self, e):
        # handle escript symbols
        if isinstance(e, Symbol):
            if e.getRank()<=4:
                return self._print(e.__array__())
            return PrettyPrinter._print_Symbol(self,e)

        # e is a sympy Symbol. Remove any brackets from the name in case e is
        # a component
        n,c=Symbol._symComp(e)
        if len(c)==0:
            return PrettyPrinter._print_Symbol(self,e)
        s=sympy.Symbol(n+'_'.join([str(i) for i in c]))
        return PrettyPrinter._print_Symbol(self, s)
    def _print_Symbol(self, e):
        # handle escript symbols
        if isinstance(e, Symbol):
            if e.getRank() <= 4:
                return self._print(e.__array__())
            return PrettyPrinter._print_Symbol(self, e)

        # e is a sympy Symbol. Remove any brackets from the name in case e is
        # a component
        n, c = Symbol._symComp(e)
        if len(c) == 0:
            return PrettyPrinter._print_Symbol(self, e)
        s = sympy.Symbol(n + '_'.join([str(i) for i in c]))
        return PrettyPrinter._print_Symbol(self, s)
Beispiel #5
0
def test_printing3():
    check(PrettyPrinter())
Beispiel #6
0
 def __init__(self, **kwargs):
     DocumentWriter.__init__(self)
     self.pp = PrettyPrinter(settings={'wrap_line': False})
Beispiel #7
0
class TextDocumentWriter(DocumentWriter):
    """ 
    Documents the network by printing to stdout, uses `sympy` for formatting
    the equations (including nice Unicode symbols)
    """
    def __init__(self, **kwargs):
        DocumentWriter.__init__(self, **kwargs)
        self.pp = PrettyPrinter(settings={'wrap_line': False})

    def document_sim(self, network):
        clock = guess_clock(network.clock)
        print 'Simulating with dt = ' + str(clock.dt)

    def document_connections(self, connections):
        print 'Connections and SpikeMonitors: '
        for con in connections:
            if con.target:
                print '\t%s (%s -> %s)' % (con, self.short_labels[con.source],
                                           self.short_labels[con.target])
        # Monitors are connections without a target
        for con in connections:
            if con.target is None:
                print '\t%s (%s, monitoring %s)' % (
                    con, self.short_labels[con], self.short_labels[con.source])

    def document_groups(self, groups):
        if not groups:
            return
        print 'Groups: '
        DocumentWriter.document_groups(self, groups)

    def document_group(self, group):
        print '\t%s (%s)' % (self.long_labels[group], self.short_labels[group])

        sympy_time = Symbol('t')

        try:
            eqs = group._eqs
            print '\t\tEquations: '

            equations = ''
            for varname in eqs._diffeq_names:
                sympy_var = DocumentWriter.to_sympy_expression(varname)
                eq_string = eqs._string[varname]
                sympy_string = self.pp.doprint(
                    Eq(Derivative(sympy_var, sympy_time),
                       DocumentWriter.to_sympy_expression(eq_string)))
                for line in sympy_string.split('\n'):
                    equations += '\t\t\t' + line + '\n'
                equations += '\n'

            for varname in eqs._eq_names:
                sympy_var = DocumentWriter.to_sympy_expression(varname)
                eq_string = eqs._string[varname]
                sympy_string = self.pp.doprint(
                    Eq(sympy_var,
                       DocumentWriter.to_sympy_expression(eq_string)))
                for line in sympy_string.split('\n'):
                    equations += '\t\t\t' + line + '\n'
                equations += '\n'

            print equations
        except AttributeError:
            pass

        if group._subgroup_set:
            print '\t\tSubgroups:'
            for subgroup_ref in group._subgroup_set:
                subgroup = subgroup_ref()
                print '\t\t\t%s (%s)' % (self.long_labels[subgroup],
                                         self.short_labels[subgroup])

    def document_operations(self, operations):
        if not operations:
            return
        print 'NetworkOperations and StateMonitors:'
        for op in operations:
            if isinstance(op, StateMonitor):
                print '\t' + str(
                    op) + ' (monitoring: %s)' % self.short_labels[op.P]
            else:
                print '\t' + str(op)
Beispiel #8
0
 def __init__(self, **kwargs):
     DocumentWriter.__init__(self, **kwargs)
     self.pp = PrettyPrinter(settings={'wrap_line': False})
Beispiel #9
0
class TextDocumentWriter(DocumentWriter):
    """ 
    Documents the network by printing to stdout, uses `sympy` for formatting
    the equations (including nice Unicode symbols)
    """
    def __init__(self, **kwargs):
        DocumentWriter.__init__(self, **kwargs)
        self.pp = PrettyPrinter(settings={'wrap_line': False})
    
    def document_sim(self, network): 
        clock = guess_clock(network.clock)
        print 'Simulating with dt = ' + str(clock.dt)
    
    def document_connections(self, connections):
        print 'Connections and SpikeMonitors: '
        for con in connections:
            if con.target:
                print '\t%s (%s -> %s)' % (con, self.short_labels[con.source],
                                           self.short_labels[con.target])
        # Monitors are connections without a target
        for con in connections:
            if con.target is None:
                print '\t%s (%s, monitoring %s)' %  (con,
                                                     self.short_labels[con],
                                                     self.short_labels[con.source])

    def document_groups(self, groups):
        if not groups:
            return
        print 'Groups: '
        DocumentWriter.document_groups(self, groups)
                    
    def document_group(self, group):        
        print '\t%s (%s)' % (self.long_labels[group], self.short_labels[group]) 
        
        sympy_time = Symbol('t')
        
        try:
            eqs = group._eqs
            print '\t\tEquations: '
            
            equations = ''
            for varname in eqs._diffeq_names:
                sympy_var = DocumentWriter.to_sympy_expression(varname)
                eq_string = eqs._string[varname]                
                sympy_string = self.pp.doprint(Eq(Derivative(sympy_var, sympy_time),
                                                  DocumentWriter.to_sympy_expression(eq_string)))
                for line in sympy_string.split('\n'):                                        
                    equations +=  '\t\t\t' + line + '\n'
                equations += '\n'
        
            for varname in eqs._eq_names:
                sympy_var = DocumentWriter.to_sympy_expression(varname)
                eq_string = eqs._string[varname]
                sympy_string = self.pp.doprint(Eq(sympy_var,
                                                  DocumentWriter.to_sympy_expression(eq_string)))                                    
                for line in sympy_string.split('\n'):                                        
                    equations +=  '\t\t\t' + line + '\n'
                equations += '\n'
            
            print equations
        except AttributeError:
            pass
        
        if group._subgroup_set:
            print '\t\tSubgroups:'
            for subgroup_ref in group._subgroup_set:
                subgroup = subgroup_ref()
                print '\t\t\t%s (%s)' % (self.long_labels[subgroup],
                                         self.short_labels[subgroup]) 

    def document_operations(self, operations):
        if not operations:
            return
        print 'NetworkOperations and StateMonitors:'
        for op in operations:
            if isinstance(op, StateMonitor):
                print '\t' + str(op) + ' (monitoring: %s)' % self.short_labels[op.P]
            else:
                print '\t' + str(op)