Skip to content

Commit

Permalink
refactored for current millenium
Browse files Browse the repository at this point in the history
  • Loading branch information
bgoli committed Aug 24, 2020
1 parent c005e26 commit 2344f52
Show file tree
Hide file tree
Showing 6 changed files with 190 additions and 107 deletions.
1 change: 0 additions & 1 deletion pysces/PyscesModel.py
Original file line number Diff line number Diff line change
Expand Up @@ -2108,7 +2108,6 @@ def Stoichiometry_Load_Serial(self):
stc = self.SerialDecode(self.ModelFile[:-4] + '_stoichiometry')
return stc

# new powerslave method - brett 20050825
def Stoichiometry_Analyse(self, override=0, load=0):
"""
Stoichiometry_Analyse(override=0,load=0)
Expand Down
2 changes: 1 addition & 1 deletion pysces/PyscesParScan.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ def genScanSpace(self):
spr = self.scans_per_run
Tsteps = 1
for gen in self.GenOrder:
if self.GenDict[gen][4] == False: # don't increase Tsteps for slaves
if self.GenDict[gen][4] == False: # don't increase Tsteps for followers
Tsteps *= self.GenDict[gen][2]
for step in range(Tsteps):
pars = self.__nextValue__()
Expand Down
28 changes: 15 additions & 13 deletions pysces/PyscesScan.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ def addUserOutput(self, *kw):
print('MaxMode', MaxMode)
self.UserOutputList = output

def addScanParameter(self, name, start, end, points, log=False, slave=False):
def addScanParameter(self, name, start, end, points, log=False, follower=False):
"""
Add a parameter to scan (an axis if you like) input is:
Expand All @@ -127,9 +127,9 @@ def addScanParameter(self, name, start, end, points, log=False, slave=False):
- float(end) = upper bound of scan
- int(points) = number of points in scan range
- bool(log) = Use a logarithmic (base10) range
- bool(slave) = Scan parameters can be masters i.e. an independent axis or a "slave" which moves synchronously with the previously defined parameter range.
- bool(follower) = Scan parameters can be leaders i.e. an independent axis or a "follower" which moves synchronously with the previously defined parameter range.
The first ScanParameter cannot be a slave.
The first ScanParameter cannot be a follower.
"""
offset = 1
assert self.testInputParameter(name), (
Expand All @@ -140,22 +140,24 @@ def addScanParameter(self, name, start, end, points, log=False, slave=False):
), '\nSCANNER: This operation is currently not allowed\n'
if not len(self.GenOrder) == 0:
for el in self.GenOrder:
if self.GenDict[el][4] == False: # test if not slave
if self.GenDict[el][4] == False: # test if not follower
offset = offset * self.GenDict[el][2] # increment offset
if slave == True:
prevpar = self.GenOrder[-1] # previous parameter, i.e. master
offset = self.GenDict[prevpar][5] # don't increment for slave
if follower == True:
prevpar = self.GenOrder[-1] # previous parameter, i.e. leader
offset = self.GenDict[prevpar][5] # don't increment for follower
if points != self.GenDict[prevpar][2]:
print(
'SCANNER: Slave parameter needs to iterate over same number of\npoints as master...resetting points.'
'SCANNER: Follower parameter needs to iterate over same number of\npoints as leader...resetting points.'
)
points = self.GenDict[prevpar][2]
else:
if slave == True:
slave = False
print('SCANNER: Inner range cannot be a slave ... resetting to master')
if follower == True:
follower = False
print(
'SCANNER: Inner range cannot be a follower ... resetting to leader'
)
self.GenDict.setdefault(
name, (start, end, points, log, slave, offset, getattr(self.mod, name))
name, (start, end, points, log, follower, offset, getattr(self.mod, name))
)
setattr(self, name + '_test', self.stepGen(offset))
setattr(self, name, self.rangeGen(name, start, end, points, log))
Expand Down Expand Up @@ -269,7 +271,7 @@ def Run(self, ReRun=False):
# self.mod.mode_state_nan_on_fail = True
Tsteps = 1
for gen in self.GenOrder:
if self.GenDict[gen][4] == False: # don't increase Tsteps for slaves
if self.GenDict[gen][4] == False: # don't increase Tsteps for follower
Tsteps *= self.GenDict[gen][2]
print(next(self.scanT.RUN))
analysis_counter = 0
Expand Down
25 changes: 13 additions & 12 deletions pysces/examples/testRunScatter.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,30 @@
# Testing the new parallel scanner class

import os

backupdir = os.getcwd()

import numpy as np
import pysces

tbox=pysces.PyscesUtils.TimerBox()
tbox = pysces.PyscesUtils.TimerBox()
import time

m=pysces.model('isola2a')
m = pysces.model('isola2a')

print("\n\nParallel execution...using RunScatter")
par2 = pysces.ParScanner(m)
t5=time.time()
par2.addScanParameter('V4',60,100,11)
par2.addScanParameter('V1',100,130,16)
par2.addScanParameter('V2',100,130,16,slave=True)
par2.addScanParameter('V3',80,90,6)
t5 = time.time()
par2.addScanParameter('V4', 60, 100, 11)
par2.addScanParameter('V1', 100, 130, 16)
par2.addScanParameter('V2', 100, 130, 16, follower=True)
par2.addScanParameter('V3', 80, 90, 6)
par2.addUserOutput('J_R1', 'A', 'ecR4_X', 'ccJR1_R1')
#par2.addUserOutput('J_R1', 'A')
# par2.addUserOutput('J_R1', 'A')
par2.RunScatter()
t6=time.time()
print("Duration: %.2f seconds" % (t6-t5))
par2.statespersecond = par2.Tsteps/(t6-t5)
t6 = time.time()
print("Duration: %.2f seconds" % (t6 - t5))
par2.statespersecond = par2.Tsteps / (t6 - t5)
print("States per second: %.1f" % par2.statespersecond)

os.chdir(backupdir)
os.chdir(backupdir)
86 changes: 45 additions & 41 deletions pysces/examples/testparscanner.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,76 +2,80 @@
# Testing the new parallel scanner class

import os

backupdir = os.getcwd()

import numpy as np
import pysces

tbox=pysces.PyscesUtils.TimerBox()
tbox = pysces.PyscesUtils.TimerBox()
import time

m=pysces.model('isola2a')
m = pysces.model('isola2a')

ser = pysces.Scanner(m)

print("Serial execution...")
print("Start: ", tbox.normal_timer('SER'))
print(next(tbox.SER))
t1=time.time()
t1 = time.time()
ser.quietRun = True
ser.addScanParameter('V4',60,100,11)
ser.addScanParameter('V1',100,160,16)
ser.addScanParameter('V2',100,130,16,slave=True)
ser.addScanParameter('V3',80,90,6)
ser.addUserOutput('J_R1', 'A', 'ecR4_X','ccJR1_R1')
#ser.addUserOutput('J_R1', 'A')
ser.addScanParameter('V4', 60, 100, 11)
ser.addScanParameter('V1', 100, 160, 16)
ser.addScanParameter('V2', 100, 130, 16, follower=True)
ser.addScanParameter('V3', 80, 90, 6)
ser.addUserOutput('J_R1', 'A', 'ecR4_X', 'ccJR1_R1')
# ser.addUserOutput('J_R1', 'A')
ser.Run()
print("Done: ", next(tbox.SER))
t2=time.time()
print("Duration: %.2f seconds" % (t2-t1))
ser.statespersecond = len(ser.ScanSpace)/(t2-t1)
t2 = time.time()
print("Duration: %.2f seconds" % (t2 - t1))
ser.statespersecond = len(ser.ScanSpace) / (t2 - t1)
print("States per second: %.1f" % ser.statespersecond)

print("\n\nParallel execution...scans per run =", 100)
par = pysces.ParScanner(m)
par.scans_per_run = 100
t3=time.time()
par.addScanParameter('V4',60,100,11)
par.addScanParameter('V1',100,160,16)
par.addScanParameter('V2',100,130,16,slave=True)
par.addScanParameter('V3',80,90,6)
t3 = time.time()
par.addScanParameter('V4', 60, 100, 11)
par.addScanParameter('V1', 100, 160, 16)
par.addScanParameter('V2', 100, 130, 16, follower=True)
par.addScanParameter('V3', 80, 90, 6)
par.addUserOutput('J_R1', 'A', 'ecR4_X', 'ccJR1_R1')
#par.addUserOutput('J_R1', 'A')
# par.addUserOutput('J_R1', 'A')
par.Run()
t4=time.time()
print("Duration: %.2f seconds" % (t4-t3))
par.statespersecond = par.Tsteps/(t4-t3)
t4 = time.time()
print("Duration: %.2f seconds" % (t4 - t3))
par.statespersecond = par.Tsteps / (t4 - t3)
print("States per second: %.1f" % par.statespersecond)

print("\n Speedup with load balanced TaskClient: %.2f" % (par.statespersecond/ser.statespersecond))
print(
"\n Speedup with load balanced TaskClient: %.2f"
% (par.statespersecond / ser.statespersecond)
)

print("\n\nParallel execution...using RunScatter")
par2 = pysces.ParScanner(m)
t5=time.time()
par2.addScanParameter('V4',60,100,11)
par2.addScanParameter('V1',100,160,16)
par2.addScanParameter('V2',100,130,16,slave=True)
par2.addScanParameter('V3',80,90,6)
t5 = time.time()
par2.addScanParameter('V4', 60, 100, 11)
par2.addScanParameter('V1', 100, 160, 16)
par2.addScanParameter('V2', 100, 130, 16, follower=True)
par2.addScanParameter('V3', 80, 90, 6)
par2.addUserOutput('J_R1', 'A', 'ecR4_X', 'ccJR1_R1')
#par2.addUserOutput('J_R1', 'A')
# par2.addUserOutput('J_R1', 'A')
par2.RunScatter()
t6=time.time()
print("Duration: %.2f seconds" % (t6-t5))
par2.statespersecond = par2.Tsteps/(t6-t5)
t6 = time.time()
print("Duration: %.2f seconds" % (t6 - t5))
par2.statespersecond = par2.Tsteps / (t6 - t5)
print("States per second: %.1f" % par2.statespersecond)

print("\n Speedup with RunScatter: %.2f" % (par2.statespersecond/ser.statespersecond))
print("\n Speedup with RunScatter: %.2f" % (par2.statespersecond / ser.statespersecond))

print("\n===========\nComparing results...")
#comp = np.equal(ser.SteadyStateResults, par.SteadyStateResults[::5])
#print np.alltrue(comp)
#comp2 = np.equal(ser.UserOutputResults, par.UserOutputResults[::5])
#print np.alltrue(comp)
# comp = np.equal(ser.SteadyStateResults, par.SteadyStateResults[::5])
# print np.alltrue(comp)
# comp2 = np.equal(ser.UserOutputResults, par.UserOutputResults[::5])
# print np.alltrue(comp)

sss = ser.SteadyStateResults
pss = par.SteadyStateResults
Expand All @@ -80,10 +84,10 @@
p2ss = par2.SteadyStateResults
p2uo = par2.UserOutputResults

print("serial vs. parallel s/s results : ", np.alltrue(np.equal(sss,pss)))
print("serial vs. parallel user output : ", np.alltrue(np.equal(suo,puo)))
print("TaskClient vs RunScatter s/s results: ", np.alltrue(np.equal(pss,p2ss)))
print("TaskClient vs RunScatter user output: ", np.alltrue(np.equal(puo,p2uo)))
print("serial vs. parallel s/s results : ", np.alltrue(np.equal(sss, pss)))
print("serial vs. parallel user output : ", np.alltrue(np.equal(suo, puo)))
print("TaskClient vs RunScatter s/s results: ", np.alltrue(np.equal(pss, p2ss)))
print("TaskClient vs RunScatter user output: ", np.alltrue(np.equal(puo, p2uo)))


os.chdir(backupdir)
os.chdir(backupdir)
Loading

0 comments on commit 2344f52

Please sign in to comment.