From 62e09de7ce93ae068e76c8b43f4470ded8573761 Mon Sep 17 00:00:00 2001 From: Logan Drescher <106617880+CodeByDrescher@users.noreply.github.com> Date: Wed, 15 Mar 2023 17:31:00 -0400 Subject: [PATCH 1/8] working on data gen fix for HDF5 --- .../cli/run/hdf5/Hdf5WrapperFactory.java | 41 ++++++++++++++++++- 1 file changed, 39 insertions(+), 2 deletions(-) diff --git a/vcell-cli/src/main/java/org/vcell/cli/run/hdf5/Hdf5WrapperFactory.java b/vcell-cli/src/main/java/org/vcell/cli/run/hdf5/Hdf5WrapperFactory.java index 0c3dfc8144..b0db92b63e 100644 --- a/vcell-cli/src/main/java/org/vcell/cli/run/hdf5/Hdf5WrapperFactory.java +++ b/vcell-cli/src/main/java/org/vcell/cli/run/hdf5/Hdf5WrapperFactory.java @@ -1,7 +1,11 @@ package org.vcell.cli.run.hdf5; import cbit.vcell.solver.Simulation; +import cbit.vcell.parser.DivideByZeroException; +import cbit.vcell.parser.Expression; import cbit.vcell.parser.ExpressionException; +import cbit.vcell.parser.SimpleSymbolTable; +import cbit.vcell.parser.SymbolTable; import cbit.vcell.solver.ode.ODESolverResultSet; import ncsa.hdf.hdf5lib.exceptions.HDF5Exception; @@ -27,6 +31,7 @@ import java.io.*; import java.nio.file.Paths; import java.util.*; +import java.util.stream.Stream; /** @@ -65,6 +70,7 @@ public Hdf5DataWrapper generateHdf5File(Map nonSpat Hdf5DataWrapper hdf5FileWrapper = new Hdf5DataWrapper(); Exception nonSpatialException = null, spatialException = null; + // Nonspacial Collection try { wrappers.addAll(this.collectNonspatialDatasets(this.sedml, nonSpatialResults, this.taskToSimulationMap, this.sedmlLocation)); } catch (Exception e){ @@ -72,6 +78,7 @@ public Hdf5DataWrapper generateHdf5File(Map nonSpat nonSpatialException = e; } + // Spacial Collection try { wrappers.addAll(this.collectSpatialDatasets(this.sedml, spatialResults, this.taskToSimulationMap, this.sedmlLocation)); } catch (Exception e){ @@ -79,6 +86,7 @@ public Hdf5DataWrapper generateHdf5File(Map nonSpat spatialException = e; } + // Error Checking if (nonSpatialException != null && nonSpatialException != null){ throw new RuntimeException("Encountered complete dataset collection failure;\nNonSpatial Reported:\n" + nonSpatialException.getMessage() + "\nSpatial Reported:\n" + spatialException.getMessage()); @@ -102,7 +110,6 @@ private List collectNonspatialDatasets(SedML sedml, Map varIDs = new ArrayList<>(); Map values = new HashMap<>(); - int maxLengthOfAllData = 0; // We have to pad up to this value // use the data reference to obtain the data generator DataGenerator datagen = sedml.getDataGeneratorWithId(dataset.getDataReference()); assert datagen != null; @@ -165,7 +172,6 @@ private List collectNonspatialDatasets(SedML sedml, Map collectNonspatialDatasets(SedML sedml, Map bindingMap; + + public SimpleDataGenCalculator(DataGenerator dataGen, List paramters) throws ExpressionException { + this.equation = new Expression(dataGen.getMathAsString()); + this.bindingMap = new LinkedHashMap<>(); // LinkedHashMap preserves insertion order + + String[] variableArray = paramters.toArray(new String[dataGen.getListOfVariables().size()]); + SymbolTable symTable = new SimpleSymbolTable(variableArray); + this.equation.bindExpression(symTable); + + for (String var : variableArray){ + bindingMap.put(var, Double.NaN); + } + } + + public void setArgument(String parameter, Double argument){ + if (!this.bindingMap.containsKey(parameter)) throw new IllegalArgumentException(String.format("\"%s\" is not a parameter of the expression", parameter)); + this.bindingMap.put(parameter, argument); + } + + public Double evaluateWithCurrentArguments() throws ExpressionException, DivideByZeroException { + Double[] args = this.bindingMap.values().toArray(new Double[0]); + return this.equation.evaluateVector(Stream.of(args).mapToDouble(Double::doubleValue).toArray()); + } + } } From 100633c3e714c181e2b11f65d73afc9f8b41713d Mon Sep 17 00:00:00 2001 From: Logan Drescher <106617880+CodeByDrescher@users.noreply.github.com> Date: Thu, 16 Mar 2023 15:35:32 -0400 Subject: [PATCH 2/8] WIP fix to HDF5 generation --- .../cli/run/hdf5/Hdf5WrapperFactory.java | 62 ++++++++++++++----- 1 file changed, 48 insertions(+), 14 deletions(-) diff --git a/vcell-cli/src/main/java/org/vcell/cli/run/hdf5/Hdf5WrapperFactory.java b/vcell-cli/src/main/java/org/vcell/cli/run/hdf5/Hdf5WrapperFactory.java index b0db92b63e..93dfaf9cd8 100644 --- a/vcell-cli/src/main/java/org/vcell/cli/run/hdf5/Hdf5WrapperFactory.java +++ b/vcell-cli/src/main/java/org/vcell/cli/run/hdf5/Hdf5WrapperFactory.java @@ -104,12 +104,14 @@ private List collectNonspatialDatasets(SedML sedml, Map datasetWrappers = new ArrayList<>(); for (Report report : this.getReports(sedml.getOutputs())){ - Map> dataSetValues = new LinkedHashMap<>(); + //Map> dataSetValues = new LinkedHashMap<>(); + Map dataSetValues = new LinkedHashMap<>(); // go through each entry (dataset) for (DataSet dataset : report.getListOfDataSets()) { - List varIDs = new ArrayList<>(); - Map values = new HashMap<>(); + Map> idToDataMap = new LinkedHashMap<>(); + //List varIDs = new ArrayList<>(); + //List values = new ArrayList<>(); // use the data reference to obtain the data generator DataGenerator datagen = sedml.getDataGeneratorWithId(dataset.getDataReference()); assert datagen != null; @@ -147,7 +149,7 @@ private List collectNonspatialDatasets(SedML sedml, Map collectNonspatialDatasets(SedML sedml, Map variablesList; for (TaskJob taskJob : taskJobs) { ODESolverResultSet results = nonspatialResultsHash.get(taskJob); - int column = results.findColumn(sbmlVarId); - double[] data = results.extractColumn(column); + double[] data = results.extractColumn(results.findColumn(sbmlVarId)); if (outputStartTime > 0){ double[] correctiveData = new double[outputNumberOfPoints + 1]; @@ -172,17 +174,26 @@ private List collectNonspatialDatasets(SedML sedml, Map(); + }*/ + // really ugly convert from double[] to List + variablesList = Arrays.asList(Arrays.stream(data).boxed().toArray(Double[]::new)); + idToDataMap.put(var.getId(), variablesList); } } // Missing functionality!!! We need to computer the variables into the proper values + if (varIDs.isEmpty()) continue; + List data = new LinkedList<>(); + for (int i = 0; i < varIDs.size(); i++) data.add(null); + for (Variable var : values.keySet()){ + if (varIDs.contains(var.getId())) data.set(data.indexOf(var.getId()), values.get(var)); + } + SimpleDataGenCalculator calc = new SimpleDataGenCalculator(datagen, varIDs); + dataSetValues.put(dataset, values); @@ -482,9 +493,32 @@ public void setArgument(String parameter, Double argument){ this.bindingMap.put(parameter, argument); } - public Double evaluateWithCurrentArguments() throws ExpressionException, DivideByZeroException { + public void setArguments(Map parameterToArgumentMap){ + for (String param : parameterToArgumentMap.keySet()){ + this.bindingMap.put(param, parameterToArgumentMap.get(param)); + } + } + + public double evaluateWithCurrentArguments() throws ExpressionException, DivideByZeroException { Double[] args = this.bindingMap.values().toArray(new Double[0]); return this.equation.evaluateVector(Stream.of(args).mapToDouble(Double::doubleValue).toArray()); } + + public double evaluateWithProvidedArguments(Map parameterToArgumentMap) throws ExpressionException, DivideByZeroException { + Double[] dummyArray = new Double[0]; + List args = new LinkedList<>(); + + // Confirm we have the correct params + if (parameterToArgumentMap.size() != this.bindingMap.size()) throw new IllegalArgumentException("Incorrect number of entries."); + if (!parameterToArgumentMap.keySet().equals(this.bindingMap.keySet())) throw new IllegalArgumentException("Parameter 'keys' don't match"); + + // Prepare args + for (String param : this.bindingMap.keySet()){ // binding map, because keys are set-similar but only binding map preserves order for sure! + args.add(parameterToArgumentMap.get(param)); + } + + // Solve + return this.equation.evaluateVector(Stream.of(args.toArray(dummyArray)).mapToDouble(Double::doubleValue).toArray()); + } } } From 0a4ca818923759691eb8e40d1eba9a9a19e95855 Mon Sep 17 00:00:00 2001 From: Logan Drescher <106617880+CodeByDrescher@users.noreply.github.com> Date: Mon, 20 Mar 2023 12:14:53 -0400 Subject: [PATCH 3/8] WIP: more work, Nonspatial HDF5 close to working with 1D, but not nD data --- .../cli/run/hdf5/Hdf5WrapperFactory.java | 42 ++++++++++++------- 1 file changed, 26 insertions(+), 16 deletions(-) diff --git a/vcell-cli/src/main/java/org/vcell/cli/run/hdf5/Hdf5WrapperFactory.java b/vcell-cli/src/main/java/org/vcell/cli/run/hdf5/Hdf5WrapperFactory.java index 93dfaf9cd8..20480c7f6f 100644 --- a/vcell-cli/src/main/java/org/vcell/cli/run/hdf5/Hdf5WrapperFactory.java +++ b/vcell-cli/src/main/java/org/vcell/cli/run/hdf5/Hdf5WrapperFactory.java @@ -160,7 +160,7 @@ private List collectNonspatialDatasets(SedML sedml, Map variablesList; + List formattedData; for (TaskJob taskJob : taskJobs) { ODESolverResultSet results = nonspatialResultsHash.get(taskJob); @@ -180,22 +180,33 @@ private List collectNonspatialDatasets(SedML sedml, Map(); }*/ // really ugly convert from double[] to List - variablesList = Arrays.asList(Arrays.stream(data).boxed().toArray(Double[]::new)); - idToDataMap.put(var.getId(), variablesList); + formattedData = Arrays.asList(Arrays.stream(data).boxed().toArray(Double[]::new)); + idToDataMap.put(var.getId(), formattedData); } } // Missing functionality!!! We need to computer the variables into the proper values - if (varIDs.isEmpty()) continue; - List data = new LinkedList<>(); - for (int i = 0; i < varIDs.size(); i++) data.add(null); - for (Variable var : values.keySet()){ - if (varIDs.contains(var.getId())) data.set(data.indexOf(var.getId()), values.get(var)); - } - SimpleDataGenCalculator calc = new SimpleDataGenCalculator(datagen, varIDs); + if (idToDataMap.isEmpty()) continue; + int maxLengthOfData = 0; + List data = new LinkedList<>(); + + SimpleDataGenCalculator calc = new SimpleDataGenCalculator(datagen); + for (List varData : idToDataMap.values()) + if (varData.size() > maxLengthOfData) + maxLengthOfData = varData.size(); + + + for (int i = 0; i < maxLengthOfData; i++){ + for (String varId : idToDataMap.keySet()){ + List varData = idToDataMap.get(varId); + Double value = i >= varData.size() ? Double.NaN : varData.get(i); + calc.setArgument(varId, value); + } + data.add(calc.evaluateWithCurrentArguments()); + } - dataSetValues.put(dataset, values); + dataSetValues.put(dataset, data.stream().toArray(Double[]::new)); } // end of dataset @@ -475,11 +486,11 @@ private class SimpleDataGenCalculator { private Expression equation; private Map bindingMap; - public SimpleDataGenCalculator(DataGenerator dataGen, List paramters) throws ExpressionException { + public SimpleDataGenCalculator(DataGenerator dataGen) throws ExpressionException { this.equation = new Expression(dataGen.getMathAsString()); this.bindingMap = new LinkedHashMap<>(); // LinkedHashMap preserves insertion order - - String[] variableArray = paramters.toArray(new String[dataGen.getListOfVariables().size()]); + + String[] variableArray = dataGen.getListOfVariables().stream().map(Variable::getId).toArray(String[]::new); SymbolTable symTable = new SimpleSymbolTable(variableArray); this.equation.bindExpression(symTable); @@ -505,7 +516,6 @@ public double evaluateWithCurrentArguments() throws ExpressionException, DivideB } public double evaluateWithProvidedArguments(Map parameterToArgumentMap) throws ExpressionException, DivideByZeroException { - Double[] dummyArray = new Double[0]; List args = new LinkedList<>(); // Confirm we have the correct params @@ -518,7 +528,7 @@ public double evaluateWithProvidedArguments(Map parameterToArgum } // Solve - return this.equation.evaluateVector(Stream.of(args.toArray(dummyArray)).mapToDouble(Double::doubleValue).toArray()); + return this.equation.evaluateVector(args.stream().mapToDouble(Double::doubleValue).toArray()); } } } From 61d3424007265d7298348c47d5409957f3ba77ea Mon Sep 17 00:00:00 2001 From: Logan Drescher <106617880+CodeByDrescher@users.noreply.github.com> Date: Mon, 20 Mar 2023 13:21:11 -0400 Subject: [PATCH 4/8] formatting --- .../org/vcell/cli/run/hdf5/Hdf5WrapperFactory.java | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/vcell-cli/src/main/java/org/vcell/cli/run/hdf5/Hdf5WrapperFactory.java b/vcell-cli/src/main/java/org/vcell/cli/run/hdf5/Hdf5WrapperFactory.java index 20480c7f6f..1806e2bde2 100644 --- a/vcell-cli/src/main/java/org/vcell/cli/run/hdf5/Hdf5WrapperFactory.java +++ b/vcell-cli/src/main/java/org/vcell/cli/run/hdf5/Hdf5WrapperFactory.java @@ -191,12 +191,11 @@ private List collectNonspatialDatasets(SedML sedml, Map data = new LinkedList<>(); SimpleDataGenCalculator calc = new SimpleDataGenCalculator(datagen); + for (List varData : idToDataMap.values()) if (varData.size() > maxLengthOfData) maxLengthOfData = varData.size(); - - for (int i = 0; i < maxLengthOfData; i++){ for (String varId : idToDataMap.keySet()){ List varData = idToDataMap.get(varId); @@ -216,12 +215,8 @@ private List collectNonspatialDatasets(SedML sedml, Map firstValues = dataSetValues.entrySet().iterator().next().getValue(); - if (firstValues.size()==0){ - continue; - } - NonspatialValueHolder valuesForFirstVar = firstValues.entrySet().iterator().next().getValue(); - int numJobs = valuesForFirstVar.getNumJobs(); + Double[] valuesForFirstVar = dataSetValues.entrySet().iterator().next().getValue(); + int numJobs = valuesForFirstVar.length; Hdf5DataSourceNonspatial dataSourceNonspatial = new Hdf5DataSourceNonspatial(); hdf5DatasetWrapper.dataSource = dataSourceNonspatial; // Using upcasting From 8c3f7f1da37ff10c601624947f4746bbb402e4c9 Mon Sep 17 00:00:00 2001 From: Logan Drescher Date: Tue, 21 Mar 2023 14:11:23 -0400 Subject: [PATCH 5/8] WIP work towards flexible data-container for post-dataGen processing storage --- .../vcell/cli/run/hdf5/Hdf5DataPreparer.java | 2 +- .../run/hdf5/Hdf5DataSourceNonspatial.java | 88 +++++++++++++++---- .../cli/run/hdf5/Hdf5WrapperFactory.java | 4 +- .../vcell/cli/run/hdf5/Hdf5WriterTest.java | 10 +-- 4 files changed, 81 insertions(+), 23 deletions(-) diff --git a/vcell-cli/src/main/java/org/vcell/cli/run/hdf5/Hdf5DataPreparer.java b/vcell-cli/src/main/java/org/vcell/cli/run/hdf5/Hdf5DataPreparer.java index 3ac6f5c237..85fc412b26 100644 --- a/vcell-cli/src/main/java/org/vcell/cli/run/hdf5/Hdf5DataPreparer.java +++ b/vcell-cli/src/main/java/org/vcell/cli/run/hdf5/Hdf5DataPreparer.java @@ -136,7 +136,7 @@ public static Hdf5PreparedData prepareNonspacialData(Hdf5DatasetWrapper datasetW double[] bigDataBuffer = new double[totalDataSize]; int bufferOffset = 0; - for (Hdf5DataSourceNonspatial.Hdf5JobData jobData : dataSourceNonspatial.jobData) { + for (Hdf5DataSourceNonspatial.Hdf5DataFragment jobData : dataSourceNonspatial.jobData) { for (int varIndex = 0; varIndex < vars.size(); varIndex++) { Variable var = vars.get(varIndex); double[] dataArray = jobData.varData.get(var); diff --git a/vcell-cli/src/main/java/org/vcell/cli/run/hdf5/Hdf5DataSourceNonspatial.java b/vcell-cli/src/main/java/org/vcell/cli/run/hdf5/Hdf5DataSourceNonspatial.java index 6df7c0c785..e55768bdf5 100644 --- a/vcell-cli/src/main/java/org/vcell/cli/run/hdf5/Hdf5DataSourceNonspatial.java +++ b/vcell-cli/src/main/java/org/vcell/cli/run/hdf5/Hdf5DataSourceNonspatial.java @@ -1,33 +1,91 @@ package org.vcell.cli.run.hdf5; -import org.jlibsedml.Variable; - -import java.util.ArrayList; -import java.util.LinkedHashMap; +import java.util.Iterator; +import java.util.LinkedList; import java.util.List; -import java.util.Map; /** - * Struct-class to hold list of nonspacial variable data + * Class */ -public class Hdf5DataSourceNonspatial extends Hdf5DataSource { - public Hdf5DataSourceNonspatial() {} +public class Hdf5DataSourceNonspatial extends Hdf5DataSource implements Iterable>{ /** * List of all data contained within a job relevant to HDF5 formatted files */ - public List jobData = new ArrayList<>(); + private int numDimensions; + private Hdf5DataFragment jobDataHead, jobDataTail; + + /* + * Creates an empty data source + * + * There are no paramaterized constructors, as they may result in "heap pollution" + */ + public Hdf5DataSourceNonspatial(){ + this.numDimensions = 0; + this.jobDataHead = null; + this.jobDataTail = jobDataHead; + } + + /** + * + * @return + */ + public void add(List data){ + this.jobDataTail.nextDimension = new Hdf5DataFragment(data); + this.numDimensions += 1; + } + + public int getNumberOfDimensions(){ + return this.numDimensions; + } + + /** + * + * @return + */ + public boolean hasNext(){ + return this.jobDataHead == null ? false : true; + } + + @Override + public Iterator> iterator() { + return new DataSourceIterator(this.jobDataHead); + } /** * Struct-Subclass for holding job data */ - public static class Hdf5JobData { - // metadata? parameter values??? or jobIndex?? + private class Hdf5DataFragment { + public Hdf5DataFragment(List data){ + this.varData = data; + } + + public Hdf5DataFragment nextDimension = null; + public List varData = new LinkedList<>(); + } + + private class DataSourceIterator implements Iterator>{ + + private Hdf5DataFragment head; + /** - * Mapping that connects a sedml varaible to its data + * Constructor for the iterator + * @param chainStart */ - public Map varData = new LinkedHashMap<>(); - } + public DataSourceIterator(Hdf5DataFragment chainStart){ + this.head = chainStart; + } - + @Override + public boolean hasNext() { + return head != null && head.nextDimension != null; + } + + @Override + public List next() { + List result = head == null ? null : head.varData; + if (head != null) head = head.nextDimension; + return result; + } + } } diff --git a/vcell-cli/src/main/java/org/vcell/cli/run/hdf5/Hdf5WrapperFactory.java b/vcell-cli/src/main/java/org/vcell/cli/run/hdf5/Hdf5WrapperFactory.java index 1806e2bde2..53903160e2 100644 --- a/vcell-cli/src/main/java/org/vcell/cli/run/hdf5/Hdf5WrapperFactory.java +++ b/vcell-cli/src/main/java/org/vcell/cli/run/hdf5/Hdf5WrapperFactory.java @@ -223,7 +223,7 @@ private List collectNonspatialDatasets(SedML sedml, Map(); for (int i=0; i shapes = new LinkedList<>(); @@ -241,7 +241,7 @@ private List collectNonspatialDatasets(SedML sedml, Map Date: Tue, 21 Mar 2023 16:35:17 -0400 Subject: [PATCH 6/8] WIP push --- .../java/org/vcell/cli/run/hdf5/Hdf5WrapperFactory.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/vcell-cli/src/main/java/org/vcell/cli/run/hdf5/Hdf5WrapperFactory.java b/vcell-cli/src/main/java/org/vcell/cli/run/hdf5/Hdf5WrapperFactory.java index 53903160e2..7f30ae9bab 100644 --- a/vcell-cli/src/main/java/org/vcell/cli/run/hdf5/Hdf5WrapperFactory.java +++ b/vcell-cli/src/main/java/org/vcell/cli/run/hdf5/Hdf5WrapperFactory.java @@ -159,7 +159,6 @@ private List collectNonspatialDatasets(SedML sedml, Map formattedData; for (TaskJob taskJob : taskJobs) { @@ -379,6 +378,11 @@ private List getReports(List outputs){ return reports; } + /** + * Goes though references of repeated tasks, finding the "base" task that isn't repeated. + * @param task the task to check if repeated + * @return the base task (not a repeated task) + */ private AbstractTask getOriginalTask(AbstractTask task){ while (task instanceof RepeatedTask) { // We need to find the original task burried beneath. // We assume that we can never have a sequential repeated task at this point, we check for that in SEDMLImporter From bc54ae41c688fb6ec1ffc825deea9be0a1f152a3 Mon Sep 17 00:00:00 2001 From: Logan Drescher Date: Thu, 23 Mar 2023 09:16:30 -0400 Subject: [PATCH 7/8] WIP working on multidimensional data --- .../main/java/org/vcell/cli/run/hdf5/Hdf5DataSet.java | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 vcell-cli/src/main/java/org/vcell/cli/run/hdf5/Hdf5DataSet.java diff --git a/vcell-cli/src/main/java/org/vcell/cli/run/hdf5/Hdf5DataSet.java b/vcell-cli/src/main/java/org/vcell/cli/run/hdf5/Hdf5DataSet.java new file mode 100644 index 0000000000..10f62df649 --- /dev/null +++ b/vcell-cli/src/main/java/org/vcell/cli/run/hdf5/Hdf5DataSet.java @@ -0,0 +1,9 @@ +package org.vcell.cli.run.hdf5; + +public class Hdf5DataSet { + + + public Hdf5DataSet (){ + + } +} From c79d7fb5565fc077ef3dc3aa6c096843f719d33b Mon Sep 17 00:00:00 2001 From: Logan Drescher Date: Fri, 24 Mar 2023 11:05:48 -0400 Subject: [PATCH 8/8] WIP Undoing changes. Will just open new branch off master and use this for reference. Please close if stale. --- .../vcell/cli/run/hdf5/Hdf5DataPreparer.java | 2 +- .../run/hdf5/Hdf5DataSourceNonspatial.java | 81 +++---------------- .../cli/run/hdf5/Hdf5WrapperFactory.java | 17 ++-- .../vcell/cli/run/hdf5/Hdf5WriterTest.java | 10 +-- 4 files changed, 27 insertions(+), 83 deletions(-) diff --git a/vcell-cli/src/main/java/org/vcell/cli/run/hdf5/Hdf5DataPreparer.java b/vcell-cli/src/main/java/org/vcell/cli/run/hdf5/Hdf5DataPreparer.java index 85fc412b26..3ac6f5c237 100644 --- a/vcell-cli/src/main/java/org/vcell/cli/run/hdf5/Hdf5DataPreparer.java +++ b/vcell-cli/src/main/java/org/vcell/cli/run/hdf5/Hdf5DataPreparer.java @@ -136,7 +136,7 @@ public static Hdf5PreparedData prepareNonspacialData(Hdf5DatasetWrapper datasetW double[] bigDataBuffer = new double[totalDataSize]; int bufferOffset = 0; - for (Hdf5DataSourceNonspatial.Hdf5DataFragment jobData : dataSourceNonspatial.jobData) { + for (Hdf5DataSourceNonspatial.Hdf5JobData jobData : dataSourceNonspatial.jobData) { for (int varIndex = 0; varIndex < vars.size(); varIndex++) { Variable var = vars.get(varIndex); double[] dataArray = jobData.varData.get(var); diff --git a/vcell-cli/src/main/java/org/vcell/cli/run/hdf5/Hdf5DataSourceNonspatial.java b/vcell-cli/src/main/java/org/vcell/cli/run/hdf5/Hdf5DataSourceNonspatial.java index e55768bdf5..ab00b2db08 100644 --- a/vcell-cli/src/main/java/org/vcell/cli/run/hdf5/Hdf5DataSourceNonspatial.java +++ b/vcell-cli/src/main/java/org/vcell/cli/run/hdf5/Hdf5DataSourceNonspatial.java @@ -3,89 +3,30 @@ import java.util.Iterator; import java.util.LinkedList; import java.util.List; +import java.util.Map; +import java.util.LinkedHashMap; + +import org.jlibsedml.Variable; /** * Class */ -public class Hdf5DataSourceNonspatial extends Hdf5DataSource implements Iterable>{ +public class Hdf5DataSourceNonspatial extends Hdf5DataSource { + public Hdf5DataSourceNonspatial() {} /** * List of all data contained within a job relevant to HDF5 formatted files */ - private int numDimensions; - private Hdf5DataFragment jobDataHead, jobDataTail; - - /* - * Creates an empty data source - * - * There are no paramaterized constructors, as they may result in "heap pollution" - */ - public Hdf5DataSourceNonspatial(){ - this.numDimensions = 0; - this.jobDataHead = null; - this.jobDataTail = jobDataHead; - } - - /** - * - * @return - */ - public void add(List data){ - this.jobDataTail.nextDimension = new Hdf5DataFragment(data); - this.numDimensions += 1; - } - - public int getNumberOfDimensions(){ - return this.numDimensions; - } - - /** - * - * @return - */ - public boolean hasNext(){ - return this.jobDataHead == null ? false : true; - } - - @Override - public Iterator> iterator() { - return new DataSourceIterator(this.jobDataHead); - } + public List jobData = new LinkedList<>(); /** * Struct-Subclass for holding job data */ - private class Hdf5DataFragment { - public Hdf5DataFragment(List data){ - this.varData = data; - } - - public Hdf5DataFragment nextDimension = null; - public List varData = new LinkedList<>(); - } - - private class DataSourceIterator implements Iterator>{ - - private Hdf5DataFragment head; - + public static class Hdf5JobData { + // metadata? parameter values??? or jobIndex?? /** - * Constructor for the iterator - * @param chainStart + * Mapping that connects a sedml varaible to its data */ - public DataSourceIterator(Hdf5DataFragment chainStart){ - this.head = chainStart; - } - - @Override - public boolean hasNext() { - return head != null && head.nextDimension != null; - } - - @Override - public List next() { - List result = head == null ? null : head.varData; - if (head != null) head = head.nextDimension; - return result; - } + public Map varData = new LinkedHashMap<>(); } } diff --git a/vcell-cli/src/main/java/org/vcell/cli/run/hdf5/Hdf5WrapperFactory.java b/vcell-cli/src/main/java/org/vcell/cli/run/hdf5/Hdf5WrapperFactory.java index 7f30ae9bab..773024bdd1 100644 --- a/vcell-cli/src/main/java/org/vcell/cli/run/hdf5/Hdf5WrapperFactory.java +++ b/vcell-cli/src/main/java/org/vcell/cli/run/hdf5/Hdf5WrapperFactory.java @@ -104,8 +104,7 @@ private List collectNonspatialDatasets(SedML sedml, Map datasetWrappers = new ArrayList<>(); for (Report report : this.getReports(sedml.getOutputs())){ - //Map> dataSetValues = new LinkedHashMap<>(); - Map dataSetValues = new LinkedHashMap<>(); + Map> dataSetValues = new LinkedHashMap<>(); // go through each entry (dataset) for (DataSet dataset : report.getListOfDataSets()) { @@ -204,7 +203,7 @@ private List collectNonspatialDatasets(SedML sedml, Map collectNonspatialDatasets(SedML sedml, Map firstValues = dataSetValues.entrySet().iterator().next().getValue(); + if (firstValues.size()==0){ + continue; + } + NonspatialValueHolder valuesForFirstVar = firstValues.entrySet().iterator().next().getValue(); + int numJobs = valuesForFirstVar.getNumJobs(); Hdf5DataSourceNonspatial dataSourceNonspatial = new Hdf5DataSourceNonspatial(); hdf5DatasetWrapper.dataSource = dataSourceNonspatial; // Using upcasting hdf5DatasetWrapper.datasetMetadata.sedmlDataSetShapes = new LinkedList<>(); for (int i=0; i shapes = new LinkedList<>(); @@ -240,7 +243,7 @@ private List collectNonspatialDatasets(SedML sedml, Map