Commit 5257b709 authored by Martin Reinecke's avatar Martin Reinecke
Browse files

merge

parents a272d7c5 222a4305
Pipeline #65030 passed with stages
in 9 minutes and 34 seconds
......@@ -18,6 +18,7 @@
import numpy as np
from ..logger import logger
from ..domain_tuple import DomainTuple
from ..domains.power_space import PowerSpace
from ..domains.unstructured_domain import UnstructuredDomain
......@@ -52,9 +53,9 @@ def _lognormal_moments(mean, sig, N=0):
else:
mean, sig = (_reshaper(param, N) for param in (mean, sig))
if not np.all(mean > 0):
raise ValueError(f"mean must be greater 0; got {mean!r}")
raise ValueError("mean must be greater 0; got {!r}".format(mean))
if not np.all(sig > 0):
raise ValueError(f"sig must be greater 0; got {sig!r}")
raise ValueError("sig must be greater 0; got {!r}".format(sig))
logsig = np.sqrt(np.log((sig/mean)**2 + 1))
logmean = np.log(mean) - logsig**2/2
......@@ -501,7 +502,7 @@ class CorrelatedFieldMaker:
mean = sc.mean.val
stddev = sc.var.sqrt().val
for m, s in zip(mean.flatten(), stddev.flatten()):
print('{}: {:.02E} ± {:.02E}'.format(kk, m, s))
logger.info('{}: {:.02E} ± {:.02E}'.format(kk, m, s))
def moment_slice_to_average(self, fluctuations_slice_mean, nsamples=1000):
fluctuations_slice_mean = float(fluctuations_slice_mean)
......@@ -554,7 +555,7 @@ class CorrelatedFieldMaker:
if len(self._a) == 0:
raise NotImplementedError
if space >= len(self._a):
raise ValueError(f"invalid space specified; got {space!r}")
raise ValueError("invalid space specified; got {!r}".format(space))
if len(self._a) == 1:
return self.average_fluctuation(0)
q = 1.
......@@ -571,7 +572,7 @@ class CorrelatedFieldMaker:
if len(self._a) == 0:
raise NotImplementedError
if space >= len(self._a):
raise ValueError(f"invalid space specified; got {space!r}")
raise ValueError("invalid space specified; got {!r}".format(space))
if len(self._a) == 1:
return self._a[0].fluctuation_amplitude
return self._a[space].fluctuation_amplitude
......@@ -593,7 +594,7 @@ class CorrelatedFieldMaker:
space) realizations."""
ldom = len(samples[0].domain)
if space >= ldom:
raise ValueError(f"invalid space specified; got {space!r}")
raise ValueError("invalid space specified; got {!r}".format(space))
if ldom == 1:
return _total_fluctuation_realized(samples)
res1, res2 = 0., 0.
......@@ -611,7 +612,7 @@ class CorrelatedFieldMaker:
space) realizations."""
ldom = len(samples[0].domain)
if space >= ldom:
raise ValueError(f"invalid space specified; got {space!r}")
raise ValueError("invalid space specified; got {!r}".format(space))
if ldom == 1:
return _total_fluctuation_realized(samples)
spaces = ()
......
......@@ -20,6 +20,7 @@ from time import time
import numpy as np
from .logger import logger
from . import utilities
from .domain_tuple import DomainTuple
from .domains.power_space import PowerSpace
......@@ -436,46 +437,46 @@ def exec_time(obj, want_metric=True):
if isinstance(obj, Energy):
t0 = time()
obj.at(0.99*obj.position)
print('Energy.at():', time() - t0)
logger.info('Energy.at(): {}'.format(time() - t0))
t0 = time()
obj.value
print('Energy.value:', time() - t0)
logger.info('Energy.value: {}'.format(time() - t0))
t0 = time()
obj.gradient
print('Energy.gradient:', time() - t0)
logger.info('Energy.gradient: {}'.format(time() - t0))
t0 = time()
obj.metric
print('Energy.metric:', time() - t0)
logger.info('Energy.metric: {}'.format(time() - t0))
t0 = time()
obj.apply_metric(obj.position)
print('Energy.apply_metric:', time() - t0)
logger.info('Energy.apply_metric: {}'.format(time() - t0))
t0 = time()
obj.metric(obj.position)
print('Energy.metric(position):', time() - t0)
logger.info('Energy.metric(position): {}'.format(time() - t0))
elif isinstance(obj, Operator):
want_metric = bool(want_metric)
pos = from_random('normal', obj.domain)
t0 = time()
obj(pos)
print('Operator call with field:', time() - t0)
logger.info('Operator call with field: {}'.format(time() - t0))
lin = Linearization.make_var(pos, want_metric=want_metric)
t0 = time()
res = obj(lin)
print('Operator call with linearization:', time() - t0)
logger.info('Operator call with linearization: {}'.format(time() - t0))
if isinstance(obj, EnergyOperator):
t0 = time()
res.gradient
print('Gradient evaluation:', time() - t0)
logger.info('Gradient evaluation: {}'.format(time() - t0))
if want_metric:
t0 = time()
res.metric(pos)
print('Metric apply:', time() - t0)
logger.info('Metric apply: {}'.format(time() - t0))
else:
raise TypeError
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment