Exemple #1
0
 def view_activate(self, widget, *args):
     filename = ''
     if self.modulename:
         x = ascpy.Library()
         # TODO is this the fastest way??
         for module in x.getModules():
             if module.getName() == self.modulename:
                 fn = module.getFilename()
                 break
         # FIXME what if module not found??
         ViewModel(filename=fn, title="Module '%s'" % (self.modulename))
     elif self.modelname:
         x = ascpy.Library()
         for module in x.getModules():
             for model in x.getModuleTypes(module):
                 if str(model) == self.modelname:
                     filename = module.getFilename()
         if not filename:
             return
         displaytext = []
         typelist = ['MODEL', 'DEFINITION', 'ATOM']
         proceed = False
         flagvariable = False
         module = open(filename, "r")
         if module:
             lines = module.readlines()
             for line in lines:
                 words = line.split()
                 for i in range(len(words)):
                     if words[i] in typelist:
                         if i != len(words) - 1:
                             if words[i + 1].split(
                                     ';')[0] == self.modelname or words[
                                         i +
                                         1].split('(')[0] == self.modelname:
                                 proceed = True
                     elif words[i] == 'END':
                         if words[i + 1].split(
                                 ';')[0] == self.modelname or words[
                                     i + 1].split('(')[0] == self.modelname:
                             flagvariable = True
                             if proceed == True:
                                 displaytext.append(line)
                                 proceed = False
                             break
                     if proceed == True:
                         displaytext.append(line)
                         break
                 if flagvariable == True:
                     break
             ViewModel(text=''.join(displaytext),
                       title="Model '%s'" % (self.modelname))
