Coder Social home page Coder Social logo

simkernel's Introduction

SimKernel

SimKernel controls parameter scans and iterations for any given C++ code / scientific simulation. Parameters, iteration ranges, settings and dependencies are all specified in Mathematica syntax.

Features:

  • Powerful control for parameter scans of scientific software
  • Works with any C++ program in minutes
  • Mathematica syntax input & manipulation of parameter lists
  • MPI parallel version
  • Nested iterations - exploit symmetries in parameter space
  • Handles any parameter dependencies during iteration
  • Function / module definitions possible in input file
  • Soon to come: result dependent parameter selection

Tutorial

This Tutorial will walk you through adding SimKernel functionality to a simple program.

Say you have program like this:

#include <stdio>

using namespace std;

int main(void) {
  cout <<"Hello world!"<<endl;
  
  return 0;
}

The output is, of course: Hello world!

But now you decide that you need a more flexible version of this program, so you wrap it as a SimKernel class like this:

#include "../sim_main.h"

class Kernel;

int main(int argc, char* argv[])
{
  SimControl<Kernel> simc;
  simc.simulate(argc, argv);
  return 0;
};

class Kernel
{
public:
  void initialize(Sim& sim) {};
  
  void execute(Sim& sim) {
    sim.io <<"Hello World!"<<Endl;
  };
  
  void finalize(Sim& sim) {};
};

Note that this file is included in the repository as tutorial/hello_world_sim.cpp, which you can build by calling make tutorial_sim. When executing, it requires a control file as parameter, but for now, any empty file will do. To run the program, type ./tutorial_sim tutorial/empty_control_file.txt.

The output is, slightly more verbose than our original version:

Sim: Starting Simulation iteration: 1/1
Sim: It 1: Hello World!
Sim: Simulation iteration: 1/1 done!
Sim: Simulation done!
Sim: 
Sim: Error Summary:
Sim: No errors!
Sim: Bye!

Now say that we want to call this with different names as parameters, and would also allow for external control of the greeting, maybe because we want to use different languages later. To do this, we simply add the strings greeting and name as a variable to our SimKernel object and have SimKernel read it in during initialization, like this:

class Kernel
{
public:
  string greeting, name;
  void initialize(Sim& sim) {
    sim.get("greeting",greeting,"Hello");
    sim.get("name",name);
  };
  
  void execute(Sim& sim) {
    sim.io <<greeting<<" "<<name<<"!"<<Endl;
  };
  
  void finalize(Sim& sim) {};
};

This file is available at tutorial/hello_world_sim_iterated.cpp, and after you have compiled it by typing make tutorial_sim_iterated.

Note: The third parameter of sim.get, where we supply default values in case a variable is not listed in the respective control file. If we do not supply a default value and the variable is not found in the control file, the program will exit with an error message.

Then, we add a control file that list several names, and define an iterator. Each value of this iterator corresponds to an iteration of our main SimKernel program. For each iteration, greeting and name are read in from the control file.

greeting = "Hello";

people = {"Alice", "Bob", "Peter"};

whichone = Iterator[j,{j,0,Length[people]-1,1}];
name = people[[whichone]];

That's it! Now if we run ./tutorial_sim_iterated tutorial/control_file.txt, we get the following result:

Sim: Starting Simulation iteration: 1/3
Sim: It 1: Hello Alice!
Sim: Simulation iteration: 1/3 done!
Sim: Starting Simulation iteration: 2/3
Sim: It 2: Hello Bob!
Sim: Simulation iteration: 2/3 done!
Sim: Starting Simulation iteration: 3/3
Sim: It 3: Hello Peter!
Sim: Simulation iteration: 3/3 done!
Sim: Simulation done!
Sim: 
Sim: Error Summary:
Sim: No errors!
Sim: Bye!

We believe you can see where this is going. Just paste the code you originally had into the execute method. Then use the method intialize to load parameters from the control file, and use finalize to save results or to deallocate memory.

If you have ever worked with simulations or any other program that has lots of parameters, you might see how this can save a lot of time because all you need to do to understand or repeat later what you have been doing is to keep track of your control files.

If you have any questions, feature requests or bug reports, feel free to use the Issues tab above.

simkernel's People

Contributors

dherkova avatar olavolav avatar orlandi avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

simkernel's Issues

Sim::get does not work with "unsigned long" values

(Feature request copied from SoureceForge repository)

long is okay, unsigned int is okay, but unsigned int is no good for the linker. blow is an example:

g++ -c -O3 -g te-global.cpp -o maketemp/te-global.o
../../../Sonstiges/SimKernel/expression_basic.h: In function ‘void ExprToValue(const ExprPtrT&, T&) [with T = long unsigned int]’:
../../../Sonstiges/SimKernel/sim.hpp:22: instantiated from ‘bool Sim::get(const ExprNameT&, T&, const SimSignal&) [with T = long unsigned int]’
te-global.cpp:124: instantiated from here
../../../Sonstiges/SimKernel/expression_basic.h:2503: error: conversion from ‘Expression’ to ‘long unsigned int’ is ambiguous
../../../Sonstiges/SimKernel/expression.h:210: note: candidates are: virtual Expression::operator bool() const
../../../Sonstiges/SimKernel/expression.h:208: note: virtual Expression::operator int() const
../../../Sonstiges/SimKernel/expression.h:207: note: virtual Expression::operator double() const
make: *** [maketemp/te-global.o] Error 1

