Skip to content

Commit

Permalink
Merge pull request #139 from DimitriPlotnikov/master
Browse files Browse the repository at this point in the history
Add Dockerfile. Refactor and improve structure.
  • Loading branch information
Plotnikov committed May 3, 2016
2 parents 1119127 + c1382b1 commit c07c57c
Show file tree
Hide file tree
Showing 21 changed files with 149 additions and 84 deletions.
54 changes: 54 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# Pull base image.
FROM ubuntu:16.04

ENV DEBIAN_FRONTEND noninteractive

# Install developer tools, alse add-re
RUN apt-get update
# install basics
RUN apt-get install -y software-properties-common
RUN apt-get install -y git
RUN apt-get install -y wget
RUN apt-get install -y gcc
RUN apt-get install -y python
RUN apt-get install -y python-dev

# install oracle java
RUN add-apt-repository -y ppa:webupd8team/java
RUN apt-get update
RUN echo oracle-java8-installer shared/accepted-oracle-license-v1-1 select true | debconf-set-selections
RUN apt-get install -y oracle-java8-installer

WORKDIR /tmp
RUN wget https://bootstrap.pypa.io/get-pip.py
RUN python get-pip.py
RUN pip install numpy
RUN pip install mpmath
RUN git clone https://github.com/sympy/sympy.git
WORKDIR /tmp/sympy
RUN python setup.py install
WORKDIR /tmp

ENV MAVEN_VERSION 3.3.9
RUN mkdir -p /usr/share/maven
RUN wget http://mirror.softaculous.com/apache/maven/maven-3/$MAVEN_VERSION/binaries/apache-maven-$MAVEN_VERSION-bin.tar.gz
RUN tar -xzf apache-maven-$MAVEN_VERSION-bin.tar.gz -C /usr/share/maven --strip-components=1
RUN ln -s /usr/share/maven/bin/mvn /usr/bin/mvn

# Define commonly used JAVA_HOME variable
ENV JAVA_HOME /usr/lib/jvm/java-8-oracle
ENV MAVEN_HOME /usr/share/maven

# Define working directory.
WORKDIR /data
RUN git clone https://github.com/nest/nestml.git

WORKDIR /data/nestml
RUN mvn install
ENV NESTML 'java -jar /data/nestml/target/nestml.jar'

# Define default command.
ENTRYPOINT ["java", "-jar", "/data/nestml/target/nestml.jar", "/nestml", "--target", "/nestml/result"]

