MUQ  0.4.3
RemoteMIProposal.h
Go to the documentation of this file.
1 #ifndef REMOTEMIPROPOSAL_H_
2 #define REMOTEMIPROPOSAL_H_
3 
4 #include "MUQ/config.h"
5 
6 #if MUQ_HAS_MPI
7 
8 #if !MUQ_HAS_PARCER
9 #error
10 #endif
11 
12 
13 #include <boost/property_tree/ptree.hpp>
15 
16 #include <boost/property_tree/ptree.hpp>
17 namespace pt = boost::property_tree;
18 
19 namespace muq {
20  namespace SamplingAlgorithms {
21 
28  class RemoteMIProposal : public MCMCProposal {
29  public:
30  RemoteMIProposal (pt::ptree const& pt, std::shared_ptr<AbstractSamplingProblem> prob, std::shared_ptr<parcer::Communicator> comm, std::shared_ptr<MultiIndex> remoteIndex, std::shared_ptr<MultiIndex> sourceIndex, std::shared_ptr<PhonebookClient> phonebookClient)
31  : MCMCProposal(pt,prob),
32  //subsampling(pt.get<int>("Subsampling")),
33  comm(comm),
37  {
38  }
39 
40  std::shared_ptr<SamplingState> Sample(std::shared_ptr<SamplingState> const& currentState) {
41 
42 
43  int remoteRank = phonebookClient->Query(remoteIndex, sourceIndex, true);
44 
45  comm->Send(ControlFlag::SAMPLE, remoteRank, ControlTag);
46  Eigen::VectorXd remoteState = comm->Recv<Eigen::VectorXd>(remoteRank, ControlTag);
47  double remoteLogTarget = comm->Recv<double>(remoteRank, ControlTag);
48  Eigen::VectorXd remoteQOI = comm->Recv<Eigen::VectorXd>(remoteRank, ControlTag);
49 
50  auto proposal = std::make_shared<SamplingState>(remoteState); // TODO: Support non-QOI samples!!
51  proposal->meta["QOI"] = std::make_shared<SamplingState>(remoteQOI);
52  proposal->meta["LogTarget"] = remoteLogTarget;
53 
54  return proposal;
55  }
56 
57  double LogDensity(std::shared_ptr<SamplingState> const& currState,
58  std::shared_ptr<SamplingState> const& propState) {
59  return 0;
60  }
61 
62  private:
63  int sampleID = 0;
64  int sampleWeight = 0;
65  //const int subsampling;
66  std::shared_ptr<parcer::Communicator> comm;
67  std::shared_ptr<MultiIndex> remoteIndex;
68  std::shared_ptr<MultiIndex> sourceIndex;
69  std::shared_ptr<PhonebookClient> phonebookClient;
70  };
71  }
72 }
73 
74 #endif
75 
76 #endif
std::shared_ptr< AbstractSamplingProblem > prob
Definition: MCMCProposal.h:81
Proposal retrieving samples from other ranks.
RemoteMIProposal(pt::ptree const &pt, std::shared_ptr< AbstractSamplingProblem > prob, std::shared_ptr< parcer::Communicator > comm, std::shared_ptr< MultiIndex > remoteIndex, std::shared_ptr< MultiIndex > sourceIndex, std::shared_ptr< PhonebookClient > phonebookClient)
std::shared_ptr< parcer::Communicator > comm
double LogDensity(std::shared_ptr< SamplingState > const &currState, std::shared_ptr< SamplingState > const &propState)
std::shared_ptr< MultiIndex > sourceIndex
std::shared_ptr< MultiIndex > remoteIndex
std::shared_ptr< SamplingState > Sample(std::shared_ptr< SamplingState > const &currentState)
std::shared_ptr< PhonebookClient > phonebookClient
const int ControlTag
Tags separating MPI communication between control level processes and internal work group communicati...
Definition: ParallelFlags.h:15