BornAgain  1.19.79
Simulate and fit neutron and x-ray scattering at grazing incidence
GUIFitObserver Class Reference

Description

Serves as observer for FitObjective and saves fit iteration data for later display in GUI widgets.

Definition at line 30 of file GUIFitObserver.h.

Inheritance diagram for GUIFitObserver:
[legend]
Collaboration diagram for GUIFitObserver:
[legend]

Public Slots

void setInterval (int val)
 

Signals

void updateReady ()
 

Public Member Functions

 GUIFitObserver (QObject *parent=nullptr)
 
 ~GUIFitObserver () override
 
void finishedPlotting ()
 Informs observer that FitSuiteWidget has finished plotting and is ready for next plot. More...
 
FitProgressInfo progressInfo ()
 
void update (const FitObjective *subject)
 

Private Member Functions

bool is_obligatory_iteration (const FitObjective *fitSuite) const
 Returns true if given iteration should be obligary plotted. More...
 
bool is_suitable_iteration (const FitObjective *fitSuite) const
 Returns true if data could be plotted, when there are resources for it. More...
 

Private Attributes

bool m_block_update_plots
 
FitProgressInfo m_iteration_info
 
std::condition_variable m_on_finish_notifier
 
int m_update_interval
 
std::mutex m_update_plot_mutex
 

Constructor & Destructor Documentation

◆ GUIFitObserver()

GUIFitObserver::GUIFitObserver ( QObject *  parent = nullptr)

Definition at line 22 of file GUIFitObserver.cpp.

23  : QObject(parent)
24  , m_block_update_plots(false)
26 {
27 }
bool m_block_update_plots

◆ ~GUIFitObserver()

GUIFitObserver::~GUIFitObserver ( )
overridedefault

Member Function Documentation

◆ finishedPlotting()

void GUIFitObserver::finishedPlotting ( )

Informs observer that FitSuiteWidget has finished plotting and is ready for next plot.

Definition at line 83 of file GUIFitObserver.cpp.

84 {
85  std::unique_lock<std::mutex> lock(m_update_plot_mutex);
86  m_block_update_plots = false;
87  lock.unlock();
88  m_on_finish_notifier.notify_one();
89 }
std::condition_variable m_on_finish_notifier
std::mutex m_update_plot_mutex

References m_block_update_plots, m_on_finish_notifier, and m_update_plot_mutex.

◆ is_obligatory_iteration()

bool GUIFitObserver::is_obligatory_iteration ( const FitObjective *  fitSuite) const
private

Returns true if given iteration should be obligary plotted.

Definition at line 71 of file GUIFitObserver.cpp.

72 {
73  return fitSuite->isCompleted();
74 }

Referenced by update().

◆ is_suitable_iteration()

bool GUIFitObserver::is_suitable_iteration ( const FitObjective *  fitSuite) const
private

Returns true if data could be plotted, when there are resources for it.

Definition at line 59 of file GUIFitObserver.cpp.

60 {
61  if (fitSuite->isInterrupted())
62  return false;
63 
64  int n_iter = static_cast<int>(fitSuite->iterationInfo().iterationCount());
65  return fitSuite->isFirstIteration() || n_iter % m_update_interval == 0
66  || fitSuite->isCompleted();
67 }

References m_update_interval.

Referenced by update().

◆ progressInfo()

FitProgressInfo GUIFitObserver::progressInfo ( )

Definition at line 91 of file GUIFitObserver.cpp.

92 {
93  std::unique_lock<std::mutex> lock(m_update_plot_mutex);
94  m_block_update_plots = true;
95  return m_iteration_info;
96 }
FitProgressInfo m_iteration_info

References m_block_update_plots, m_iteration_info, and m_update_plot_mutex.

◆ setInterval

void GUIFitObserver::setInterval ( int  val)
slot

Definition at line 76 of file GUIFitObserver.cpp.

77 {
78  m_update_interval = val;
79 }

References m_update_interval.

◆ update()

void GUIFitObserver::update ( const FitObjective *  subject)

Definition at line 31 of file GUIFitObserver.cpp.

32 {
33  if (!is_suitable_iteration(subject))
34  return;
35 
36  std::unique_lock<std::mutex> lock(m_update_plot_mutex);
38  return; // plotting still works, will skip iteration
39 
41  m_on_finish_notifier.wait(lock, [this]() { return m_block_update_plots; });
42 
43  FitProgressInfo info;
44  info.m_chi2 = subject->iterationInfo().chi2();
45  info.m_iteration_count = static_cast<int>(subject->iterationInfo().iterationCount());
46  info.m_values = subject->iterationInfo().parameters().values();
47 
48  if (subject->isCompleted())
49  info.m_log_info = subject->minimizerResult().toString();
50 
51  info.m_sim_values = subject->dataPair().simulationResult().flatVector();
52 
53  m_iteration_info = info;
54  emit updateReady();
55 }
The FitProgressInfo class contains all essential information about fit progress. It is send from GUIF...
std::string m_log_info
std::vector< double > m_values
std::vector< double > m_sim_values
bool is_suitable_iteration(const FitObjective *fitSuite) const
Returns true if data could be plotted, when there are resources for it.
bool is_obligatory_iteration(const FitObjective *fitSuite) const
Returns true if given iteration should be obligary plotted.
void updateReady()

References is_obligatory_iteration(), is_suitable_iteration(), m_block_update_plots, FitProgressInfo::m_chi2, FitProgressInfo::m_iteration_count, m_iteration_info, FitProgressInfo::m_log_info, m_on_finish_notifier, FitProgressInfo::m_sim_values, m_update_plot_mutex, FitProgressInfo::m_values, and updateReady().

Here is the call graph for this function:

◆ updateReady

void GUIFitObserver::updateReady ( )
signal

Member Data Documentation

◆ m_block_update_plots

bool GUIFitObserver::m_block_update_plots
private

Definition at line 53 of file GUIFitObserver.h.

Referenced by finishedPlotting(), progressInfo(), and update().

◆ m_iteration_info

FitProgressInfo GUIFitObserver::m_iteration_info
private

Definition at line 57 of file GUIFitObserver.h.

Referenced by progressInfo(), and update().

◆ m_on_finish_notifier

std::condition_variable GUIFitObserver::m_on_finish_notifier
private

Definition at line 55 of file GUIFitObserver.h.

Referenced by finishedPlotting(), and update().

◆ m_update_interval

int GUIFitObserver::m_update_interval
private

Definition at line 56 of file GUIFitObserver.h.

Referenced by is_suitable_iteration(), and setInterval().

◆ m_update_plot_mutex

std::mutex GUIFitObserver::m_update_plot_mutex
private

Definition at line 54 of file GUIFitObserver.h.

Referenced by finishedPlotting(), progressInfo(), and update().


The documentation for this class was generated from the following files: