From 7c71305865364216fd1a00b4a2498da44f0cbb0b Mon Sep 17 00:00:00 2001 From: Dilawar Singh <dilawars@ncbs.res.in> Date: Thu, 2 Feb 2017 11:47:21 +0530 Subject: [PATCH] Squashed 'moose-core/' changes from 14e2d78..f3d0477 f3d0477 Merge branch 'master' of https://github.com/BhallaLab/moose-core 176a5f0 solver's short form should also be taken 8624e24 Merge branch 'master' of https://github.com/BhallaLab/moose-core 6c964b1 Added isBuffered field to Pool to let users convert the object class to BufPool, and vice versa. 97db69e moose::Neuron uses global RNG object. Global RNG object behaviour is following. - moose.seed(0) or moose.seed( ) assign a random value to seed. Use random_device if avaible else time(NULL) is used. - moose.seed( x) set moose.seed to x. c1dec94 Fixed long argument for mtseed in moosemodule.cpp 54c94f7 Modified travis scripts and reenabled developers to the list. 31dd779 Fixed import error with python3. No module should be imported in python/moose/__init__.py . Added a note for developers. This should fix the travis. git-subtree-dir: moose-core git-subtree-split: f3d0477a3ea5045db044aaae94b46a133527dbc7 --- .travis.yml | 4 +- .travis/travis_build_linux.sh | 4 +- VERSION | 2 +- biophysics/Neuron.cpp | 13 +++--- kinetics/Pool.cpp | 41 ++++++++++++++++++- kinetics/Pool.h | 7 ++++ pymoose/moosemodule.cpp | 2 +- python/moose/__init__.py | 5 +-- .../chemUtil/add_Delete_ChemicalSolver.py | 6 +-- randnum/RNG.h | 26 +++++++++--- 10 files changed, 85 insertions(+), 25 deletions(-) diff --git a/.travis.yml b/.travis.yml index a88c1f75..7a134ba7 100644 --- a/.travis.yml +++ b/.travis.yml @@ -10,6 +10,8 @@ os: notifications: email: recipients: + - bhalla@ncbs.res.in + - hrani@ncbs.res.in - dilawar.s.rajput@gmail.com on_success: change on_failure: always @@ -30,6 +32,6 @@ before_script : script: - # checking if any python3 incompatible file is in the source tree. - python2 -m compileall -q . - - if type python3 -c 'import sys' > /dev/null; then python3 -m compileall -q . ; fi + - if type python3 > /dev/null; then python3 -m compileall -q . ; fi - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then ./.travis/travis_build_osx.sh; fi - if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then ./.travis/travis_build_linux.sh; fi diff --git a/.travis/travis_build_linux.sh b/.travis/travis_build_linux.sh index cf339969..b993e109 100755 --- a/.travis/travis_build_linux.sh +++ b/.travis/travis_build_linux.sh @@ -30,8 +30,8 @@ PYTHON3="/usr/bin/python3" ( # Old makefile based flow. - python2 -m compileall -q . - if type $PYTHON3 > /dev/null; then python3 -m compileall -q . ; fi + $PYTHON2 -m compileall -q . + if type $PYTHON3 > /dev/null; then $PYTHON3 -m compileall -q . ; fi # Traditional make. make ## CMAKE based flow diff --git a/VERSION b/VERSION index a7ea0627..ffbc5f42 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -3.1.1-73-g3ebc0a5 \ No newline at end of file +3.1.1-79-gc1dec94 \ No newline at end of file diff --git a/biophysics/Neuron.cpp b/biophysics/Neuron.cpp index 002952ac..cf305336 100644 --- a/biophysics/Neuron.cpp +++ b/biophysics/Neuron.cpp @@ -14,11 +14,10 @@ #include "shell/Wildcard.h" #include "ReadCell.h" #include "utility/Vec.h" -#include "randnum/Normal.h" -#include "randnum/randnum.h" #include "SwcSegment.h" #include "Spine.h" #include "Neuron.h" +#include "basecode/global.h" #include "muParser.h" @@ -1737,7 +1736,7 @@ static void addPos( unsigned int segIndex, unsigned int eIndex, unsigned int n = 1 + dendLength / minSpacing; double dx = dendLength / n; for( unsigned int i = 0; i < n; ++i ) { - if ( mtrand() < dx / spacing ) { + if ( moose::mtrand() < dx / spacing ) { seglistIndex.push_back( segIndex ); elistIndex.push_back( eIndex ); pos.push_back( i * dx + dx*0.5 ); @@ -1758,12 +1757,12 @@ static void addPos( unsigned int segIndex, unsigned int eIndex, { if ( spacingDistrib > 0.0 ) { double position = spacing * 0.5 + - ( mtrand() - 0.5 ) * spacingDistrib; + ( moose::mtrand() - 0.5 ) * spacingDistrib; while ( position < dendLength ) { seglistIndex.push_back( segIndex ); elistIndex.push_back( eIndex ); pos.push_back( position ); - position += spacing + ( mtrand() - 0.5 ) * spacingDistrib; + position += spacing + ( moose::mtrand() - 0.5 ) * spacingDistrib; } } else { for ( double position = spacing * 0.5; @@ -1846,7 +1845,7 @@ static void makeAngleDistrib ( const vector< ObjId >& elist, angleDistrib = distribParser.eval( val.begin() + j); } if ( angleDistrib > 0 ) - theta[k] = angle + ( mtrand() - 0.5 ) * angleDistrib; + theta[k] = angle + ( moose::mtrand() - 0.5 ) * angleDistrib; else theta[k] = angle; } @@ -1883,7 +1882,7 @@ static void makeSizeDistrib ( const vector< ObjId >& elist, sizeDistrib = distribParser.eval( val.begin() + j); } if ( sizeDistrib > 0 ) - size[k] = sz + ( mtrand() - 0.5 ) * sizeDistrib; + size[k] = sz + ( moose::mtrand() - 0.5 ) * sizeDistrib; else size[k] = sz; } diff --git a/kinetics/Pool.cpp b/kinetics/Pool.cpp index 691daf29..8b8b6561 100644 --- a/kinetics/Pool.cpp +++ b/kinetics/Pool.cpp @@ -8,6 +8,7 @@ **********************************************************************/ #include "header.h" +#include "ElementValueFinfo.h" #include "lookupVolumeFromMesh.h" #include "PoolBase.h" #include "Pool.h" @@ -19,6 +20,16 @@ const Cinfo* Pool::initCinfo() ////////////////////////////////////////////////////////////// // Field Definitions: All inherited from PoolBase. ////////////////////////////////////////////////////////////// + static ElementValueFinfo< Pool, bool > isBuffered( + "isBuffered", + "Flag: True if Pool is buffered. This field changes the " + "type of the Pool object to BufPool, or vice versa. " + "None of the messages are affected. " + "This object class flip can only be done in the non-zombified " + "form of the Pool.", + &Pool::setIsBuffered, + &Pool::getIsBuffered + ); ////////////////////////////////////////////////////////////// // MsgDest Definitions: All but increment and decrement inherited @@ -45,9 +56,10 @@ const Cinfo* Pool::initCinfo() // SharedMsg Definitions: All inherited. ////////////////////////////////////////////////////////////// static Finfo* poolFinfos[] = { + &isBuffered, // ElementValueFinfo &increment, // DestFinfo &decrement, // DestFinfo - &nIn, + &nIn, // DestFinfo }; static Dinfo< Pool > dinfo; @@ -78,6 +90,33 @@ Pool::Pool() Pool::~Pool() {;} +////////////////////////////////////////////////////////////// +// Field Definitions +/** + * setIsBuffered is a really nasty operation, made possible only because + * BufPool is derived from Pool and has no other fields. + * It uses a low-level replaceCinfo call to just change the + * identity of the Cinfo used, leaving everything else as is. + */ +void Pool::setIsBuffered( const Eref& e, bool v ) +{ + static const Cinfo* bufPoolCinfo = Cinfo::find( "BufPool" ); + if (getIsBuffered( e ) == v) + return; + if (v) { + e.element()->replaceCinfo( bufPoolCinfo ); + } else { + e.element()->replaceCinfo( poolCinfo ); + } +} + +bool Pool::getIsBuffered( const Eref& e ) const +{ + return e.element()->cinfo()->name() == "BufPool"; +} + +////////////////////////////////////////////////////////////// +// ////////////////////////////////////////////////////////////// // MsgDest Definitions ////////////////////////////////////////////////////////////// diff --git a/kinetics/Pool.h b/kinetics/Pool.h index dc45e189..dec4dfa4 100644 --- a/kinetics/Pool.h +++ b/kinetics/Pool.h @@ -53,6 +53,13 @@ class Pool: public PoolBase void vSetSpecies( const Eref& e, SpeciesId v ); SpeciesId vGetSpecies( const Eref& e ) const; + + /** + * Functions to examine and change class between Pool and BufPool. + */ + void setIsBuffered( const Eref& e, bool v ); + bool getIsBuffered( const Eref& e ) const; + ////////////////////////////////////////////////////////////////// // Dest funcs. These too override virtual funcs in the Pool base // class. diff --git a/pymoose/moosemodule.cpp b/pymoose/moosemodule.cpp index 62a9ea2e..1ac1d91f 100644 --- a/pymoose/moosemodule.cpp +++ b/pymoose/moosemodule.cpp @@ -125,7 +125,7 @@ extern void mooseBenchmarks( unsigned int option ); * themselves. If seed is not set by user, it uses std::random_device to * initialize itself. *-----------------------------------------------------------------------------*/ -void pymoose_mtseed_( unsigned int seed ) +void pymoose_mtseed_( long int seed ) { moose::mtseed( seed ); } diff --git a/python/moose/__init__.py b/python/moose/__init__.py index a1a77c0e..2e2f6772 100644 --- a/python/moose/__init__.py +++ b/python/moose/__init__.py @@ -26,8 +26,7 @@ from .moose import * # Wrapper to get moose version information. __version__ = moose._moose.__version__ + VERSION = moose._moose.VERSION -import chemUtil.add_Delete_ChemicalSolver -import chemUtil.chemConnectUtil -import chemUtil.graphUtils \ No newline at end of file +# NOTE: No module should be imported here. Use moose.py to write imports. diff --git a/python/moose/chemUtil/add_Delete_ChemicalSolver.py b/python/moose/chemUtil/add_Delete_ChemicalSolver.py index 6d5886f1..af9437b9 100644 --- a/python/moose/chemUtil/add_Delete_ChemicalSolver.py +++ b/python/moose/chemUtil/add_Delete_ChemicalSolver.py @@ -24,11 +24,11 @@ def mooseaddChemSolver(modelRoot, solver): comptinfo = moose.Annotator(moose.element(compt[0]).path + '/info') previousSolver = comptinfo.solver currentSolver = previousSolver - if solver == "Gillespie": + if solver == "Gillespie" or solver == "gssa": currentSolver = "gssa" - elif solver == "Runge Kutta": + elif solver == "Runge Kutta" or solver == "gsl": currentSolver = "gsl" - elif solver == "Exponential Euler": + elif solver == "Exponential Euler" or solver == "ee": currentSolver = "ee" if previousSolver != currentSolver: diff --git a/randnum/RNG.h b/randnum/RNG.h index 09dbdf05..8fe38b64 100644 --- a/randnum/RNG.h +++ b/randnum/RNG.h @@ -57,6 +57,14 @@ class RNG RNG () /* constructor */ { // Setup a random seed if possible. + setRandomSeed( ); + } + + ~RNG () /* destructor */ + { ; } + + void setRandomSeed( ) + { #if defined(USE_BOOST) #if defined(BOOST_RANDOM_DEVICE_EXISTS) boost::random::random_device rd; @@ -68,12 +76,6 @@ class RNG #else mtseed( time(NULL) ); #endif /* ----- not ENABLE_CPP11 ----- */ - - } - - ~RNG () /* destructor */ - { - } /* ==================== ACCESSORS ======================================= */ @@ -83,9 +85,21 @@ class RNG } /* ==================== MUTATORS ======================================= */ + /** + * @brief If seed if 0 then set seed to a random number else set seed to + * the given number. + * + * @param seed + */ void setSeed( const unsigned long int seed ) { seed_ = seed; + if( seed == 0 ) + { + setRandomSeed( ); + return; + } + #if defined(USE_BOOST) || defined(ENABLE_CPP11) rng_.seed( seed_ ); #else -- GitLab