Skip to content

Commit

Permalink
WIP - refactoring LangevinPostProcessor, simulations results recovery
Browse files Browse the repository at this point in the history
  • Loading branch information
danv61 committed Jan 31, 2025
1 parent 08935a4 commit 14bec87
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 105 deletions.
49 changes: 44 additions & 5 deletions vcell-client/src/main/java/cbit/vcell/client/ClientSimManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import cbit.vcell.client.task.AsynchClientTaskFunction;
import cbit.vcell.client.task.ClientTaskDispatcher;
import cbit.vcell.export.server.ExportServiceImpl;
import cbit.vcell.export.server.ExportSpecs;
import cbit.vcell.field.FieldDataIdentifierSpec;
import cbit.vcell.mapping.SimulationContext;
import cbit.vcell.mapping.SimulationContext.NetworkGenerationRequirements;
Expand Down Expand Up @@ -199,21 +198,61 @@ public void showSimulationResults(OutputContext outputContext, Simulation[] simu
ClientTaskDispatcher.dispatch(getDocumentWindowManager().getComponent(), hashTable, taskArray, false, true, null);
}
/*
* -------------------------------------------------------------------------------------------------
TODO: postProcessLangevinResults
*/
public void postProcessLangevinResults(Simulation sim) {

SimulationOwner simOwner = getSimWorkspace().getSimulationOwner();
Hashtable<String, Object> hashTable = new Hashtable<> ();

Hashtable<String, Object> hashTable = new Hashtable<String, Object>();
hashTable.put(LangevinPostProcessor.FAILURE_KEY, false);
hashTable.put(LangevinPostProcessor.SIMULATION_KEY, sim);
hashTable.put(LangevinPostProcessor.SIMULATION_OWNER, simOwner);
hashTable.put(LangevinPostProcessor.SIMULATION_OWNER_KEY, simOwner);

SolverTaskDescription std = sim.getSolverTaskDescription();
int numTrials = std.getNumTrials();
VCSimulationIdentifier vcSimulationIdentifier = sim.getSimulationInfo().getAuthoritativeVCSimulationIdentifier();
MathOverrides mathOverrides = sim.getMathOverrides();
int sizeOverrides = mathOverrides.getSize();
int scanCount = mathOverrides.getScanCount();
System.out.println(" --- " + sim.getName() + ", numTrials = " + numTrials);
System.out.println(" --- " + sim.getName() + ", jobCount" + sim.getJobCount());
System.out.println(" --- " + sim.getName() + ", sizeOverrides = " + sizeOverrides);
System.out.println(" --- " + sim.getName() + ", scanCount = " + scanCount);

if(sizeOverrides > 0) {
System.out.println("ClientSimManager: parameter overrides not supported yet for SpringSaLaD applications");
hashTable.put(LangevinPostProcessor.FAILURE_KEY, true);
}
if(scanCount != 1) {
System.out.println("ClientSimManager: parameter scans not supported yet for SpringSaLaD applications");
hashTable.put(LangevinPostProcessor.FAILURE_KEY, true);
}
if(numTrials != sim.getJobCount()) {
System.out.println("ClientSimManager: numTrials must be the same as numTrials: " + numTrials + ", " + sim.getJobCount());
hashTable.put(LangevinPostProcessor.FAILURE_KEY, true);
}

ArrayList<AsynchClientTask> taskList = new ArrayList<AsynchClientTask>();
AsynchClientTask postProcessLangevinResultsTask = new AsynchClientTask("PostProcessLangevinResultsTask", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {
public void run(Hashtable<String, Object> hashTable) throws Exception {

Map<Integer, ODEDataManager> odeDataManagerMap = new LinkedHashMap<>();
try {
for (int trialIndex = 0; trialIndex < numTrials; trialIndex++) {
VCSimulationDataIdentifier vcSimulationDataIdentifier = new VCSimulationDataIdentifier(vcSimulationIdentifier, trialIndex);
ODEDataManager dm = (ODEDataManager) getDocumentWindowManager().getRequestManager().getDataManager(null, vcSimulationDataIdentifier, false);
odeDataManagerMap.put(trialIndex, dm);
}
} catch(DataAccessException dae) {
System.out.println("ClientSimManager.postProcessLangevinResults() DataAccessException: " + dae.getMessage());
hashTable.put(LangevinPostProcessor.FAILURE_KEY, true);
}
if(odeDataManagerMap.isEmpty()) {
System.out.println("ClientSimManager: no data");
hashTable.put(LangevinPostProcessor.FAILURE_KEY, true);
}
hashTable.put(LangevinPostProcessor.ODE_SIM_DATA_MAP_KEY, odeDataManagerMap);

LangevinPostProcessor lpp = new LangevinPostProcessor();
lpp.postProcessLangevinResults(hashTable);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -894,8 +894,15 @@ void showSimulationResults(Simulation[] sims, ViewerType viewerType) {

void postProcessLangevinResults(Simulation simulation) {
if(!getSimulationOwner().getMathDescription().isLangevin()) {
return;
throw new RuntimeException("Expecting Langevin math description.");
}
if(simulation.getVersion() == null) {
throw new RuntimeException("Missing Version.");
}
if(simulation.getSimulationInfo() == null) {
throw new RuntimeException("Missing Simulation Info.");
}

if (simulation.getSimulationInfo() != null && getSimulationStatus(simulation).getHasData()) {
getClientSimManager().postProcessLangevinResults(simulation);
}
Expand Down
132 changes: 33 additions & 99 deletions vcell-core/src/main/java/cbit/vcell/simdata/LangevinPostProcessor.java
Original file line number Diff line number Diff line change
@@ -1,142 +1,76 @@
package cbit.vcell.simdata;

import cbit.vcell.export.server.ExportSpecs;
import cbit.vcell.mapping.SimulationContext;
import cbit.vcell.solver.*;
import cbit.vcell.solver.ode.ODESimData;
import org.vcell.util.TokenMangler;
import org.vcell.util.document.SimulationVersion;

import java.util.ArrayList;
import java.io.File;
import java.text.SimpleDateFormat;
import java.util.Hashtable;
import java.util.LinkedHashMap;
import java.util.Map;

public class LangevinPostProcessor {

public static final String FAILURE_KEY = "FAILURE_KEY";
public static final String SIMULATION_KEY = "SIMULATION_KEY";
public static final String SIMULATION_OWNER = "SIMULATION_OWNER";
public static final String SIMULATION_OWNER_KEY = "SIMULATION_OWNER_KEY";
public static final String ODE_SIM_DATA_MAP_KEY = "ODE_SIM_DATA_MAP_KEY";

boolean failure;
Simulation sim;
SimulationOwner simOwner;
Map<Integer, ODESimData> odeSimDataMap;

public void postProcessLangevinResults(Hashtable<String, Object> hashTable) {

failure = (boolean) hashTable.get(FAILURE_KEY);
sim = (Simulation)hashTable.get(SIMULATION_KEY);
simOwner = (SimulationOwner)hashTable.get(SIMULATION_OWNER);;
simOwner = (SimulationOwner)hashTable.get(SIMULATION_OWNER_KEY);
odeSimDataMap = (Map<Integer, ODESimData>)hashTable.get(ODE_SIM_DATA_MAP_KEY);

if(sim.getVersion() == null) {
throw new RuntimeException("Missing Version.");
}
if(sim.getSimulationInfo() == null) {
throw new RuntimeException("Missing Simulation Info.");
if(failure) {
return;
}

retrieveLangevinResultsTask();
calculateLangevinAveragesTask();
calculateLangevinAdvancedStatisticsTask();
}

private void retrieveLangevinResultsTask() {
private void calculateLangevinAveragesTask() {
SolverTaskDescription std = sim.getSolverTaskDescription();
int numTrials = std.getNumTrials();
VCSimulationIdentifier vcSimulationIdentifier = sim.getSimulationInfo().getAuthoritativeVCSimulationIdentifier();
MathOverrides mathOverrides = sim.getMathOverrides();
int sizeOverrides = mathOverrides.getSize();
int scanCount = mathOverrides.getScanCount();

System.out.println(" --- " + sim.getName() + ", numTrials = " + numTrials);
System.out.println(" --- " + sim.getName() + ", jobCount" + sim.getJobCount());
System.out.println(" --- " + sim.getName() + ", sizeOverrides = " + sizeOverrides);
System.out.println(" --- " + sim.getName() + ", scanCount = " + scanCount);

SimulationInfo simInfo = sim.getSimulationInfo();
VCSimulationIdentifier asi = simInfo.getAuthoritativeVCSimulationIdentifier();
VCSimulationDataIdentifier vcSimulationDataIdentifier = new VCSimulationDataIdentifier(asi, 0);

// ODEDataManager dm = (ODEDataManager)getDocumentWindowManager().getRequestManager().getDataManager(null, vcSimulationDataIdentifier, false);
// ODESimData osd = (ODESimData)dm.getODESolverResultSet();
VCSimulationIdentifier vcSimulationIdentifier = simInfo.getAuthoritativeVCSimulationIdentifier();
MathOverrides mathOverrides = sim.getMathOverrides();
SimulationVersion simVersion = simInfo.getSimulationVersion();

// TODO: go through time series and compute averages, erc

System.out.println(" ------------------------------------");

}
private void calculateLangevinAveragesTask() {

}
private void calculateLangevinAdvancedStatisticsTask() {

}

// public void postProcessLangevinResults(Simulation sim) {
//
// final String FAILURE_KEY = "FAILURE_KEY";
// final String SIMULATION_KEY = "SIMULATION_KEY";
// Hashtable<String, Object> hashTable = new Hashtable<String, Object>();
// hashTable.put(FAILURE_KEY, false);
// hashTable.put(SIMULATION_KEY, sim);
//
// ArrayList<AsynchClientTask> taskList = new ArrayList<AsynchClientTask>();
// AsynchClientTask retrieveLangevinResultsTask = new AsynchClientTask("Retrieving results", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {
// public void run(Hashtable<String, Object> hashTable) throws Exception {
// boolean failure = (boolean) hashTable.get(FAILURE_KEY);
// SolverTaskDescription std = sim.getSolverTaskDescription();
// int numTrials = std.getNumTrials();
// System.out.println(sim.getName() + ", numTrials = " + numTrials);
//// LangevinSimulationOptions lso = std.getLangevinSimulationOptions();
// final VCSimulationIdentifier vcSimulationIdentifier = sim.getSimulationInfo().getAuthoritativeVCSimulationIdentifier();
// SimulationOwner simOwner = getSimWorkspace().getSimulationOwner();
// Simulation allSims[] = simOwner.getSimulations();
// for (Simulation simCandidate : allSims) {
// if (simCandidate.getName().startsWith(sim.getName())) {
// System.out.println(" --- " + simCandidate.getName() + ", jobCount" + simCandidate.getJobCount());
// MathOverrides mathOverrides = simCandidate.getMathOverrides();
// int sizeOverrides = mathOverrides.getSize();
// int scanCount = mathOverrides.getScanCount();
// System.out.println(" --- " + sim.getName() + ", sizeOverrides = " + sizeOverrides);
// System.out.println(" --- " + sim.getName() + ", scanCount = " + scanCount);
//
// ExportSpecs.ExportParamScanInfo es = ExportSpecs.getParamScanInfo(simCandidate,0);
// ExportSpecs.ExportParamScanInfo es1 = ExportSpecs.getParamScanInfo(simCandidate,1);
// ExportSpecs.ExportParamScanInfo es2 = ExportSpecs.getParamScanInfo(simCandidate,2);
//
// if(sim.getVersion() == null) {
// throw new RuntimeException("Missing Version.");
// }
// SimulationInfo simInfo = sim.getSimulationInfo();
// if(simInfo == null) {
// throw new RuntimeException("Missing Simulation Info.");
// }
//
// VCSimulationIdentifier asi = simInfo.getAuthoritativeVCSimulationIdentifier();
// VCSimulationDataIdentifier vcSimulationDataIdentifier = new VCSimulationDataIdentifier(asi, 0);
//
// ODEDataManager dm = (ODEDataManager)getDocumentWindowManager().getRequestManager().getDataManager(outputContext, vcSimulationDataIdentifier, false);
// ODESimData osd = (ODESimData)dm.getODESolverResultSet();
//
//
// System.out.println(" ------------------------------------");
// }
// }
// }
// };
// AsynchClientTask calculateLangevinAveragesTask = new AsynchClientTask("Retrieving results", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {
// public void run(Hashtable<String, Object> hashTable) throws Exception {
// boolean failure = (boolean)hashTable.get(FAILURE_KEY);
//
// }
// };
// AsynchClientTask calculateLangevinAdvancedStatisticsTask = new AsynchClientTask("Retrieving results", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {
// public void run(Hashtable<String, Object> hashTable) throws Exception {
// boolean failure = (boolean)hashTable.get(FAILURE_KEY);
//
// }
// };
// taskList.add(retrieveLangevinResultsTask);
// taskList.add(calculateLangevinAveragesTask);
// taskList.add(calculateLangevinAdvancedStatisticsTask);
// AsynchClientTask[] taskArray = new AsynchClientTask[taskList.size()];
// taskList.toArray(taskArray);
// ClientTaskDispatcher.dispatch(getDocumentWindowManager().getComponent(), hashTable, taskArray, false, true, null);
//
// private static final SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy_MM_dd_HHmmss");
// private static File createDirFile(SimulationContext simulationContext){
// String userid = simulationContext.getBioModel().getVersion().getOwner().getName();
// String simContextDirName =
// TokenMangler.fixTokenStrict(userid)+"-"+
// TokenMangler.fixTokenStrict(simulationContext.getBioModel().getName())+"-"+
// TokenMangler.fixTokenStrict(simulationContext.getName())+"-"+
// TokenMangler.fixTokenStrict(simpleDateFormat.format(simulationContext.getBioModel().getVersion().getDate()));
//// simContextDirName = TokenMangler.fixTokenStrict(simContextDirName);
// File dirFile = new File("C:\\temp\\ruleBasedTestDir\\"+simContextDirName);
// if(!dirFile.exists()){
// dirFile.mkdirs();
// }
// return dirFile;
// }

}

0 comments on commit 14bec87

Please sign in to comment.