Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

'division_safe' fix applied #8084

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/python/PSetTweaks/WMTweak.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

"""
from __future__ import print_function
from __future__ import division
from past.utils import old_div
import logging
import pickle
import traceback
Expand Down Expand Up @@ -120,7 +122,7 @@ def lfnGroup(job):
default both to 0. The result will be a 5-digit string.
"""
modifier = str(job.get("agentNumber", 0))
lfnGroup = modifier + str(job.get("counter", 0) / 1000).zfill(4)
lfnGroup = modifier + str(old_div(job.get("counter", 0), 1000)).zfill(4)
return lfnGroup


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
3. Couchdb replication status (and status of its database)
4. Disk usage status
"""
from __future__ import division
from past.utils import old_div
__all__ = []

import threading
Expand Down Expand Up @@ -285,7 +287,7 @@ def checkProxyLifetime(self, agInfo):

if proxyWarning:
warnMsg = "Agent proxy '%s' must be renewed ASAP. " % self.proxyFile
warnMsg += "Its time left is: %.2f hours." % (secsLeft / 3600.)
warnMsg += "Its time left is: %.2f hours." % (old_div(secsLeft, 3600.))
agInfo['proxy_warning'] = warnMsg

return
4 changes: 3 additions & 1 deletion src/python/WMComponent/AlertGenerator/Pollers/Agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
of agent's components, etc.

"""
from __future__ import division

# TODO
# Should consider ProcessDetail and Measurement occupying a common
Expand All @@ -12,6 +13,7 @@
# be ensured automatically


from past.utils import old_div
import os
import logging
from xml.etree.ElementTree import ElementTree
Expand Down Expand Up @@ -98,7 +100,7 @@ def _setUp(self):
and Measurements classes.

"""
self.numOfMeasurements = round(self.config.period / self.config.pollInterval, 0)
self.numOfMeasurements = round(old_div(self.config.period, self.config.pollInterval), 0)
# list of pairs (componentPID, componentName)
componentsInfo = self._getComponentsInfo()
for compName, compPID in componentsInfo.items():
Expand Down
4 changes: 3 additions & 1 deletion src/python/WMComponent/AlertGenerator/Pollers/Base.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
within the Alert messaging framework.

"""
from __future__ import division

from past.utils import old_div
import sys
import time
import logging
Expand Down Expand Up @@ -257,7 +259,7 @@ def check(self, pd, measurements):
avgPerc = None
if len(measurements) >= measurements._numOfMeasurements:
# evaluate: calculate average value and react
avgPerc = round((sum(measurements) / len(measurements)), 2)
avgPerc = round((old_div(sum(measurements), len(measurements))), 2)
details = dict(period = self.config.period,
numMeasurements = len(measurements),
average = "%s%%" % avgPerc)
Expand Down
4 changes: 3 additions & 1 deletion src/python/WMComponent/AlertGenerator/Pollers/Couch.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
Module for all CouchDb related polling.

"""
from __future__ import division

from past.utils import old_div
import os
import logging

Expand Down Expand Up @@ -85,7 +87,7 @@ def _setUp(self):
"""
pid = self._getProcessPID()
self._dbProcessDetail = ProcessDetail(pid, "CouchDB")
numOfMeasurements = round(self.config.period / self.config.pollInterval, 0)
numOfMeasurements = round(old_div(self.config.period, self.config.pollInterval), 0)
self._measurements = Measurements(numOfMeasurements)


Expand Down
4 changes: 3 additions & 1 deletion src/python/WMComponent/AlertGenerator/Pollers/MySQL.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
Common module for all MySQL related checked metrics.

"""
from __future__ import division

from past.utils import old_div
import threading
import logging

Expand Down Expand Up @@ -61,7 +63,7 @@ def _setUp(self):
"""
pid = self._getProcessPID()
self._dbProcessDetail = ProcessDetail(pid, "MySQL")
numOfMeasurements = round(self.config.period / self.config.pollInterval, 0)
numOfMeasurements = round(old_div(self.config.period, self.config.pollInterval), 0)
self._measurements = Measurements(numOfMeasurements)


