Skip to content

Commit

Permalink
Merge pull request #279 from carterbox/revise-logging
Browse files Browse the repository at this point in the history
DOC: Make logging less verbose
  • Loading branch information
carterbox authored Oct 3, 2023
2 parents 76b75f2 + c739c5d commit b8a452d
Show file tree
Hide file tree
Showing 9 changed files with 38 additions and 25 deletions.
2 changes: 1 addition & 1 deletion src/tike/lamino/solvers/bucket.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def _estimate_step_length(obj, fwd_data, theta, grid, op, comm, s):
proper order of magnitude.
"""
logger.info('Estimate step length from forward adjoint operations.')
logger.debug('Estimate step length from forward adjoint operations.')

def reduce_norm(data, workers):

Expand Down
2 changes: 1 addition & 1 deletion src/tike/lamino/solvers/cgrad.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def _estimate_step_length(obj, theta, op):
proper order of magnitude.
"""
logger.info('Estimate step length from forward adjoint operations.')
logger.debug('Estimate step length from forward adjoint operations.')
outnback = op.adj(
data=op.fwd(u=obj, theta=theta),
theta=theta,
Expand Down
8 changes: 4 additions & 4 deletions src/tike/opt.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def momentum(g, v, m, vdecay=None, mdecay=0.9):
eps : float
A tiny constant to prevent zero division.
"""
logger.info("Momentum decay m=%+.3e", mdecay)
logger.debug("Momentum decay m=%+.3e", mdecay)
m = 0 if m is None else m
m = mdecay * m + (1 - mdecay) * g
return m, None, m
Expand Down Expand Up @@ -203,7 +203,7 @@ def adam(
Kingma, Diederik P., and Jimmy Ba. "Adam: A method for stochastic
optimization." arXiv preprint arXiv:1412.6980 (2014).
"""
logger.info("ADAM decay m=%+.3e, v=%+.3e; eps=%+.3e", mdecay, vdecay, eps)
logger.debug("ADAM decay m=%+.3e, v=%+.3e; eps=%+.3e", mdecay, vdecay, eps)
v = np.zeros_like(g.real) if v is None else v
m = np.zeros_like(g) if m is None else m
m = mdecay * m + (1 - mdecay) * g
Expand Down Expand Up @@ -272,7 +272,7 @@ def line_search(
break
step_count += 1

logger.info("line_search: %d backtracks; %.3e -> %.3e; cost %.6e",
logger.debug("line_search: %d backtracks; %.3e -> %.3e; cost %.6e",
step_count, first_step, step_length, fxsd)

return step_length, fxsd, xsd
Expand Down Expand Up @@ -372,7 +372,7 @@ def conjugate_gradient(
)
else:
x = update_multi(x, step_length, dir_list)
logger.info("Blind update; length %.3e", step_length)
logger.debug("Blind update; length %.3e", step_length)

if __debug__ and num_search < num_iter:
cost = cost_function(x)
Expand Down
7 changes: 5 additions & 2 deletions src/tike/ptycho/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,11 @@ def position_units_to_pixels(
(detector_pixel_width * detector_pixel_count) /
(detector_distance * wavelength(photon_energy / 1000) / 100))
logger.info(
"Based on detector distance and photon energy,"
f" reconstruction pixel size will be {1 / pixel_per_meter:.3e} m.")
f"For a detector of {detector_pixel_count:d} pixels"
f" each {detector_pixel_width:.3e} m wide"
f" with propagation distance {detector_distance:.3e} m"
f" and photon energy {photon_energy:.3e} eV;"
f" the reconstruction pixel size will be {1 / pixel_per_meter:.3e} m.")
return positions * pixel_per_meter


Expand Down
2 changes: 1 addition & 1 deletion src/tike/ptycho/position.py
Original file line number Diff line number Diff line change
Expand Up @@ -625,7 +625,7 @@ def update_positions_pd(operator, data, psi, probe, scan,

check_allowed_positions(scan, psi, probe.shape)
cost = operator.cost(data=data, psi=psi, scan=scan, probe=probe).get()
logger.info('%10s cost is %+12.5e', 'position', cost)
logger.debug('%10s cost is %+12.5e', 'position', cost)
return scan, cost


Expand Down
35 changes: 26 additions & 9 deletions src/tike/ptycho/ptycho.py
Original file line number Diff line number Diff line change
Expand Up @@ -476,8 +476,7 @@ def iterate(self, num_iter: int) -> None:
self.parameters.psi = self.comm.pool.map(
tike.ptycho.object.smoothness_constraint,
self.parameters.psi,
a=self.parameters.object_options
.smoothness_constraint,
a=self.parameters.object_options.smoothness_constraint,
)

if self.parameters.object_options.clip_magnitude:
Expand All @@ -487,9 +486,11 @@ def iterate(self, num_iter: int) -> None:
a_max=1.0,
)

if (self.parameters.algorithm_options.name != 'dm'
and self.parameters.object_options.preconditioner is not None
and (len(self.parameters.algorithm_options.costs) % 10 == 1)):
if (
self.parameters.algorithm_options.name != 'dm'
and self.parameters.object_options.preconditioner is not None
and len(self.parameters.algorithm_options.costs) % 10 == 1
): # yapf: disable
(
self.parameters.psi,
self.parameters.probe,
Expand Down Expand Up @@ -537,6 +538,12 @@ def iterate(self, num_iter: int) -> None:
)
break

logger.info(
'%10s cost is %+1.3e',
self.parameters.exitwave_options.noise_model,
np.mean(self.parameters.algorithm_options.costs[-1]),
)

def get_result(self):
"""Return the current parameter estimates."""
reorder = np.argsort(np.concatenate(self.comm.order))
Expand Down Expand Up @@ -734,7 +741,10 @@ def make_certain_args_constant(
_,
) -> typing.Tuple[npt.NDArray]:

(data, scan,) = ind_args
(
data,
scan,
) = ind_args
(sums,) = mod_args

intensity, _ = operator._compute_intensity(
Expand All @@ -747,12 +757,19 @@ def make_certain_args_constant(
sums[0] += cp.sum(data[:, measured_pixels], dtype=np.double)
sums[1] += cp.sum(intensity[:, measured_pixels], dtype=np.double)

return [sums,]
return [
sums,
]

result = tike.communicators.stream.stream_and_modify(
f=make_certain_args_constant,
ind_args=[data, scan,],
mod_args=[sums,],
ind_args=[
data,
scan,
],
mod_args=[
sums,
],
streams=streams,
)

Expand Down
1 change: 0 additions & 1 deletion src/tike/ptycho/solvers/dm.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ def dm(
)))

cost = comm.Allreduce_mean(cost, axis=None).get()
logger.info('%10s cost is %+12.5e', 'farplane', cost)
batch_cost.append(cost)

(
Expand Down
3 changes: 0 additions & 3 deletions src/tike/ptycho/solvers/lstsq.py
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,6 @@ def _update_nearplane(
):
m = 0
if eigen_weights[0] is not None:
logger.info('Updating eigen probes')

eigen_weights = comm.pool.map(
_get_coefs_intensity,
Expand Down Expand Up @@ -864,8 +863,6 @@ def _update_position(
alpha * max(position_update_denominator.max(), 1e-6))

if position_options.use_adaptive_moment:
logger.info(
"position correction with ADAptive Momemtum acceleration enabled.")
(
step,
position_options.v,
Expand Down
3 changes: 0 additions & 3 deletions src/tike/ptycho/solvers/rpie.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,6 @@ def rpie(
)))

batch_cost.append(comm.Allreduce_mean(cost, axis=None).get())
logger.info('%10s cost is %+12.5e', 'farplane', batch_cost[-1])

if algorithm_options.batch_method != 'compact':
(
Expand Down Expand Up @@ -564,8 +563,6 @@ def _update_position(
alpha * max(position_update_denominator.max(), 1e-6))

if position_options.use_adaptive_moment:
logger.info(
"position correction with ADAptive Momemtum acceleration enabled.")
(
step,
position_options.v,
Expand Down

0 comments on commit b8a452d

Please sign in to comment.