33 #include <tomographerpy/common.h> 38 #include <tomographerpy/pymhrw.h> 39 #include <tomographerpy/exc.h> 76 : num_completed(-1), num_total_runs(-1), elapsed(0.0),
77 workers(), total_fraction_done(), human_report()
110 template<
typename TaskType>
116 static inline void addDataFields(py::dict & ,
const typename TaskType::StatusReportType & ) { }
126 template<
typename CData,
typename Rng>
130 static inline void addDataFields(py::dict & d,
const TaskStatusReportType & wr) {
137 d[
"kstep"] = wr.
kstep;
150 template<
typename TaskType,
typename IntType =
int>
173 wreport.
msg = rr.msg;
201 template<
typename TaskDispatcher>
203 int progress_interval_ms,
bool require_gil_acquisition =
false)
205 typedef typename TaskDispatcher::TaskType TaskType;
212 auto fn = [progress_fn](
const typename TaskDispatcher::FullStatusReportType & report) {
214 if (PyErr_Occurred() != NULL || PyErr_CheckSignals() == -1) {
219 if (!progress_fn.is_none()) {
220 auto r = preparePyTaskStatusReport<TaskType>(report);
222 progress_fn(py::cast(r));
223 if (PyErr_Occurred() != NULL || PyErr_CheckSignals() == -1) {
224 fprintf(stderr,
"DEBUG:: error set, throwing\n") ;
231 auto fn_with_gil = [fn](
const typename TaskDispatcher::FullStatusReportType & report) {
232 py::gil_scoped_acquire gil_acquire;
236 if (require_gil_acquisition) {
237 tasks.setStatusReportHandler(fn_with_gil);
239 tasks.setStatusReportHandler(fn);
241 tasks.requestPeriodicStatusReport(progress_interval_ms);
IterCountIntType kstep
the current iteration number
double acceptance_ratio
the current acceptance ratio of the random walk (see Tomographer::MHRandomWalk::acceptanceRatio() ) ...
py::float_ fraction_done
Fraction of the job done for this worker (0.0 to 1.0)
Base namespace for the Tomographer project.
py::int_ num_total_runs
Total number of tasks which have been or will be run.
py::dict data
Additional task-specific data; see also PyStatusReportAddWorkerDataFields.
int worker_id
Unique identifier of the worker.
std::vector< TaskStatusReportType, typename Tools::NeedOwnOperatorNew< TaskStatusReportType >::AllocatorType > workers_reports
List with the raw report submitted from each individual thread.
std::vector< bool > workers_running
List specifying for each worker (e.g. a spawned thread) whether it is active or not.
TaskCountIntType num_completed
Number of completed tasks.
std::string getHumanReport() const
Produce a text-based human-readable short representation of the status report.
py::float_ elapsed
Elapsed time in seconds since the launching of the tasks.
Multiprocessing tasks interface (see Multiprocessing Task Interfaces) for parallel Metropolis-Hasting...
Complete status report for multiple tasks running in parallel.
IterCountIntType n_total_iters
the total number of iterations required for this random walk
C++ utility to populate the data field of a WorkerStatusReport for a given TaskType.
py::dict pyMHWalkerParamsToDictInvoke(const MHWalkerParams &p)
Helper for converting any MHWalkerParams into a dictionary, using automatic template parameter deduct...
double totalFractionDone() const
The total fraction of the job completed.
Tomographer::MHRWParams< py::object, IterCountIntType > MHRWParams
The Tomographer::MHRWParams type exposed to Python (the MHWalkerParam can be represented by any Pytho...
Helper for catching exceptions in a thread and re-raising them.
py::int_ num_completed
Number of tasks which have already completed.
tpy::FullStatusReport preparePyTaskStatusReport(const Tomographer::MultiProc::FullStatusReport< typename TaskType::StatusReportType, IntType > &report)
Utility to prepare a Python status report (FullStatusReport) from a task's status report...
static void addDataFields(py::dict &, const typename TaskType::StatusReportType &)
Add fields to the given dict, from a status report sent in by a TaskType. The default implementation ...
py::float_ total_fraction_done
Total fraction of work done, as a fraction between 0 and 1.
Status Report structure representing the status of a MHRandomWalk.
TaskCountIntType num_total_runs
Total number of tasks to perform.
py::str human_report
Complete, human-readable summary of the current status of everything.
void setTasksStatusReportPyCallback(TaskDispatcher &tasks, py::object progress_fn, int progress_interval_ms, bool require_gil_acquisition=false)
Set up status reporting for a task dispatcher, using a Python callback for status reports...
py::list workers
A Python list of worker status; either a WorkerStatusReport, or py::none() if the worker is idle...
Routines for performing a Metropolis-Hastings random walk.
Report of the status of a single worker.
C++ Classes and Utilities for Python Modules.
MHRWParamsType mhrw_params
the parameters of the random walk
double elapsed
Number of seconds elapsed since launching the tasks.
py::str msg
Human-readable message summarizing the status of this worker.
A complete status report, abstract version.