Expand Down
8 changes: 5 additions & 3 deletions src/python/WMComponent/AlertGenerator/Pollers/System.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
utilisation by particular processes, etc.

"""
from __future__ import division

from past.utils import old_div
import logging
import subprocess

Expand Down Expand Up @@ -80,7 +82,7 @@ class CPUPoller(PeriodPoller):
"""
def __init__(self, config, generator):
PeriodPoller.__init__(self, config, generator)
numOfMeasurements = round(self.config.period / self.config.pollInterval, 0)
numOfMeasurements = round(old_div(self.config.period, self.config.pollInterval), 0)
self._measurements = Measurements(numOfMeasurements)


Expand All @@ -107,7 +109,7 @@ class MemoryPoller(PeriodPoller):
"""
def __init__(self, config, generator):
PeriodPoller.__init__(self, config, generator)
numOfMeasurements = round(self.config.period / self.config.pollInterval, 0)
numOfMeasurements = round(old_div(self.config.period, self.config.pollInterval), 0)
self._measurements = Measurements(numOfMeasurements)


Expand Down Expand Up @@ -271,7 +273,7 @@ def sample(self, dir):
(self._myName, ex, out))
logging.error(m)
return None
return round(size / self._prefixBytesFactor, 3)
return round(old_div(size, self._prefixBytesFactor), 3)


def check(self):
Expand Down
4 changes: 3 additions & 1 deletion src/python/WMComponent/JobArchiver/JobArchiverPoller.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
"""
The actual jobArchiver algorithm
"""
from __future__ import division
from past.utils import old_div
__all__ = []

import threading
Expand Down Expand Up @@ -244,7 +246,7 @@ def cleanJobCache(self, job):
workflow = job['workflow']
firstCharacter = workflow[0]
jobFolder = 'JobCluster_%i' \
% (int(job['id'] / self.numberOfJobsToCluster))
% (int(old_div(job['id'], self.numberOfJobsToCluster)))
logDir = os.path.join(self.logDir, firstCharacter,
workflow, jobFolder)
if not os.path.exists(logDir):
Expand Down
4 changes: 3 additions & 1 deletion src/python/WMComponent/JobCreator/CreateWorkArea.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
Class(es) that create the work area for each jobGroup
Used in JobCreator
"""
from __future__ import division

from past.utils import old_div
import os
import os.path
import threading
Expand Down Expand Up @@ -311,7 +313,7 @@ def createJobCollection(self, jobCounter, taskDir):
Create a sub-directory to allow storage of large jobs
"""

value = jobCounter/1000
value = old_div(jobCounter,1000)
jobCollDir = '%s/JobCollection_%i_%i' % (taskDir, self.jobGroup.id, value)
#Set this to a global variable
self.collectionDir = jobCollDir
Expand Down
4 changes: 3 additions & 1 deletion src/python/WMComponent/JobCreator/JobCreatorPoller.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
"""
The JobCreator Poller for the JSM
"""
from __future__ import division
from past.utils import old_div
__all__ = []


Expand Down Expand Up @@ -112,7 +114,7 @@ def capResourceEstimates(jobGroups, nCores, constraints):
j['estimatedDiskUsage'] = min(j['estimatedDiskUsage'], constraints['MaxRequestDiskKB'])
else:
# we assume job efficiency as nCores * 0.8 for multicore
j['estimatedJobTime'] = min(j['estimatedJobTime']/(nCores * 0.8),
j['estimatedJobTime'] = min(old_div(j['estimatedJobTime'],(nCores * 0.8)),
constraints['MaxWallTimeSecs'])
j['estimatedDiskUsage'] = min(j['estimatedDiskUsage'],
constraints['MaxRequestDiskKB'] * nCores)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@
deleted from the site it was originally injected at.

"""
from __future__ import division