Exemple #2
0
    def load_library(self, lib_name=None):
        if lib_name == None:
            return

        lib_path = os.path.join('test', 'canvas', lib_name)
        try:
            self.library.clear()
            self.library.load(lib_path)
        except Exception as e:
            self.library = ascpy.Library()
            self.library.load(lib_path)

        self.annodb = self.library.getAnnotationDatabase()
        self.modules = self.library.getModules()

        try:
            self.blocktypes = set()
            self.streamtypes = set()
            for m in self.modules:
                self.types = self.library.getModuleTypes(m)
                for t in self.types:
                    #if t.hasParameters():
                    #	continue
                    self.parse_types(t)
                    self.parse_streams(t)
        except Exception as e:
            print 'Error: ASCEND Blocks Could not be loaded \n', e
            exit()

        try:
            del self.canvas_blocks[:]
            for t in self.blocktypes:
                b = BlockType(t, self.annodb)
                self.canvas_blocks += [b]
        except Exception as e:
            print 'Error: Could not load blocktypes \n', e
            exit()
        try:
            for stream in self.streamtypes:
                s = BlockStream(stream, self.annodb)
                self.streams += [s]

        except Exception as e:
            print 'Error: Could not load streams \n', e
            exit()
        '''
Exemple #3
0
 def run(self):
     ascendlock.acquire()
     L = ascpy.Library()
     L.clear()
     L.load(self.filepath)
     for M in L.getModules():
         print "Looking at module '" + M.getName() + "'"
         for t in L.getModuleTypes(M):
             #print "Looking at type '"+str(t.getName())+"'"
             for m in t.getMethods():
                 #print "Looking at method '"+str(m.getName())+"'"
                 if m.getName() == TEST_METHOD_NAME:
                     jobslock.acquire()
                     heapq.heappush(
                         jobs, (0,
                                AscendTestModel(self.filepath,
                                                t.getName().toString())))
                     jobslock.release()
     ascendlock.release()
Exemple #4
0
    def run(self):
        ascendlock.acquire()
        try:
            L = ascpy.Library()
            L.clear()
            L.load(self.filepath)
            t = L.findType(self.modelname)
            testmethod = None
            for m in t.getMethods():
                if m.getName() == TEST_METHOD_NAME:
                    testmethod = m
            if not testmethod:
                raise RuntimeError("No method '" + TEST_METHOD_NAME +
                                   "' found")

            s = t.getSimulation('testsim')
            #s.check()
            s.build()
            print "LAUNCHING SOLVER...\n\n"
            r = ascpy.SolverReporter()
            s.solve(ascpy.Solver('QRSlv'), r)
            s.run(testmethod)
        except RuntimeError, e:
            print e
import os, os.path, re
import threading, heapq
import time, platform

import sys, dl
# This sets the flags for dlopen used by python so that the symbols in the
# ascend library are made available to libraries dlopened within ASCEND:
sys.setdlopenflags(dl.RTLD_GLOBAL|dl.RTLD_NOW)
import ascpy

if os.getenv('ASCENDLIBRARY')==None:
	path = '~/src/ascend/trunk/models'
	print "Setting ASCEND path to",path
	os.putenv('ASCENDLIBRARY',path)

L = ascpy.Library();
L.load(filepath);
for M in L.getModules():
	print "Looking at module '"+M.getName()+"'"
	for t in L.getModuleTypes(M):
		#print "Looking at type '"+str(t.getName())+"'"
		for m in t.getMethods():
			print "Looking at method '"+str(m.getName())+"'"
			if m.getName()==TEST_METHOD_NAME:
				jobslock.acquire()
				heapq.heappush(jobs, (0, AscendTestModel( self.filepath,M.getName())) )
				jobslock.release()
del(L)
ascendlock.release()		

Exemple #6
0
import ascpy
import TReport

import matplotlib as mpl
from mpl_toolkits.mplot3d import Axes3D
import numpy as np
import matplotlib.pyplot as plt

## CODE BEGINS

lib = ascpy.Library()
lib.load('test/ida/leon/electron.a4c')

M = lib.findType('electron').getSimulation('sim')
M.setSolver(ascpy.Solver('QRSlv'))

P = M.getParameters()

I = ascpy.Integrator(M)

I.setEngine('IDA')
I.setLinearTimesteps(ascpy.Units("s"), 0.0, 40.0, 60)
I.setMinSubStep(0.0001)
I.setMaxSubStep(0.1)
I.setInitialSubStep(0.001)
I.setMaxSubSteps(200)

I.setParameter('autodiff', False)
I.analyse()
reporter = TReport.TestReporter(I)
I.setReporter(reporter)
Exemple #7
0
	def setUp(self):
		import ascpy
		self.L = ascpy.Library()
def solvernotes(self):
	""" use the NOTES DB to set parameters applicable to the current active solver """
	print "SETUP_SOLVER..."
	sim = ascpy.Registry().getSimulation('sim')

	browser = extpy.getbrowser()
	if browser:
		reporter = browser.reporter
	else:
		print "Using console solver reporter"
		reporter = ascpy.getReporter()

	if browser:
		print "Using browser.solver"
		solver = browser.solver
	else:
		print "Using hardwired default solver, QRSlv"
		solver = ascpy.Solver("QRSlv")
	

	db = ascpy.Library().getAnnotationDatabase()

	print "GOT SIM..."
	
	if not sim:
		reporter.reportError("No simulation present yet")
		return

	if not solver:
		reporter.reportError("No solver yet")
		return

	# the simulation needs to be built at this point, else solver could not
	# be selected, and hence solver params could not be assigned.
	sim.build()
	
	# use the solver selected in the browser
	sim.setSolver(solver)

	solvername = solver.getName()
	reporter.reportNote("Active solver is '%s'" % solvername)

	notes = db.getNotes(self.getType(),ascpy.SymChar(solvername))

	print "GETTING SOLVER PARAMS..."

	params = sim.getParameters()

	print "DONE SOLVER PARAMS"

	print params

	paramnames = [p.getName() for p in params]

	print "DONE PARAMS"

	for i in range(0,len(notes)):
		note = notes[i]

		if note.getId()==None:
			browser.reporter.reportNote("Empty note ID...")
			continue
		n = note.getId()
		param = None
		for p in params:
			if p.getName()==n: 
				param = p
		if param:
			if param.isInt():
				v = int( note.getText() )
				param.setIntValue(v)
			elif param.isReal():
				v = float( note.getText() )
				param.setRealValue(v)
			elif param.isStr():
				v = note.getText()
				param.setStrValue(v)
			elif param.isBool():
				v = bool( note.getText() )
				param.setBoolValue(v)
			else:
				raise Exception("unknown parameter type")
			reporter.reportNote("Set %s = %s" % (param.getName(),v))
		else:
			reporter.reportWarning("Ignoring unrecognised parameter '%s' for solver '%s' (from solver notes)\n%s:%d" % (n,solvername,note.getFilename(),note.getLineNumber()))