Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_dict_from_and_to_json():
dct = {1: 0.5, 2: 42, 3: [1, 2, 0.1]}
file_ = tempfile.mkstemp()[1]
pyabc.storage.save_dict_to_json(dct, file_)
re_dct = pyabc.storage.load_dict_from_json(file_)
assert dct == re_dct
def log(self, t):
logger.debug(f"pdf_norm={self.pdf_norms[t]:.4e} for t={t}.")
if self.log_file:
save_dict_to_json(self.pdf_norms, self.log_file)
fallback = self.temperatures[t-1] \
if t-1 in self.temperatures else np.inf
temperature = self.aggregate_fun(temps)
# also a value lower than 1.0 does not make sense
temperature = max(min(temperature, fallback), 1.0)
if not np.isfinite(temperature):
raise ValueError("Temperature must be finite.")
# record found value
self.temperatures[t] = temperature
# logging
logger.debug(f"Proposed temperatures for {t}: {temps}.")
self.temperature_proposals[t] = temps
if self.log_file:
save_dict_to_json(self.temperature_proposals, self.log_file)
def log(self, t: int) -> None:
logger.debug(f"updated weights[{t}] = {self.weights[t]}")
if self.log_file:
save_dict_to_json(self.weights, self.log_file)
def log(self, t: int) -> None:
logger.debug(f"updated weights[{t}] = {self.weights[t]}")
if self.log_file:
save_dict_to_json(self.weights, self.log_file)