from past.utils import old_div
import threading
import logging
import traceback
Expand Down Expand Up @@ -86,7 +88,7 @@ def __init__(self, config):
if getattr(config.PhEDExInjector, "subscribeDatasets", False):
pollInterval = config.PhEDExInjector.pollInterval
subInterval = config.PhEDExInjector.subscribeInterval
self.subFrequency = max(1, int(round(subInterval / pollInterval)))
self.subFrequency = max(1, int(round(old_div(subInterval, pollInterval))))
logging.info("SubscribeDataset and deleteBlocks will run every %d polling cycles", self.subFrequency)
# subscribe on first cycle
self.pollCounter = self.subFrequency - 1
Expand Down
8 changes: 5 additions & 3 deletions src/python/WMComponent/TaskArchiver/CleanCouchPoller.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
"""
Perform cleanup actions
"""
from __future__ import division
from past.utils import old_div
import httplib
import json
import logging
Expand Down Expand Up @@ -716,13 +718,13 @@ def archiveWorkflowSummary(self, spec):
workflowData['histograms'] = jsonHistograms

# No easy way to get the memory footprint of a python object.
summarySize = len(json.dumps(workflowData)) / 1024
summarySize = old_div(len(json.dumps(workflowData)), 1024)
if summarySize > 6 * 1024: # 6MB
msg = "Workload summary for %s is too big: %d Kb. " % (workflowName, summarySize)
msg += "Wiping out the 'errors' section to make it smaller."
logging.warning(msg)
workflowData['errors'] = {}
summarySize = len(json.dumps(workflowData)) / 1024
summarySize = old_div(len(json.dumps(workflowData)), 1024)

# Now we have the workflowData in the right format, time to push it
logging.info("About to commit %d Kb of data for workflow summary for %s", summarySize, workflowName)
Expand Down Expand Up @@ -989,7 +991,7 @@ def filterInterestingPerfPoints(self, responseJSON, minLumi, maxLumi):
# Those should come from the config :
if points[i] == 0:
continue
binSize = responseJSON["hist"]["xaxis"]["last"]["value"] / responseJSON["hist"]["xaxis"]["last"]["id"]
binSize = old_div(responseJSON["hist"]["xaxis"]["last"]["value"], responseJSON["hist"]["xaxis"]["last"]["id"])
# Fetching the important values
instLuminosity = i * binSize
timePerEvent = points[i]
Expand Down
14 changes: 8 additions & 6 deletions src/python/WMCore/Algorithms/MathAlgos.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
Simple mathematical tools and tricks that might prove to
be useful.
"""
from __future__ import division

from past.utils import old_div
import math
import decimal
import logging
Expand Down Expand Up @@ -57,13 +59,13 @@ def getAverageStdDev(numList):
if length < 1:
return average, total

average = float(total)/length
average = old_div(float(total),length)

for value in numList:
tmpValue = value - average
stdBase += (tmpValue * tmpValue)

stdDev = math.sqrt(stdBase/length)
stdDev = math.sqrt(old_div(stdBase,length))

if math.isnan(average) or math.isinf(average):
average = 0.0
Expand Down Expand Up @@ -127,7 +129,7 @@ def createHistogram(numList, nBins, limit):
nBins = 1
upperBound = upperBound + 1
lowerBound = lowerBound - 1
binSize = float(upperBound - lowerBound)/nBins
binSize = old_div(float(upperBound - lowerBound),nBins)
binSize = floorTruncate(binSize)

for x in range(nBins):
Expand Down Expand Up @@ -184,7 +186,7 @@ def floorTruncate(value, precision = 3):

prec = math.pow(10, precision)

return math.floor(float(value * prec))/float(prec)
return old_div(math.floor(float(value * prec)),float(prec))


def sortDictionaryListByKey(dictList, key, reverse = False):
Expand Down Expand Up @@ -256,7 +258,7 @@ def calculateRunningAverageAndQValue(newPoint, n, oldM, oldQ):
else:
if not validateNumericInput(oldM): raise MathAlgoException("Provided a non-valid oldM")
if not validateNumericInput(oldQ): raise MathAlgoException("Provided a non-valid oldQ")
M = oldM + (newPoint - oldM) / n
M = oldM + old_div((newPoint - oldM), n)
Q = oldQ + ((n - 1) * (newPoint - oldM) * (newPoint - oldM) / n)

return M, Q
Expand All @@ -275,7 +277,7 @@ def calculateStdDevFromQ(Q, n):
if not validateNumericInput(Q): raise MathAlgoException("Provided a non-valid Q")
if not validateNumericInput(n): raise MathAlgoException("Provided a non-valid n")

sigma = math.sqrt(Q / n)
sigma = math.sqrt(old_div(Q, n))

if not validateNumericInput(sigma): return 0.0

Expand Down
6 changes: 4 additions & 2 deletions src/python/WMCore/Credential/Proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
_Proxy_
Wrap gLite proxy commands.
"""
from __future__ import division

