Skip to content

Commit

Permalink
f string
Browse files Browse the repository at this point in the history
  • Loading branch information
Christian-B committed Jun 6, 2024
1 parent e14d338 commit bb674fc
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 19 deletions.
8 changes: 4 additions & 4 deletions mcmc/mcmc_framework.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,8 @@ def run_mcmc(
eth_y = chip.nearest_ethernet_y
coordinator = coordinators.get((eth_x, eth_y))
if coordinator is None:
print("Warning - couldn't find {}, {} for chip {}, {}".format(
eth_x, eth_y, chip.x, chip.y))
print(f"Warning - couldn't find {eth_x}, {eth_y} "
f"for chip {chip.x}, {chip.y}")
coordinator = coordinators[0, 0]
print("Using coordinator ", coordinator)

Expand Down Expand Up @@ -226,8 +226,8 @@ def run_mcmc(
error = txrx.get_core_state_count(app_id, CPUState.RUN_TIME_EXCEPTION)
watchdog = txrx.get_core_state_count(app_id, CPUState.WATCHDOG)
if error > 0 or watchdog > 0:
error_msg = "Some cores have failed ({} RTE, {} WDOG)".format(
error, watchdog)
error_msg = (f"Some cores have failed ({error} RTE, "
f"{watchdog} WDOG)")
raise SpinnmanException(error_msg)
running = txrx.get_core_state_count(app_id, CPUState.RUNNING)
print('running: ', running)
Expand Down
14 changes: 7 additions & 7 deletions mcmc/mcmc_vertex.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,13 +102,13 @@ def _get_model_parameters_array(self):
numpy_values = list()
for i, param in enumerate(parameters):
if (param.data_type is numpy.float64):
numpy_format.append(('f{}'.format(i), param.data_type))
numpy_format.append((f"f{{{i}}}", param.data_type))
numpy_values.append(param.value)
elif (param.data_type is numpy.float32):
numpy_format.append(('f{}'.format(i), param.data_type))
numpy_format.append((f"f{{{i}}}", param.data_type))
numpy_values.append(param.value)
elif (param.data_type is DataType.S1615):
numpy_format.append(('f{}'.format(i), numpy.uint32))
numpy_format.append((f"f{{{i}}}", numpy.uint32))
numpy_values.append(
int(param.value * float(DataType.S1615.scale)))
else:
Expand All @@ -124,16 +124,16 @@ def _get_model_state_array(self):
numpy_values = list()
for i, param in enumerate(state):
if (param.data_type is numpy.float64):
numpy_format.append(('f{}'.format(i), param.data_type))
numpy_format.append((f"f{{{i}}}", param.data_type))
numpy_values.append(param.initial_value)
elif (param.data_type is numpy.float32):
numpy_format.append(('f{}'.format(i), param.data_type))
numpy_format.append((f"f{{{i}}}", param.data_type))
numpy_values.append(param.initial_value)
elif (param.data_type is numpy.uint32):
numpy_format.append(('f{}'.format(i), param.data_type))
numpy_format.append((f"f{{{i}}}", param.data_type))
numpy_values.append(param.initial_value)
elif (param.data_type is DataType.S1615):
numpy_format.append(('f{}'.format(i), numpy.uint32))
numpy_format.append((f"f{{{i}}}", numpy.uint32))
numpy_values.append(
int(param.initial_value * float(DataType.S1615.scale)))
else:
Expand Down
8 changes: 4 additions & 4 deletions mcmc_examples/arma/arma.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,11 @@
# print('samples: ', samples)

# Save the results
dirpath = "results_{}_nboards{}_nsamples{}".format(
strftime("%Y-%m-%d_%H:%M:%S", gmtime()), n_boards, n_samples)
dirpath = (f'results_{strftime("%Y-%m-%d_%H:%M:%S", gmtime())}'
f'_nboards{n_boards}_nsamples{n_samples}')
os.mkdir(dirpath)
for coord, sample in samples.items():
fname = "{}/results_board_x{}_y{}_nboards{}_nsamples{}".format(
dirpath, coord[0], coord[1], n_boards, n_samples)
fname = (f"{dirpath}/results_board_x{coord[0]}_y{coord[1]}"
f"_nboards{n_boards}_nsamples{n_samples}")
numpy.save(fname+".npy", sample)
numpy.savetxt(fname+".csv", sample, fmt="%f", delimiter=",")
9 changes: 5 additions & 4 deletions mcmc_examples/lighthouse/lighthouse.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,12 +300,13 @@ def run_job(_thread_id, _model=model, _data_points=None,

print('samples: ', samples)

dirpath = "results_{}_nboards{}_nsamples{}".format(
strftime("%Y-%m-%d_%H:%M:%S", gmtime()), n_boards, _n_samples)
dirpath = (f'results_{strftime("%Y-%m-%d_%H:%M:%S", gmtime())}'
f'_nboards{n_boards}_nsamples{_n_samples}')
os.mkdir(dirpath)
for coord, sample in samples.items():
fname = "{}/results_th{}_board_x{}_y{}_nboards{}_nsamples{}".format(
dirpath, _thread_id[0], coord[0], coord[1], n_boards, _n_samples)
fname = (f"{dirpath}/results_th{_thread_id[0]}"
f"_board_x{coord[0]}_y{coord[1]}_nboards{n_boards}"
f"_nsamples{_n_samples}")
numpy.save(fname+".npy", sample)
numpy.savetxt(fname+".csv", sample, fmt="%f", delimiter=",")

Expand Down

0 comments on commit bb674fc

Please sign in to comment.