Compiler error on OSX Mavericks

As discussed here, there seems to be a problem when installing SimKernel on OSX Mavericks.

Since it seems to be a SimKernel problem, I have closed the issue there, and let's continue the discussion here.

Javier have you tried the latest (library-style) version of SimKernel from Christoph's repository? (my changes have recently been merged)

edit: See specifically the error message here.

Compilation error

Dear all,

i am trying to use SimKernel in combination with the transferentropy computation from OlavOlav. During compilation by using make, I am runing into the following error:

src/sim.cpp:304:2: fatal error: opening dependency file mpi/sim.d: No such file or directory

and compilation gets terminated.

I have this issue on mac 10.10.3 and on a Ubuntu 14.04.
I have no clue why this happens, and i am not so advanced with unix operation system. Would be perfect if you could suport me.

Inline private function breaks exe make target build

Here's the compiler output:

g++ -I./include -O3 -MD obj/sim.o obj/sim_io.o obj/sim_signals.o obj/sim_io_manager.o obj/expression.o obj/expression_basic.o obj/expression_sim.o obj/expression_extra.o obj/expression_parser.o test/main.o -o test/test -lgsl -lgslcblas -L. -lrt
test/main.o: In function bool Sim::get<double>(std::string const&, double&, SimSignal const&)': main.cpp:(.text._ZN3Sim3getIdEEbRKSsRT_RK9SimSignal[_ZN3Sim3getIdEEbRKSsRT_RK9SimSignal]+0x3b): undefined reference toSim::get_expr_nothrow(std::string const&, ExpressionPtr&, SimSignal const&, bool&)'
collect2: error: ld returned 1 exit status
Makefile:58: recipe for target 'exe' failed
make: *** [exe] Error 1

Specifically, if in file src/sim.cpp the inline attribute of

bool Sim::get_expr_nothrow(const ExprNameT& n, ExprPtrT& e, const SimSignal& sig, bool& eo)

is removed, the build completes without errors.
Is it possible that it's similar to this http://stackoverflow.com/questions/4769479/c-inlining-class-methods-causes-undefined-reference ?

I'm on Arch linux using gcc 4.9.1

compiling issue

I met the following two errors when I tried to build and install the package by typing "make"
Error 1: src/sim.cpp:192:76: error: no match for ‘operator<<’ (operand types are ‘std::basic_ostream’ and ‘std::stringstream’ {aka ‘std::__cxx11::basic_stringstream’})
192 | str << "Sim: process = " << process() << " iteration = " << iteration() <<
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ^~
Error 2: /usr/include/c++/9/ostream:691:5: error: no type named ‘type’ in ‘struct std::enable_if<false, std::basic_ostream&>’
make: *** [Makefile:83: obj/sim.o] Error 1
Any help?
Thanks

compiling the tutorial

Hello again,

I hope I am annoying you not to much, with all the questions. I tried to run one of the tutorial skips by using

make tutorial_sim_iterated

the first error I received was that he could not include "../sim_main.h". Therefore I changed the hello_world_sim_iterated.cpp line 2

#include <sim_main.h>

and include the following paths into ~/.profile

export PATH="/usr/local/include/sim:$PATH"
export PATH="/usr/local/libc:$PATH"
export PATH="/usr/local/lib/libsim:$PATH"

Now I run into the following:

Undefined symbols for architecture x86_64:
  "toExprString(char const*)", referenced from:
      bool Sim::get<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, char [6]>(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::basic_string<char, std::char_traits<char>, std::allocator<char> >&, char const (&) [6], SimSignal const&) in ccBhzTjU.o
  "Endl(SimIO&)", referenced from:
      SimControl<Kernel>::simulate(int, char**) in ccBhzTjU.o
  "ExprParser::parse_file(char const*, std::basic_string<char, std::char_traits<char>, std::allocator<char> >&)", referenced from:
      SimControl<Kernel>::simulate(int, char**) in ccBhzTjU.o

..... two more pages of complains

     std::basic_string<char, std::char_traits<char>, std::allocator<char> > ExprToValueErrorDescription<std::basic_string<char, std::char_traits<char>, std::allocator<char> > >(ExpressionPtr const&) in ccBhzTjU.o
ld: symbol(s) not found for architecture x86_64
collect2: error: ld returned 1 exit status
make: *** [tutorial_sim_iterated] Error 1

Do you know what I am doing wrong? If i remember right, that this is also the problem when i am running the te_causality_master from olavolav. Did i forget to add some paths?

Bye the way the ./test inputworks like a charm

Thanks again for all your help.

Dirk

Header files

It would be great to have some preprocessing in SimKernel control files. For instance, one could have a file for the general options and then a number of more specific control files (that only include the necessary bits which are not in the general one) that reference the general control file.

(Request copied from the SourceForge repository)

Abort when loading parameter without default value

I haven't checked when this was introduced, but the Kernel does not exit anymore in such a case. Instead for an undefined variable var, it prints:

Sim: It 1: Warning: Cannot get value for var! Not Defined!

I do believe that I have seen the value of such variables being not set at all, completely undefined, but testing it just now I couldn't confirm that (var was set to zero).

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.