Skip to content

Commit

Permalink
[EXPR-2]cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
sudheerad9 committed Jul 24, 2021
1 parent 618f8b7 commit 5fd198d
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 76 deletions.
16 changes: 1 addition & 15 deletions SirIsaac/fittingProblem.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

# 9.9.2015 directory needed for direct calling using MPI?
import os
from scipy.special import logsumexp

SIRISAACDIR = os.path.abspath(os.path.dirname(__file__))

Expand Down Expand Up @@ -174,7 +173,6 @@ def fitAll(self,usePreviousParams=True,fitPerfectModel=False,resume=True,
to the number of fittingModels in
self.fittingModelNames.
"""
print("verboseeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee", self.verbose)
oldFitParameters = []
oldCost = scipy.inf

Expand All @@ -187,7 +185,6 @@ def fitAll(self,usePreviousParams=True,fitPerfectModel=False,resume=True,

for name in self.fittingModelNames:
fittingModel = self.fittingModelDict[name]
print("fittingModel",fittingModel)
# 4.18.2012
if self.costDict.has_key(name) and resume:
# We've already fit this one.
Expand All @@ -202,7 +199,6 @@ def fitAll(self,usePreviousParams=True,fitPerfectModel=False,resume=True,

if usePreviousParams:
fittingModel.initializeParameters(oldFitParameters)
print("oldfitpramsssssssssss",oldFitParameters)
# 4.17.2012
if self.smallerBestParamsDict.has_key(name):
smallerBestParams = self.smallerBestParamsDict[name]
Expand All @@ -214,13 +210,10 @@ def fitAll(self,usePreviousParams=True,fitPerfectModel=False,resume=True,
# 9.20.2012 XXX Should we never include priors for cost?
if fittingDataDerivs is not None: includePriors = False
else: includePriors = True
print("include priors",includePriors)
newFitParameters = \
fittingModel.fitToData(self.fittingData,self.indepParamsList, \
otherStartingPoint=smallerBestParams, \
fittingDataDerivs=fittingDataDerivs,**kwargs)
print("fffffffffffffffffffffffffffffffffffff")
print(newFitParameters)

if not hasattr(self,'fittingDataDerivs'):
self.fittingDataDerivs = None
Expand All @@ -235,9 +228,6 @@ def fitAll(self,usePreviousParams=True,fitPerfectModel=False,resume=True,
# (Note: This assumes that the default values for the new
# parameters make the new (more complex) model behave the
# same as the old one before they are changed.)
print("new_osssssssssssssssss")
print(newCost)
print(oldCost)
if newCost > oldCost:
fittingModel.initializeParameters(oldFitParameters)
newFitParameters = \
Expand Down Expand Up @@ -275,11 +265,7 @@ def fitAll(self,usePreviousParams=True,fitPerfectModel=False,resume=True,
fittingModel.initializeParameters(newFitParameters)
oldCost = newCost
oldFitParameters = newFitParameters
print("old cose llllllllllllllllllllllllllllllllll",oldCost)
print("old fit parameters",oldFitParameters)
self._UpdateDicts(name,includePriors=includePriors)
print("diiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiccccccccccccccccccccccccccccccccccccccctttttttttttttttt")
print(self.logLikelihoodDict)
# 5.6.2013 update old files if needed
if not hasattr(self,'logLikelihoodDict'):
self._UpdateDicts(name)
Expand Down Expand Up @@ -1817,7 +1803,7 @@ def localFitToData_parallel(self,numprocs,fittingData,dataModel,

# call mpi
stdoutFile = open(prefix+"stdout.txt",'w')
subprocess.call([ "mpirun", "-np",str(numprocs),"--allow-run-as-root","python",
subprocess.call([ "mpirun", "-np",str(numprocs),"python",
os.path.join(SIRISAACDIR, "localFitParallel.py"),
inputDictFilename],
stderr=stdoutFile,stdout=stdoutFile,env=os.environ)
Expand Down
5 changes: 0 additions & 5 deletions SirIsaac/localFitParallel.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@

### Master Process ###
if MPI_myID == MASTER_PROCESS:
print("kkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk")
from simplePickle import save

num_processors = comm.Get_size()
Expand All @@ -72,8 +71,6 @@

# list of startParams indices to pass to the workers
work_array = range(len(startParamsList))
print("work arrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr")
print(work_array)
work_size = len(work_array)

# Dispatch jobs to worker processes
Expand Down Expand Up @@ -121,8 +118,6 @@
comm.send(DIE_INDEX, dest=proc)

# Write data to file
print("in localfittttttttttttttttt")
# print(allOutputsDict)
save(allOutputsDict,outputFilename)

else:
Expand Down
1 change: 0 additions & 1 deletion SirIsaac/mpi_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
# Run like so:
# mpirun -np 3 python mpi_test.py test_input_filename
#
# RUN apt-get update & apt-get install python2-dev build-essential libssl-dev libffi-dev libxml2-dev libxslt1-dev zlib1g-dev

import sys
from simplePickle import load,save
Expand Down
59 changes: 4 additions & 55 deletions test/test_fitting_problem.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,15 @@
#
# Tests for fittingProblem.py
#
'''

import unittest

from SirIsaac.fittingProblem import *
import SloppyCell.ReactionNetworks as scrn

def mock_net():
"""
from SirIsaac import fittingProblem
import SirIsaac
Create a simple mock SloppyCell Network object
Create a simple mock SloppyCell Network object
"""
return scrn.Network('mocknet')

Expand Down Expand Up @@ -51,52 +48,4 @@ def test_fitting_problem_init(self):
indepParamsList=indepParamsList)

self.assertEqual(None, ftest.getBestModel())
'''
import scipy, pylab
from SirIsaac import fittingProblem


def test_x(self):
data = scipy.loadtxt('simpleExample_data.txt')
indepParamsList = [ [ expt[0] ] for expt in data ]
indepParamsList[:3]
sirIsaacData = []
for expt in data:
sirIsaacData.append( { 'x': { expt[1]: ( expt[2], expt[3] ) } } )
sirIsaacData[:3]
outputNames = ['x']
indepParamNames = ['x_init']
complexityStepsize = 2 # increase complexity with steps of size 2
complexityMax = 25 # don't try models with complexity > 25
complexityList = range(0,complexityMax,complexityStepsize)

# ensGen controls the generation of the initial ensemble of
# parameter starting points.
totalSteps = 1e3
keepSteps = 10
seeds = (1,1) # use a fixed random seed
ensTemperature = 100.
ensGen = fittingProblem.EnsembleGenerator( totalSteps, keepSteps,
temperature=ensTemperature, seeds=seeds )

# Parameters that control when local fitting stops.
avegtol = 1e-2
maxiter = 100

# priorSigma controls the width of priors on all parameters
priorSigma = 3.

# If you have pypar installed, you can run on multiple processors
numprocs = 6

# We'll only use a subset of our data to make the example run faster
N = 20

p = fittingProblem.PowerLawFittingProblem( complexityList,
sirIsaacData[:N], indepParamsList=indepParamsList[:N],
outputNames=outputNames, indepParamNames=indepParamNames,
ensGen=ensGen, avegtol=avegtol, maxiter=maxiter,
priorSigma=priorSigma, numprocs=numprocs, verbose=True )
p.fitAll()
#
fittingProblem.save(p,'simpleExample_savedFittingProblem.data')
{"mode":"full","isActive":false}

0 comments on commit 5fd198d

Please sign in to comment.