Skip to content

Commit

Permalink
checkpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
rbouckaert committed Feb 3, 2020
1 parent dbfd0ca commit de9ddb8
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/beast/coupledMCMC/RemoteCoupledLogger.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import beast.core.util.Log;

@Description("Logger for CoupledMCMC that logs via a RemoteLoggerService")
class RemoteCoupledLogger extends CoupledLogger {
public class RemoteCoupledLogger extends CoupledLogger {
final public Input<String> hostInput = new Input<>("host", "URL of MC3 logger service", Validate.REQUIRED);
final public Input<Integer> portInput = new Input<>("port", "port of MC3 logger service", Validate.REQUIRED);

Expand Down
32 changes: 29 additions & 3 deletions src/beast/coupledMCMC/RemoteCoupledMCMC.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.PrintStream;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.nio.file.Files;
import java.util.ArrayList;
import java.util.List;
Expand All @@ -37,7 +39,7 @@
DOI="10.1093/bioinformatics/btg427")
}
)
@Description("Parallel Metropolis Coupled Markov Chain Monte Carlo")
@Description("Distributed Parallel Metropolis Coupled Markov Chain Monte Carlo")
public class RemoteCoupledMCMC extends MCMC {
public Input<Integer> nrOfChainsInput = new Input<Integer>("chains", " number of chains to run in parallel (default 2)", 2);
public Input<Integer> resampleEveryInput = new Input<Integer>("resampleEvery", "number of samples in between resampling (and possibly swappping) states", 100);
Expand All @@ -58,7 +60,9 @@ public class RemoteCoupledMCMC extends MCMC {


public Input<String> hostsInput = new Input<>("hosts","comma separated list of hosts -- should be equal to number of chains", Validate.REQUIRED);
public Input<String> portsInput = new Input<>("ports","comma separated list of ports on hosts. If fewer ports than hosts are specified, it cycles through the list (so you can specify only 1 port, which is 5000 by default)", "5000");
public Input<String> portsInput = new Input<>("ports","comma separated list of ports on hosts. If fewer ports than hosts are specified, it cycles through the list (so you can specify only 1 port, which is 5001 by default)", "5001");

public Input<Integer> loggerportInput = new Input<>("loggerport", "port where the logger service listens -- should differ from ports", 5000);


// nr of samples between re-arranging states
Expand Down Expand Up @@ -89,6 +93,7 @@ public class RemoteCoupledMCMC extends MCMC {
int successfullSwaps = 0, successfullSwaps0 = 0;

long sampleOffset = 0;
RemoteLoggerServer remoteLoggerServer;

@Override
public void initAndValidate() {
Expand All @@ -109,6 +114,17 @@ public void initAndValidate() {

optimise = optimiseInput.get();

if (logHeatedChainsInput.get()) {
throw new IllegalArgumentException("logHeatedChains should be set to false -- it only works with non-remote CoupledMCMC");
}

try {
remoteLoggerServer = new RemoteLoggerServer(loggerportInput.get());
} catch (IOException e) {
e.printStackTrace();
throw new RuntimeException("Cannot create logger service on port " + loggerportInput.get());
}

// // check how optimisation should be performed
// if (optimiseInput.get()==null) {
// optimise = Optimise.True;
Expand Down Expand Up @@ -138,7 +154,17 @@ private void initRun(){
XMLProducer p = new XMLProducer();
String sXML = p.toXML(this, new ArrayList<>());

String loggerHost = "localhost";
try {
loggerHost = InetAddress.getLocalHost().getHostAddress();
} catch (UnknownHostException e1) {
e1.printStackTrace();
}

// removes coupled MCMC parts of the xml
sXML = sXML.replaceAll("hosts=['\"][^ ]*['\"]", "");
sXML = sXML.replaceAll("ports=['\"][^ ]*['\"]", "");
sXML = sXML.replaceAll("loggerport=['\"][^ ]*['\"]", "");
sXML = sXML.replaceAll("chains=['\"][^ ]*['\"]", "");
sXML = sXML.replaceAll("resampleEvery=['\"][^ ]*['\"]", "");
sXML = sXML.replaceAll("tempDir=['\"][^ ]*['\"]", "");
Expand All @@ -152,7 +178,7 @@ private void initRun(){
sXML = sXML.replaceAll("preSchedule=['\"][^ ]*['\"]", "");
sXML = sXML.replaceAll("target=['\"][^ ]*['\"]", "");
sXML = sXML.replaceAll("spec=\"Logger\"", "");
sXML = sXML.replaceAll("<logger", "<coupledLogger spec=\"beast.coupledMCMC.CoupledLogger\"");
sXML = sXML.replaceAll("<logger", "<coupledLogger spec=\"beast.coupledMCMC.RemoteCoupledLogger\" host=\"" + loggerHost + "\" port=\"" + loggerportInput.get() + "\" ");
sXML = sXML.replaceAll("</logger", "</coupledLogger");

// check if the loggers have a same issue
Expand Down
5 changes: 4 additions & 1 deletion src/beast/coupledMCMC/RemoteHeatedChain.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,10 @@ public RemoteHeatedChain(String xml, String host, int port){

// sends output to the socket
out = new DataOutputStream(socket.getOutputStream());
sin = new DataInputStream(socket.getInputStream());
sin = new DataInputStream(socket.getInputStream());
out.writeUTF(xml);
String response = sin.readUTF();
System.err.println(response);
}
catch(UnknownHostException u)
{
Expand Down
5 changes: 2 additions & 3 deletions src/beast/coupledMCMC/RemoteMC3Server.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

import org.xml.sax.SAXException;

import beast.app.beauti.OperatorListInputEditor;
import beast.app.util.Application;
import beast.core.Description;
import beast.core.Input;
Expand Down Expand Up @@ -43,7 +42,7 @@ public void run() {
server = new ServerSocket(portInput.get());
System.out.println("Server started");

System.out.println("Waiting for a client ...");
System.out.println("Waiting for a client at " + server + " ...");

socket = server.accept();
System.out.println("Client accepted");
Expand Down Expand Up @@ -88,7 +87,7 @@ public void run() {
// mc3.setTemperature(i, getTemperature(i));

// needed to avoid error of putting the working dir twice
String[] splittedFileName = stateFileName.split("/");
// String[] splittedFileName = stateFileName.split("/");

// mc3.setStateFile(
// splittedFileName[splittedFileName.length-1].replace(".state", "." + i + "state"), restoreFromFile);
Expand Down

0 comments on commit de9ddb8

Please sign in to comment.