from past.utils import old_div
import contextlib
import copy
import os
Expand Down Expand Up @@ -209,7 +211,7 @@ def getUserCertEnddate(self, openSSL=True):
if self.retcode:
raise CredentialException('Cannot get user certificate remaining time with "voms-proxy-info"')

daystoexp = int(timeleft / (60 * 60 * 24))
daystoexp = int(old_div(timeleft, (60 * 60 * 24)))
return daystoexp

def getProxyDetails(self):
Expand Down Expand Up @@ -603,7 +605,7 @@ def vomsExtensionRenewal(self, proxy, voAttribute='cms'):
timeLeft = int(timeLeft.strip())

if timeLeft > 0:
vomsValid = "%d:%02d" % (timeLeft / 3600, (timeLeft - (timeLeft / 3600) * 3600) / 60)
vomsValid = "%d:%02d" % (old_div(timeLeft, 3600), old_div((timeLeft - (old_div(timeLeft, 3600)) * 3600), 60))

self.logger.debug('Requested voms validity: %s' % vomsValid)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

@author: dballest
"""
from __future__ import division
from past.utils import old_div
import math

from WMCore.DataStructs.MathStructs.SummaryHistogram import SummaryHistogram
Expand Down Expand Up @@ -148,7 +150,7 @@ def binHistogram(self):
# Number of bins can be specified or calculated based on number of points
nBins = self.fixedNBins
if nBins is None:
nBins = int(math.floor((5.0 / 3.0) * math.pow(self.nPoints, 1.0 / 3.0)))
nBins = int(math.floor((old_div(5.0, 3.0)) * math.pow(self.nPoints, old_div(1.0, 3.0))))

# Define min and max
if not self.dropOutliers:
Expand All @@ -160,7 +162,7 @@ def binHistogram(self):
lowerLimit = self.average - (stdDev * self.sigmaLimit)

# Incremental delta
delta = abs(float(upperLimit - lowerLimit)) / nBins
delta = old_div(abs(float(upperLimit - lowerLimit)), nBins)

# Build the bins, it's a list of tuples for now
bins = []
Expand Down
4 changes: 3 additions & 1 deletion src/python/WMCore/Database/CMSCouch.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
NOT A THREAD SAFE CLASS.
"""
from __future__ import print_function
from __future__ import division

from past.utils import old_div
import time
import urllib
import re
Expand Down Expand Up @@ -1144,7 +1146,7 @@ def checkReplicationStatus(self, activeStatus, dbInfo, source, target, checkUpda
adhoc way to check the replication
"""
# monitor the last update on replications according to 5 min + checkpoint_interval
secsUpdateOn = 5 * 60 + activeStatus['checkpoint_interval'] / 1000
secsUpdateOn = 5 * 60 + old_div(activeStatus['checkpoint_interval'], 1000)
lastUpdate = activeStatus["updated_on"]
updateNum = int(activeStatus["source_seq"])
previousUpdateNum = self.getPreviousUpdateSequence(source, target)
Expand Down