# usage from the commandlien
# docker run -v folderWithModelsOnHost:/nestml nestml_box
4 changes: 2 additions & 2 deletions src/main/java/org/nest/codegeneration/NESTCodeGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import org.nest.codegeneration.converters.GSLReferenceConverter;
import org.nest.codegeneration.converters.NESTReferenceConverter;
import org.nest.codegeneration.helpers.*;
import org.nest.codegeneration.printers.NESTMLFunctionPrinter;
import org.nest.codegeneration.printers.NESTFunctionPrinter;
import org.nest.codegeneration.sympy.ODEProcessor;
import org.nest.nestml._ast.ASTBody;
import org.nest.nestml._ast.ASTNESTMLCompilationUnit;
Expand Down Expand Up @@ -270,7 +270,7 @@ private void setNeuronGenerationParameter(
glex.setGlobalValue("simpleNeuronName", neuron.getName());
glex.setGlobalValue("neuronSymbol", neuron.getSymbol().get());

final NESTMLFunctionPrinter functionPrinter = new NESTMLFunctionPrinter();
final NESTFunctionPrinter functionPrinter = new NESTFunctionPrinter();
final NESTMLDeclarations declarations = new NESTMLDeclarations();
glex.setGlobalValue("declarations", new NESTMLDeclarations() );
glex.setGlobalValue("assignments", new ASTAssignments());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,14 @@ public String printSetterName(final ASTAssignment astAssignment) {
return "set_" + variableName;
}

/**
* Returns the textual representation of the setter invocation
*/
public String printLhsName(final ASTAssignment astAssignment) {
final String variableName = Names.getQualifiedName(astAssignment.getVariableName().getParts());
return variableName + "_tmp";
}

/**
* Returns the textual representation of the setter invocation
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
* @author plotnikov
*/
@SuppressWarnings("unused") // class is used in templates
public class NESTMLFunctionPrinter {
public class NESTFunctionPrinter {

public String printFunctionDeclaration(final ASTFunction astFunction) {
checkArgument(astFunction.getEnclosingScope().isPresent(), "Function: " + astFunction.getName() + " has no scope.");
Expand All @@ -51,11 +51,13 @@ public String printFunctionDeclaration(final ASTFunction astFunction) {
}

final Optional<MethodSymbol> method = NESTMLSymbols.resolveMethod(
scope, astFunction.getName(), parameterNestmlTypes);
scope,
astFunction.getName(),
parameterNestmlTypes);

final StringBuilder declaration = new StringBuilder();
if (method.isPresent()) {
declaration.append("//").append(ASTNodes.printComment(astFunction));
declaration.append("//").append(ASTNodes.printComment(astFunction)).append("\n");
final String returnType = new NESTML2NESTTypeConverter().convert(method.get().getReturnType()).replace(
".", "::");
declaration.append(returnType);
Expand Down Expand Up @@ -96,7 +98,7 @@ public String printFunctionDefinition(final ASTFunction astFunction, final Strin

final StringBuilder declaration = new StringBuilder();
if (method.isPresent()) {
declaration.append("//").append(ASTNodes.printComment(astFunction));
declaration.append("//").append(ASTNodes.printComment(astFunction)).append("\n");
final String returnType = new NESTML2NESTTypeConverter().convert(method.get().getReturnType()).replace(
".", "::");
declaration.append(returnType);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import java.util.List;
import java.util.Optional;

import static org.nest.utils.FileHelper.collectNESTMLModelFilenames;
import static org.nest.utils.FilesHelper.collectNESTMLModelFilenames;

/**
* Interprets the provided configuration by collecting models and executing parsing, context
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/org/nest/frontend/NESTMLFrontend.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import org.apache.commons.cli.*;
import org.nest.codegeneration.NESTCodeGenerator;
import org.nest.nestml._symboltable.NESTMLScopeCreator;
import org.nest.utils.FileHelper;
import org.nest.utils.FilesHelper;

import java.io.*;
import java.nio.file.Files;
Expand Down Expand Up @@ -91,7 +91,7 @@ public CLIConfiguration createCLIConfiguration(String[] args) {
}

public static boolean checkEnvironment(final CLIConfiguration cliConfiguration) {
FileHelper.createFolders(cliConfiguration.getTargetPath());
FilesHelper.createFolders(cliConfiguration.getTargetPath());
cleanUpTmpFiles(cliConfiguration);

boolean isError = false;
Expand Down Expand Up @@ -123,14 +123,14 @@ public static boolean checkEnvironment(final CLIConfiguration cliConfiguration)

private static void cleanUpTmpFiles(final CLIConfiguration cliConfiguration) {
if (!Files.exists(cliConfiguration.getTargetPath())) {
FileHelper.createFolders(cliConfiguration.getTargetPath());
FilesHelper.createFolders(cliConfiguration.getTargetPath());
}
else {
final List<Path> tmps = FileHelper.collectFiles(
final List<Path> tmps = FilesHelper.collectFiles(
cliConfiguration.getTargetPath(),
file -> file.endsWith(".tmp"));

tmps.stream().forEach(FileHelper::deleteFile);
tmps.stream().forEach(FilesHelper::deleteFile);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,23 +23,29 @@
*
* @author plotnikov
*/
public class FileHelper {
private static String LOG_NAME = FileHelper.class.getName();
public class FilesHelper {
private static String LOG_NAME = FilesHelper.class.getName();

public static List<Path> collectNESTMLModelFilenames(final Path path) {
final PathMatcher matcher = getDefault().getPathMatcher("glob:*." + NESTMLLanguage.FILE_ENDING);
return FileHelper.collectFiles(path, modelFile -> matcher.matches(modelFile.getFileName()));
return FilesHelper.collectFiles(path, modelFile -> matcher.matches(modelFile.getFileName()));
}

public static List<Path> collectSPLModelFilenames(final Path path) {
final PathMatcher matcher = getDefault().getPathMatcher("glob:*." + SPLLanguage.FILE_ENDING);
return FileHelper.collectFiles(path, modelFile -> matcher.matches(modelFile.getFileName()));
return FilesHelper.collectFiles(path, modelFile -> matcher.matches(modelFile.getFileName()));
}

public static void deleteFilesInFolder(final Path file) {
FileHelper.collectFiles(file, f -> true)
FilesHelper.collectFiles(file, f -> true)
.stream()
.forEach(FileHelper::deleteFile);
.forEach(FilesHelper::deleteFile);
}

public static void deleteFilesInFolder(final Path file, final Predicate<Path> predicate) {
FilesHelper.collectFiles(file, predicate)
.stream()
.forEach(FilesHelper::deleteFile);
}

public static void deleteFile(final Path file) {
Expand Down
6 changes: 3 additions & 3 deletions src/test/java/org/nest/base/GenerationBasedTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import org.nest.nestml._ast.ASTNESTMLCompilationUnit;
import org.nest.nestml._cocos.NESTMLCoCoChecker;
import org.nest.nestml._symboltable.NESTMLCoCosManager;
import org.nest.utils.FileHelper;
import org.nest.utils.FilesHelper;

import java.io.IOException;
import java.nio.file.Path;
Expand Down Expand Up @@ -40,7 +40,7 @@ public abstract class GenerationBasedTest extends ModelbasedTest {
@Before
public void cleanUpGeneratedFolder() {
Log.enableFailQuick(false);
FileHelper.deleteFilesInFolder(CODE_GEN_OUTPUT);
FilesHelper.deleteFilesInFolder(CODE_GEN_OUTPUT);
}

protected void invokeCodeGenerator(final String pathToModel) {
Expand All @@ -65,7 +65,7 @@ protected void generateNESTModuleCode(final List<ASTNESTMLCompilationUnit> model
generator.generateNESTModuleCode(modelRoots, MODULE_NAME, CODE_GEN_OUTPUT);
}

public void checkCocos(final String pathToModel) {
protected void checkCocos(final String pathToModel) {
final Optional<ASTNESTMLCompilationUnit> root;
try {
root = parser.parse(pathToModel);
Expand Down
38 changes: 17 additions & 21 deletions src/test/java/org/nest/codegeneration/NESTCodeGeneratorTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import org.nest.base.GenerationBasedTest;
import org.nest.mocks.PSCMock;
import org.nest.nestml._ast.ASTNESTMLCompilationUnit;
import org.nest.utils.FilesHelper;

import java.nio.file.Path;
import java.nio.file.Paths;
Expand All @@ -29,47 +30,42 @@ public class NESTCodeGeneratorTest extends GenerationBasedTest {
private static final String PSC_MODEL = "src/test/resources/codegeneration/iaf_psc_alpha.nestml";
//private static final String COND_MODEL_EXPLICIT = "src/test/resources/codegeneration/iaf_cond_alpha.nestml";
private static final String COND_MODEL_IMPLICIT = "src/test/resources/codegeneration/iaf_cond_alpha_implicit.nestml";
private Path outputFolder;

@Test
public void testPSCModelWithoutOde() {
final ASTNESTMLCompilationUnit root = parseNESTMLModel(PSC_MODEL);
scopeCreator.runSymbolTableCreator(root);
final NESTCodeGenerator generator = new NESTCodeGenerator(scopeCreator, pscMock);
generator.analyseAndGenerate(
root,
Paths.get(OUTPUT_DIRECTORY.toString(), "simple_psc"));
generator.generateNESTModuleCode(
newArrayList(root),
"simple_psc",
Paths.get(OUTPUT_DIRECTORY.toString(), "psc"));
outputFolder = Paths.get(OUTPUT_DIRECTORY.toString(), "simple_psc");

FilesHelper.deleteFilesInFolder(outputFolder);
generator.analyseAndGenerate(root, outputFolder);
generator.generateNESTModuleCode(newArrayList(root), "simple_psc", outputFolder);
}

@Test
public void testPSCModelWithOde() {
final ASTNESTMLCompilationUnit root = parseNESTMLModel(PSC_MODEL_WITH_ODE);
scopeCreator.runSymbolTableCreator(root);
final NESTCodeGenerator generator = new NESTCodeGenerator(scopeCreator, pscMock);
generator.analyseAndGenerate(
root,
Paths.get(OUTPUT_DIRECTORY.toString(), "psc"));
generator.generateNESTModuleCode(
newArrayList(root),
"psc",
Paths.get(OUTPUT_DIRECTORY.toString(), "psc"));
Path outputFolder = Paths.get(OUTPUT_DIRECTORY.toString(), "psc");

FilesHelper.deleteFilesInFolder(outputFolder);
generator.analyseAndGenerate(root, outputFolder);
generator.generateNESTModuleCode(newArrayList(root), "psc", outputFolder);
}

@Test
public void testCondModelWithImplicitOdes() {
final ASTNESTMLCompilationUnit root = parseNESTMLModel(COND_MODEL_IMPLICIT);
scopeCreator.runSymbolTableCreator(root);
final NESTCodeGenerator generator = new NESTCodeGenerator(scopeCreator, pscMock);
generator.analyseAndGenerate(
root,
Paths.get(OUTPUT_DIRECTORY.toString(), "cond"));
generator.generateNESTModuleCode(
newArrayList(root),
"cond",
Paths.get(OUTPUT_DIRECTORY.toString(), "cond"));
Path outputFolder = Paths.get(OUTPUT_DIRECTORY.toString(), "cond");

FilesHelper.deleteFilesInFolder(outputFolder);
generator.analyseAndGenerate(root, outputFolder);
generator.generateNESTModuleCode(newArrayList(root), "cond", outputFolder);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
*/
public class ExactSolutionTransformerTest extends ModelbasedTest {

public static final String TARGET_TMP_MODEL_PATH = "target/tmp.nestml";
private static final String TARGET_TMP_MODEL_PATH = "target/tmp.nestml";

private final static String P30_FILE
= "src/test/resources/codegeneration/sympy/psc/" + SymPyScriptEvaluator.P30_FILE;
Expand All @@ -44,7 +44,7 @@ public class ExactSolutionTransformerTest extends ModelbasedTest {
private static final String MODEL_FILE_PATH
= "src/test/resources/codegeneration/iaf_psc_alpha.nestml";

public static final String NEURON_NAME = "iaf_psc_alpha_nestml";
private static final String NEURON_NAME = "iaf_psc_alpha_nestml";

@Test
public void testExactSolutionTransformation() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,9 @@
import org.nest.ode._ast.ASTODE;
import org.nest.symboltable.predefined.PredefinedFunctions;
import org.nest.utils.ASTNodes;
import org.nest.utils.FileHelper;

import java.io.IOException;
import java.io.StringReader;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Optional;
Expand All @@ -42,6 +40,7 @@ public class SympyScriptGeneratorTest extends ModelbasedTest {
= "src/test/resources/codegeneration/iaf_cond_alpha_implicit.nestml";

private static final String OUTPUT_FOLDER = "target";
public static final Path OUTPUT_SCRIPT_DIRECTORY = Paths.get(OUTPUT_FOLDER, "sympy");

@Test
public void generateSymPySolverForPSCModel() throws IOException {
Expand Down Expand Up @@ -87,8 +86,7 @@ private void generateAndCheck(final String pathToModel) throws IOException {
nestmlScopeCreator.runSymbolTableCreator(root.get());

final Optional<Path> generatedScript = generateSympyODEAnalyzer(
root.get().getNeurons().get(0),
Paths.get(OUTPUT_FOLDER, "sympy"));
root.get().getNeurons().get(0), OUTPUT_SCRIPT_DIRECTORY);

assertTrue(generatedScript.isPresent());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import java.nio.file.Paths;
import java.util.List;

import static org.nest.utils.FileHelper.collectNESTMLModelFilenames;
import static org.nest.utils.FilesHelper.collectNESTMLModelFilenames;

/**
* Mocks the codegenerator and tests executor functions.
Expand Down
Loading

0 comments on commit c07c57c

Please sign in to comment.