reliability: switch to NumPy, since Numeric is deprecated

This commit is contained in:
Brian Warner 2009-02-19 01:44:35 -07:00
parent 589a757e25
commit 268cd538e2
6 changed files with 18 additions and 29 deletions

View File

@ -2,23 +2,12 @@
import math
from allmydata.util import statistics
import Numeric
from Numeric import array, matrixmultiply as mm
from numpy import array
DAY=24*60*60
MONTH=31*DAY
YEAR=365*DAY
def my_dot(v1, v2):
#print v1.shape, v2.shape
#assert len(v1.shape) == 2
#assert v1.shape[0] == 1
#assert len(v2.shape) == 2
#assert v2.shape[0] == 1
#assert v1.shape[1] == v2.shape[1]
#for i in range(v1.shape[1]):
return Numeric.sum(Numeric.sum(v1*v2))
class ReliabilityModel:
"""Generate a model of system-wide reliability, given several input
parameters.
@ -85,9 +74,9 @@ class ReliabilityModel:
#print "DECAY:", decay
#print "OLD-POST-REPAIR:", old_post_repair
#print "NEW-POST-REPAIR:", mm(decay, repair)
#print "NEW-POST-REPAIR:", decay * repair
#print "REPAIR:", repair
#print "DIFF:", (old_post_repair - mm(decay, repair))
#print "DIFF:", (old_post_repair - decay * repair)
START = array([[0]*N + [1]])
ALIVE = array([[0]*k + [1]*(1+N-k)])
@ -112,24 +101,24 @@ class ReliabilityModel:
report = ReliabilityReport()
for t in range(0, report_span+delta, delta):
unmaintained_state = mm(unmaintained_state, decay)
maintained_state = mm(maintained_state, decay)
unmaintained_state = unmaintained_state * decay
maintained_state = maintained_state * decay
if (t-last_check) > check_period:
last_check = t
# we do a check-and-repair this frequently
need_repair = my_dot(maintained_state, REPAIRp)
need_repair = (maintained_state * REPAIRp).sum()
P_repaired_last_check_period = need_repair
new_shares = my_dot(maintained_state, REPAIR_newshares)
new_shares = (maintained_state * REPAIR_newshares).sum()
needed_repairs.append(need_repair)
needed_new_shares.append(new_shares)
maintained_state = mm(maintained_state, repair)
maintained_state = maintained_state * repair
if (t-last_report) > report_period:
last_report = t
P_dead_unmaintained = my_dot(unmaintained_state, DEAD)
P_dead_maintained = my_dot(maintained_state, DEAD)
P_dead_unmaintained = (unmaintained_state * DEAD).sum()
P_dead_maintained = (maintained_state * DEAD).sum()
cumulative_number_of_repairs = sum(needed_repairs)
cumulative_number_of_new_shares = sum(needed_new_shares)
report.add_sample(t, unmaintained_state, maintained_state,
@ -139,8 +128,8 @@ class ReliabilityModel:
P_dead_unmaintained, P_dead_maintained)
# record one more sample at the end of the run
P_dead_unmaintained = my_dot(unmaintained_state, DEAD)
P_dead_maintained = my_dot(maintained_state, DEAD)
P_dead_unmaintained = (unmaintained_state * DEAD).sum()
P_dead_maintained = (maintained_state * DEAD).sum()
cumulative_number_of_repairs = sum(needed_repairs)
cumulative_number_of_new_shares = sum(needed_new_shares)
report.add_sample(t, unmaintained_state, maintained_state,

View File

@ -5,7 +5,7 @@ ReliabilityModel = None
try:
from allmydata.reliability import ReliabilityModel
except ImportError:
pass # might not be importable, since it needs Numeric
pass # might not be importable, since it needs NumPy
from nevow import inevow
from zope.interface import implements
@ -70,7 +70,7 @@ YEAR=365*DAY
class Reliability(unittest.TestCase):
def test_basic(self):
if ReliabilityModel is None:
raise unittest.SkipTest("reliability model requires Numeric")
raise unittest.SkipTest("reliability model requires NumPy")
r = ReliabilityModel.run(delta=100000,
report_period=3*MONTH,
report_span=5*YEAR)

View File

@ -476,7 +476,7 @@ class Web(WebMixin, testutil.StallMixin, unittest.TestCase):
from allmydata import reliability
_hush_pyflakes = reliability
except:
raise unittest.SkipTest("reliability tool requires Numeric")
raise unittest.SkipTest("reliability tool requires NumPy")
d = self.GET("/reliability/")
def _check(res):

View File

@ -2,7 +2,7 @@
from nevow import rend, inevow, tags as T
reliability = None # might not be usable
try:
from allmydata import reliability # requires Numeric and PIL
from allmydata import reliability # requires NumPy
except ImportError:
pass
from allmydata.web.common import getxmlfile, get_arg

View File

@ -122,7 +122,7 @@ class NoReliability(rend.Page):
</head>
<body>
<h2>"Reliability" page not available</h2>
<p>Please install the python "Numeric" module to enable this page.</p>
<p>Please install the python "NumPy" module to enable this page.</p>
</body>
</html>
''')

View File

@ -10,7 +10,7 @@ from twisted.plugin import IPlugin
# note that this .py file is *not* in a package: there is no __init__.py in
# our parent directory. This is important, because otherwise ours would fight
# with Twisted's. When trial looks for plugins, it merely executes all the
# *.py files it finds in and twisted/plugins/ subdirectories of anything on
# *.py files it finds in any twisted/plugins/ subdirectories of anything on
# sys.path . The namespace that results from executing these .py files is
# examined for instances which provide both IPlugin and the target interface
# (in this case, trial is looking for IReporter instances). Each such