本文整理汇总了Python中spartan.util.log_info函数的典型用法代码示例。如果您正苦于以下问题:Python log_info函数的具体用法?Python log_info怎么用?Python log_info使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了log_info函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: benchmark_convnet
def benchmark_convnet(ctx, timer):
image_size = BASE_IMG_SIZE
minibatch = 64
#minibatch = ctx.num_workers
hint = util.divup(image_size, sqrt(ctx.num_workers))
tile_hint = (util.divup(minibatch, ctx.num_workers), N_COLORS, image_size, image_size)
util.log_info('Hint: %s', tile_hint)
images = expr.eager(expr.ones((minibatch, N_COLORS, image_size, image_size),
tile_hint=tile_hint))
w1 = expr.eager(expr.ones((N_FILTERS, N_COLORS) + FILTER_SIZE,
tile_hint=ONE_TILE))
w2 = expr.eager(expr.ones((N_FILTERS, N_FILTERS) + FILTER_SIZE,
tile_hint=ONE_TILE))
w3 = expr.eager(expr.ones((N_FILTERS, N_FILTERS) + FILTER_SIZE,
tile_hint=ONE_TILE))
def _():
conv1 = stencil.stencil(images, w1, 2)
pool1 = stencil.maxpool(conv1)
conv2 = stencil.stencil(pool1, w2, 2)
pool2 = stencil.maxpool(conv2)
conv3 = stencil.stencil(pool2, w3, 2)
pool3 = stencil.maxpool(conv3)
expr.force(pool3)
# force parakeet functions to compile before timing.
_()
for i in range(2):
timer.time_op('convnet', _)
示例2: shortestPath_np
def shortestPath_np(dim, linkMatrix, dist):
#linkMatrix, dist = init(dim, startVertex)
for i in range(1000):
util.log_info("%s", "enter")
dist = (dist + linkMatrix).min(axis = 0).reshape(dim, 1)
util.log_info("numItersation %s", i)
return dist
示例3: test_newaxis
def test_newaxis(self):
na = np.arange(100).reshape(10, 10)
a = expr.from_numpy(na)
Assert.all_eq(na[np.newaxis, 2:7, 4:8].shape,
a[expr.newaxis,2:7, 4:8].shape)
Assert.all_eq(na[np.newaxis, 2:7, np.newaxis, 4:8].shape,
a[expr.newaxis,2:7, expr.newaxis, 4:8].shape)
Assert.all_eq(na[np.newaxis, 2:7, np.newaxis, 4:8, np.newaxis].shape,
a[expr.newaxis,2:7, expr.newaxis, 4:8, expr.newaxis].shape)
#Extreme case
Assert.all_eq(na[np.newaxis, np.newaxis, np.newaxis, np.newaxis, 2:7,
np.newaxis, np.newaxis, np.newaxis, 4:8, np.newaxis,
np.newaxis, np.newaxis].shape,
a[expr.newaxis, expr.newaxis, expr.newaxis, expr.newaxis,
2:7, expr.newaxis, expr.newaxis, expr.newaxis, 4:8,
expr.newaxis, expr.newaxis, expr.newaxis].shape)
util.log_info('\na.shape: %s \nna.shape: %s',
a[expr.newaxis,2:7, expr.newaxis, 4:8, expr.newaxis,
expr.newaxis, expr.newaxis].shape,
na[np.newaxis, 2:7, np.newaxis, 4:8, np.newaxis,
np.newaxis, np.newaxis].shape)
示例4: bfs
def bfs(ctx, dim):
util.log_info("start to computing......")
sGenerate = time.time()
current = eager(
expr.shuffle(
expr.ndarray(
(dim, 1),
dtype = np.int64,
tile_hint = (dim / ctx.num_workers, 1)),
make_current,
))
linkMatrix = eager(
expr.shuffle(
expr.ndarray(
(dim, dim),
dtype = np.int64,
tile_hint = (dim, dim / ctx.num_workers)),
make_matrix,
))
eGenerate = time.time()
startCompute = time.time()
while(True):
next = expr.dot(linkMatrix, current)
formerNum = expr.count_nonzero(current)
laterNum = expr.count_nonzero(next)
hasNew = expr.equal(formerNum, laterNum).glom()
current = next
if (hasNew):
break
current.evaluate()
endCompute = time.time()
return (eGenerate - sGenerate, endCompute - startCompute)
示例5: mark_failed_worker
def mark_failed_worker(self, worker_id):
util.log_info('Marking worker %s as failed.', worker_id)
self._available_workers.remove(worker_id)
for array in self._arrays:
for ex, tile_id in array.tiles.iteritems():
if tile_id.worker == worker_id:
array.bad_tiles.append(ex)
示例6: train_smo_1998
def train_smo_1998(self, data, labels):
'''
Train an SVM model using the SMO (1998) algorithm.
Args:
data(Expr): points to be trained
labels(Expr): the correct labels of the training data
'''
N = data.shape[0] # Number of instances
D = data.shape[1] # Number of features
self.b = 0.0
self.alpha = expr.zeros((N,1), dtype=np.float64, tile_hint=[N/self.ctx.num_workers, 1]).force()
# linear kernel
kernel_results = expr.dot(data, expr.transpose(data), tile_hint=[N/self.ctx.num_workers, N])
labels = expr.force(labels)
self.E = expr.zeros((N,1), dtype=np.float64, tile_hint=[N/self.ctx.num_workers, 1]).force()
for i in xrange(N):
self.E[i, 0] = self.b + expr.reduce(self.alpha, axis=None, dtype_fn=lambda input: input.dtype,
local_reduce_fn=margin_mapper,
accumulate_fn=np.add,
fn_kw=dict(label=labels, data=kernel_results[:,i].force())).glom() - labels[i, 0]
util.log_info("Starting SMO")
it = 0
num_changed = 0
examine_all = True
while (num_changed > 0 or examine_all) and (it < self.maxiter):
util.log_info("Iteration:%d", it)
num_changed = 0
if examine_all:
for i in xrange(N):
num_changed += self.examine_example(i, N, labels, kernel_results)
else:
for i in xrange(N):
if self.alpha[i, 0] > 0 and self.alpha[i, 0] < self.C:
num_changed += self.examine_example(i, N, labels, kernel_results)
it += 1
if examine_all: examine_all = False
elif num_changed == 0: examine_all = True
self.w = expr.zeros((D, 1), dtype=np.float64).force()
for i in xrange(D):
self.w[i,0] = expr.reduce(self.alpha, axis=None, dtype_fn=lambda input: input.dtype,
local_reduce_fn=margin_mapper,
accumulate_fn=np.add,
fn_kw=dict(label=labels, data=expr.force(data[:,i]))).glom()
self.usew_ = True
print 'iteration finish:', it
print 'b:', self.b
print 'w:', self.w.glom()
示例7: start_remote_worker
def start_remote_worker(worker, st, ed):
"""
Start processes on a worker machine.
The machine will launch worker processes ``st`` through ``ed``.
:param worker: hostname to connect to.
:param st: First process index to start.
:param ed: Last process to start.
"""
if FLAGS.use_threads and worker == "localhost":
util.log_info("Using threads.")
for i in range(st, ed):
p = threading.Thread(target=spartan.worker._start_worker, args=((socket.gethostname(), FLAGS.port_base), i))
p.daemon = True
p.start()
time.sleep(0.1)
return
util.log_info("Starting worker %d:%d on host %s", st, ed, worker)
if FLAGS.oprofile:
os.system("mkdir operf.%s" % worker)
ssh_args = ["ssh", "-oForwardX11=no", worker]
args = ["cd %s && " % os.path.abspath(os.path.curdir)]
if FLAGS.xterm:
args += ["xterm", "-e"]
if FLAGS.oprofile:
args += ["operf -e CPU_CLK_UNHALTED:100000000", "-g", "-d", "operf.%s" % worker]
args += [
#'gdb', '-ex', 'run', '--args',
"python",
"-m spartan.worker",
"--master=%s:%d" % (socket.gethostname(), FLAGS.port_base),
"--count=%d" % (ed - st),
"--heartbeat_interval=%d" % FLAGS.heartbeat_interval,
]
# add flags from config/user
for (name, value) in FLAGS:
if name in ["worker_list", "print_options"]:
continue
args += [repr(value)]
# print >>sys.stderr, args
util.log_debug("Running worker %s", " ".join(args))
time.sleep(0.1)
# TODO: improve this to make log break at newline
if worker != "localhost":
p = subprocess.Popen(ssh_args + args, executable="ssh")
else:
p = subprocess.Popen(" ".join(args), shell=True, stdin=subprocess.PIPE)
return p
示例8: fuzzy_kmeans
def fuzzy_kmeans(points, k=10, num_iter=10, m=2.0, centers=None):
'''
clustering data points using fuzzy kmeans clustering method.
Args:
points(Expr or DistArray): the input data points matrix.
k(int): the number of clusters.
num_iter(int): the max iterations to run.
m(float): the parameter of fuzzy kmeans.
centers(Expr or DistArray): the initialized centers of each cluster.
'''
points = expr.force(points)
num_dim = points.shape[1]
if centers is None:
centers = expr.rand(k, num_dim)
labels = expr.zeros((points.shape[0],), dtype=np.int)
for iter in range(num_iter):
centers = expr.as_array(centers)
points_broadcast = expr.reshape(points, (points.shape[0], 1, points.shape[1]))
centers_broadcast = expr.reshape(centers, (1, centers.shape[0], centers.shape[1]))
distances = expr.sum(expr.square(points_broadcast - centers_broadcast), axis=2)
# This is used to avoid dividing zero
distances = distances + 0.00000000001
util.log_info('distances shape %s' % str(distances.shape))
distances_broadcast = expr.reshape(distances, (distances.shape[0], 1,
distances.shape[1]))
distances_broadcast2 = expr.reshape(distances, (distances.shape[0],
distances.shape[1], 1))
prob = 1.0 / expr.sum(expr.power(distances_broadcast / distances_broadcast2,
2.0 / (m - 1)), axis=2)
prob.force()
counts = expr.sum(prob, axis=0)
counts = expr.reshape(counts, (counts.shape[0], 1))
labels = expr.argmax(prob, axis=1)
centers = expr.sum(expr.reshape(points, (points.shape[0], 1, points.shape[1])) *
expr.reshape(prob, (prob.shape[0], prob.shape[1], 1)),
axis=0)
# We assume that the size of centers are relative small that can be handled
# on the master.
counts = counts.glom()
centers = centers.glom()
# If any centroids don't have any points assigned to them.
zcount_indices = (counts == 0).reshape(k)
if np.any(zcount_indices):
# One or more centroids may not have any points assigned to them, which results in their
# position being the zero-vector. We reseed these centroids with new random values
# and set their counts to 1 in order to get rid of dividing by zero.
counts[zcount_indices, :] = 1
centers[zcount_indices, :] = np.random.rand(np.count_nonzero(zcount_indices),
num_dim)
centers = centers / counts
return labels
示例9: start_remote_worker
def start_remote_worker(worker, st, ed):
'''
Start processes on a worker machine.
The machine will launch worker processes ``st`` through ``ed``.
:param worker: hostname to connect to.
:param st: First process index to start.
:param ed: Last process to start.
'''
if FLAGS.use_threads and worker == 'localhost':
util.log_info('Using threads.')
for i in range(st, ed):
p = threading.Thread(target=spartan.worker._start_worker,
args=((socket.gethostname(), FLAGS.port_base), i))
p.daemon = True
p.start()
time.sleep(0.1)
return
util.log_info('Starting worker %d:%d on host %s', st, ed, worker)
if FLAGS.oprofile:
os.system('mkdir operf.%s' % worker)
ssh_args = ['ssh', '-oForwardX11=no', worker ]
args = ['cd %s && ' % os.path.abspath(os.path.curdir)]
if FLAGS.xterm:
args += ['xterm', '-e',]
if FLAGS.oprofile:
args += ['operf -e CPU_CLK_UNHALTED:100000000', '-g', '-d', 'operf.%s' % worker]
args += [
#'gdb', '-ex', 'run', '--args',
'python', '-m spartan.worker',
'--master=%s:%d' % (socket.gethostname(), FLAGS.port_base),
'--count=%d' % (ed - st),
'--heartbeat_interval=%d' % FLAGS.heartbeat_interval
]
# add flags from config/user
for (name, value) in FLAGS:
if name in ['worker_list', 'print_options']: continue
args += [repr(value)]
#print >>sys.stderr, args
util.log_debug('Running worker %s', ' '.join(args))
time.sleep(0.1)
if worker != 'localhost':
p = subprocess.Popen(ssh_args + args, executable='ssh')
else:
p = subprocess.Popen(' '.join(args), shell=True, stdin=subprocess.PIPE)
return p
示例10: make_current
def make_current(tile, ex):
util.log_info("start to creatting")
ul = ex.ul
lr = ex.lr
dim = ex.shape[0]
current = np.zeros((dim, 1), dtype = np.int64)
if(ul[0] <= startVertex <= lr[0]):
current[startVertex, 0] = 1
return [(ex, current)]
示例11: test_del_dim
def test_del_dim(self):
na = np.arange(100).reshape(10, 10)
a = expr.from_numpy(na)
Assert.all_eq(na[2:7, 8], a[2:7, 8].glom())
Assert.all_eq(na[3:9, 4].shape, a[3:9, 4].shape)
Assert.all_eq(na[2:7, -1], a[2:7, -1].glom())
Assert.all_eq(na[-1, 3:9].shape, a[-1, 3:9].shape)
util.log_info('\na.shape: %s \nna.shape %s', a[3:9, 4].shape, na[3:9, 4].shape)
示例12: bind
def bind(self):
host, port = self.addr
host = socket.gethostbyname(host)
util.log_debug('Binding... %s', (host, port))
if port == -1:
self.addr = (host, self._zmq.bind_to_random_port('tcp://%s' % host))
else:
try:
self._zmq.bind('tcp://%s:%d' % (host, port))
except zmq.ZMQError:
util.log_info('Failed to bind (%s, %d)' % (host, port))
raise
示例13: test_ndimension
def test_ndimension(self):
for case in xrange(5):
dim = np.random.randint(low=2, high=6)
shape = np.random.randint(low=5, high=11, size=dim)
util.log_info('Test Case #%s: DIM(%s) shape%s', case + 1, dim, shape)
na = new_ndarray(shape)
a = expr.from_numpy(na)
for axis in xrange(dim):
Assert.all_eq(expr.sort(a, axis).glom(),
np.sort(na, axis))
Assert.all_eq(expr.argsort(a, axis).glom(),
np.argsort(na, axis))
示例14: benchmark_jacobi
def benchmark_jacobi(ctx, timer):
global base, ITERATION
util.log_warn('util.log_warn: %s', ctx.num_workers)
A, b = jacobi.jacobi_init(base * ctx.num_workers)
A, b = A.evaluate(), b.evaluate()
start = time.time()
result = jacobi.jacobi_method(A, b, ITERATION).glom()
cost = time.time() - start
util.log_info('\nresult =\n%s', result)
util.log_warn('time cost: %s s', cost)
util.log_warn('cost per iteration: %s s\n', cost / ITERATION)
示例15: shutdown
def shutdown(self):
'''Shutdown all workers and halt.'''
if self._ctx.active is False:
return
self._ctx.active = False
futures = rpc.FutureGroup()
for id, w in self._workers.iteritems():
util.log_info('Shutting down worker %d', id)
futures.append(w.shutdown())
# Wait a second to let our shutdown request go out.
time.sleep(1)
self._server.shutdown()