From 87e9c246e85281b62e49402d90de9f385065b827 Mon Sep 17 00:00:00 2001 From: Matthew Gidden Date: Tue, 21 Apr 2015 10:32:28 -0500 Subject: [PATCH 01/80] adding travis.yml --- .travis.yml | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000000..3becb17748 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,49 @@ +language: python +python: + # We don't actually use the Travis Python, but this keeps it organized. + - "2.7" + - "3.4" + +before_install: + - sudo apt-get update -qq + +install: + # You may want to periodically update this, although the conda update + # conda line below will keep everything up-to-date. We do this + # conditionally because it saves us some downloading if the version is + # the same. + - if [[ "$TRAVIS_PYTHON_VERSION" == "2.7" ]]; then + wget http://repo.continuum.io/miniconda/Miniconda-latest-Linux-x86_64.sh -O miniconda.sh; + else + wget http://repo.continuum.io/miniconda/Miniconda3-latest-Linux-x86_64.sh -O miniconda.sh; + fi + - bash miniconda.sh -b -p $HOME/miniconda + - export PATH="$HOME/miniconda/bin:$PATH" + - hash -r + - conda config --set always_yes yes --set changeps1 no + - conda config --add channels pyne + - conda config --add channels cyclus + - conda config --add channels cycamore + - conda update -q conda + - conda install conda-build jinja2 setuptools binstar patchelf nose + # Useful for debugging any issues with conda + - conda info -a + + # download CI repo + - wget https://github.com/cyclus/ciclus/archive/master.zip -O ciclus.zip + - unzip -j ciclus.zip "*/cycamore/*" -d conda-recipe + + # Replace dep1 dep2 ... with your dependencies + #- conda create -q -n test-environment python=$TRAVIS_PYTHON_VERSION dep1 dep2 ... + #- source activate test-environment + - conda build --no-test conda-recipe + - conda install cycamore --use-local + +script: + - cycamore_unit_tests + - nosetests -w tests + #- cd tests + #- nosetests + #- ./travis-run-tests.sh + + From e23c820cfee4f2ebd9d286b3268d649b3df7884b Mon Sep 17 00:00:00 2001 From: Matthew Gidden Date: Tue, 21 Apr 2015 13:39:20 -0500 Subject: [PATCH 02/80] rm cycamore as binstar user --- .travis.yml | 3 --- 1 file changed, 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 3becb17748..12755d392b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,10 +3,8 @@ python: # We don't actually use the Travis Python, but this keeps it organized. - "2.7" - "3.4" - before_install: - sudo apt-get update -qq - install: # You may want to periodically update this, although the conda update # conda line below will keep everything up-to-date. We do this @@ -23,7 +21,6 @@ install: - conda config --set always_yes yes --set changeps1 no - conda config --add channels pyne - conda config --add channels cyclus - - conda config --add channels cycamore - conda update -q conda - conda install conda-build jinja2 setuptools binstar patchelf nose # Useful for debugging any issues with conda From 6884f7ef094b6e641b01ebff5f7512295f870cc8 Mon Sep 17 00:00:00 2001 From: Matthew Gidden Date: Tue, 21 Apr 2015 16:51:47 -0500 Subject: [PATCH 03/80] updating path and tables install --- .travis.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 12755d392b..f8e2e5d435 100644 --- a/.travis.yml +++ b/.travis.yml @@ -22,7 +22,7 @@ install: - conda config --add channels pyne - conda config --add channels cyclus - conda update -q conda - - conda install conda-build jinja2 setuptools binstar patchelf nose + - conda install conda-build setuptools binstar patchelf nose # Useful for debugging any issues with conda - conda info -a @@ -37,6 +37,8 @@ install: - conda install cycamore --use-local script: + - export PATH="$HOME/miniconda/bin:$PATH" + - conda install tables - cycamore_unit_tests - nosetests -w tests #- cd tests From bf235f2452ec69876d899b71c5d42e18bbf1c6ce Mon Sep 17 00:00:00 2001 From: Matthew Gidden Date: Tue, 21 Apr 2015 16:52:55 -0500 Subject: [PATCH 04/80] numpy install --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index f8e2e5d435..061440d20b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -38,7 +38,7 @@ install: script: - export PATH="$HOME/miniconda/bin:$PATH" - - conda install tables + - conda install numpy tables - cycamore_unit_tests - nosetests -w tests #- cd tests From dc7526d28b0f2174b11c708f846b8630738737a9 Mon Sep 17 00:00:00 2001 From: Matthew Gidden Date: Wed, 22 Apr 2015 10:56:36 -0500 Subject: [PATCH 05/80] updating from cyclus yml --- .travis.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.travis.yml b/.travis.yml index 061440d20b..dc2c452196 100644 --- a/.travis.yml +++ b/.travis.yml @@ -38,6 +38,11 @@ install: script: - export PATH="$HOME/miniconda/bin:$PATH" + - export LD_LIBRARY_PATH="$HOME/miniconda/lib:$HOME/miniconda/envs/_build/lib:$LD_LIBRARY_PATH" + - ls -l $HOME/miniconda/lib + - ls -l $HOME/miniconda/envs/_build/lib + - ln -s $HOME/miniconda/lib/libhdf5.so.9 $HOME/miniconda/lib/libhdf5.so.8 + - ln -s $HOME/miniconda/lib/libhdf5_hl.so.9 $HOME/miniconda/lib/libhdf5_hl.so.8 - conda install numpy tables - cycamore_unit_tests - nosetests -w tests From b33517b121b342c72237dd034bda2e3eb15e9fd4 Mon Sep 17 00:00:00 2001 From: Matthew Gidden Date: Wed, 22 Apr 2015 17:48:36 -0500 Subject: [PATCH 06/80] matching cyclus --- .travis.yml | 34 ++++++++++++++++------------------ 1 file changed, 16 insertions(+), 18 deletions(-) diff --git a/.travis.yml b/.travis.yml index dc2c452196..0bdcac5064 100644 --- a/.travis.yml +++ b/.travis.yml @@ -22,32 +22,30 @@ install: - conda config --add channels pyne - conda config --add channels cyclus - conda update -q conda - - conda install conda-build setuptools binstar patchelf nose + - conda install conda-build jinja2 setuptools binstar patchelf nose # Useful for debugging any issues with conda - conda info -a # download CI repo - wget https://github.com/cyclus/ciclus/archive/master.zip -O ciclus.zip - - unzip -j ciclus.zip "*/cycamore/*" -d conda-recipe - - # Replace dep1 dep2 ... with your dependencies - #- conda create -q -n test-environment python=$TRAVIS_PYTHON_VERSION dep1 dep2 ... - #- source activate test-environment - - conda build --no-test conda-recipe - - conda install cycamore --use-local + - unzip -j ciclus.zip + + # build cyclus + - mv ciclus/cyclus conda-recipe-cyclus + - conda build --no-test conda-recipe-cyclus + - conda install --use-local cyclus=0.0 + + # build cycamore + - mv ciclus/cycamore conda-recipe-cycamore + - conda build --no-test conda-recipe-cycamore + - conda install --use-local cycamore=0.0 script: - export PATH="$HOME/miniconda/bin:$PATH" - - export LD_LIBRARY_PATH="$HOME/miniconda/lib:$HOME/miniconda/envs/_build/lib:$LD_LIBRARY_PATH" - - ls -l $HOME/miniconda/lib - - ls -l $HOME/miniconda/envs/_build/lib - - ln -s $HOME/miniconda/lib/libhdf5.so.9 $HOME/miniconda/lib/libhdf5.so.8 - - ln -s $HOME/miniconda/lib/libhdf5_hl.so.9 $HOME/miniconda/lib/libhdf5_hl.so.8 - - conda install numpy tables + - export LD_LIBRARY_PATH="$HOME/miniconda/lib:$LD_LIBRARY_PATH" + #- ls -l $HOME/miniconda/lib + #- ls -l $HOME/miniconda/envs/_build/lib - cycamore_unit_tests + - conda install numpy tables - nosetests -w tests - #- cd tests - #- nosetests - #- ./travis-run-tests.sh - From aa10d1bc5a0e43b52fe164aa89b4f69e67b176e7 Mon Sep 17 00:00:00 2001 From: Matthew Gidden Date: Wed, 22 Apr 2015 17:50:17 -0500 Subject: [PATCH 07/80] grabbing correct ciclus --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 0bdcac5064..1d51093559 100644 --- a/.travis.yml +++ b/.travis.yml @@ -27,7 +27,7 @@ install: - conda info -a # download CI repo - - wget https://github.com/cyclus/ciclus/archive/master.zip -O ciclus.zip + - wget https://github.com/gidden/ciclus/archive/travis.zip -O ciclus.zip - unzip -j ciclus.zip # build cyclus From 5df1535be38c8870834ced308a3ca52f96a775ab Mon Sep 17 00:00:00 2001 From: Matthew Gidden Date: Wed, 22 Apr 2015 18:13:53 -0500 Subject: [PATCH 08/80] mirroring cyclus unzip --- .travis.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 1d51093559..d6eb10b32b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -28,14 +28,15 @@ install: # download CI repo - wget https://github.com/gidden/ciclus/archive/travis.zip -O ciclus.zip - - unzip -j ciclus.zip # build cyclus + - unzip -j ciclus.zip "*/cyclus/*" -d conda-recipe-cyclus - mv ciclus/cyclus conda-recipe-cyclus - conda build --no-test conda-recipe-cyclus - conda install --use-local cyclus=0.0 # build cycamore + - unzip -j ciclus.zip "*/cycamore/*" -d conda-recipe-cycamore - mv ciclus/cycamore conda-recipe-cycamore - conda build --no-test conda-recipe-cycamore - conda install --use-local cycamore=0.0 From c7c45cc38ee0f8459d016f92090b7a2b68e0d0f9 Mon Sep 17 00:00:00 2001 From: Matthew Gidden Date: Wed, 22 Apr 2015 18:23:41 -0500 Subject: [PATCH 09/80] rm mvs --- .travis.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index d6eb10b32b..09c1b2a1bf 100644 --- a/.travis.yml +++ b/.travis.yml @@ -31,13 +31,11 @@ install: # build cyclus - unzip -j ciclus.zip "*/cyclus/*" -d conda-recipe-cyclus - - mv ciclus/cyclus conda-recipe-cyclus - conda build --no-test conda-recipe-cyclus - conda install --use-local cyclus=0.0 # build cycamore - unzip -j ciclus.zip "*/cycamore/*" -d conda-recipe-cycamore - - mv ciclus/cycamore conda-recipe-cycamore - conda build --no-test conda-recipe-cycamore - conda install --use-local cycamore=0.0 From c8773ab838b053f39a11d685f490f17a3146457c Mon Sep 17 00:00:00 2001 From: Matthew Gidden Date: Wed, 22 Apr 2015 18:34:34 -0500 Subject: [PATCH 10/80] maybe conda-recipe name matters --- .travis.yml | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index 09c1b2a1bf..9e414d829c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -30,13 +30,14 @@ install: - wget https://github.com/gidden/ciclus/archive/travis.zip -O ciclus.zip # build cyclus - - unzip -j ciclus.zip "*/cyclus/*" -d conda-recipe-cyclus - - conda build --no-test conda-recipe-cyclus + - unzip -j ciclus.zip "*/cyclus/*" -d conda-recipe + - conda build --no-test conda-recipe - conda install --use-local cyclus=0.0 + - mv conda-recipe conda-recipe-cyclus # build cycamore - - unzip -j ciclus.zip "*/cycamore/*" -d conda-recipe-cycamore - - conda build --no-test conda-recipe-cycamore + - unzip -j ciclus.zip "*/cycamore/*" -d conda-recipe + - conda build --no-test conda-recipe - conda install --use-local cycamore=0.0 script: From 5808f75a18b0bd2d20778d6c70a452522b994a23 Mon Sep 17 00:00:00 2001 From: Matthew Gidden Date: Thu, 23 Apr 2015 08:55:28 -0500 Subject: [PATCH 11/80] trying now with sedding the right cyclus --- .travis.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 9e414d829c..08589b0985 100644 --- a/.travis.yml +++ b/.travis.yml @@ -33,12 +33,14 @@ install: - unzip -j ciclus.zip "*/cyclus/*" -d conda-recipe - conda build --no-test conda-recipe - conda install --use-local cyclus=0.0 - - mv conda-recipe conda-recipe-cyclus + - mv conda-recipe cyclus-recipe # build cycamore - unzip -j ciclus.zip "*/cycamore/*" -d conda-recipe + - sed -i "s/- cyclus/- cyclus=0.0/g" conda-recipe/meta.yaml - conda build --no-test conda-recipe - conda install --use-local cycamore=0.0 + - mv conda-recipe cycamore-recipe script: - export PATH="$HOME/miniconda/bin:$PATH" From 7054c3c7741e2e87d78bc63ee5e8ee819d46d1cd Mon Sep 17 00:00:00 2001 From: Matthew Gidden Date: Thu, 23 Apr 2015 09:02:51 -0500 Subject: [PATCH 12/80] trying some cyclus foo --- .travis.yml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/.travis.yml b/.travis.yml index 08589b0985..d2ca4ae79a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -30,10 +30,17 @@ install: - wget https://github.com/gidden/ciclus/archive/travis.zip -O ciclus.zip # build cyclus + - pwd=$PWD + - echo "pwd: $pwd" + - cd $HOME + - git clone git@github.com:gidden/cyclus + - cd cyclus + - git checkout origin/travis - unzip -j ciclus.zip "*/cyclus/*" -d conda-recipe - conda build --no-test conda-recipe - conda install --use-local cyclus=0.0 - mv conda-recipe cyclus-recipe + - cd $pwd # build cycamore - unzip -j ciclus.zip "*/cycamore/*" -d conda-recipe From 124d70ba03f1d2b1cdc7cb20d3f1d36bf29d2078 Mon Sep 17 00:00:00 2001 From: Matthew Gidden Date: Thu, 23 Apr 2015 09:08:50 -0500 Subject: [PATCH 13/80] travis doesn't like colons --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index d2ca4ae79a..b703ceb84a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -31,7 +31,7 @@ install: # build cyclus - pwd=$PWD - - echo "pwd: $pwd" + - echo "pwd $pwd" - cd $HOME - git clone git@github.com:gidden/cyclus - cd cyclus From c3d8d007ae4e282aee92ef93937ecb6acf9e0717 Mon Sep 17 00:00:00 2001 From: Matthew Gidden Date: Thu, 23 Apr 2015 09:15:08 -0500 Subject: [PATCH 14/80] https for clone --- .travis.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index b703ceb84a..876463161d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -32,8 +32,8 @@ install: # build cyclus - pwd=$PWD - echo "pwd $pwd" - - cd $HOME - - git clone git@github.com:gidden/cyclus + - cd .. + - git clone https://github.com/gidden/cyclus - cd cyclus - git checkout origin/travis - unzip -j ciclus.zip "*/cyclus/*" -d conda-recipe From 053b47c8c8385e4a9b3cfdb1aee0555dc1f87763 Mon Sep 17 00:00:00 2001 From: Matthew Gidden Date: Thu, 23 Apr 2015 09:23:52 -0500 Subject: [PATCH 15/80] need to rewget --- .travis.yml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 876463161d..a31791ff27 100644 --- a/.travis.yml +++ b/.travis.yml @@ -26,9 +26,6 @@ install: # Useful for debugging any issues with conda - conda info -a - # download CI repo - - wget https://github.com/gidden/ciclus/archive/travis.zip -O ciclus.zip - # build cyclus - pwd=$PWD - echo "pwd $pwd" @@ -36,6 +33,7 @@ install: - git clone https://github.com/gidden/cyclus - cd cyclus - git checkout origin/travis + - wget https://github.com/gidden/ciclus/archive/travis.zip -O ciclus.zip - unzip -j ciclus.zip "*/cyclus/*" -d conda-recipe - conda build --no-test conda-recipe - conda install --use-local cyclus=0.0 @@ -43,6 +41,7 @@ install: - cd $pwd # build cycamore + - wget https://github.com/gidden/ciclus/archive/travis.zip -O ciclus.zip - unzip -j ciclus.zip "*/cycamore/*" -d conda-recipe - sed -i "s/- cyclus/- cyclus=0.0/g" conda-recipe/meta.yaml - conda build --no-test conda-recipe From 3130135b2cd39e8ba8b32af47957a76e4d30b6dd Mon Sep 17 00:00:00 2001 From: Matthew Gidden Date: Thu, 23 Apr 2015 10:00:58 -0500 Subject: [PATCH 16/80] meta didn't like = ' --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index a31791ff27..f3b5eb5e8b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -43,7 +43,7 @@ install: # build cycamore - wget https://github.com/gidden/ciclus/archive/travis.zip -O ciclus.zip - unzip -j ciclus.zip "*/cycamore/*" -d conda-recipe - - sed -i "s/- cyclus/- cyclus=0.0/g" conda-recipe/meta.yaml + - sed -i "s/- cyclus/- cyclus 0.0/g" conda-recipe/meta.yaml - conda build --no-test conda-recipe - conda install --use-local cycamore=0.0 - mv conda-recipe cycamore-recipe From 317da972decd0d9dd60e850224422cd93a55214a Mon Sep 17 00:00:00 2001 From: Matthew Gidden Date: Thu, 23 Apr 2015 10:20:45 -0500 Subject: [PATCH 17/80] updating for travis-install.sh --- .travis-install.sh | 5 +++++ .travis.yml | 26 +++++++------------------- 2 files changed, 12 insertions(+), 19 deletions(-) create mode 100755 .travis-install.sh diff --git a/.travis-install.sh b/.travis-install.sh new file mode 100755 index 0000000000..0ab998f721 --- /dev/null +++ b/.travis-install.sh @@ -0,0 +1,5 @@ +wget https://github.com/gidden/ciclus/archive/travis.zip -O ciclus.zip +unzip -j ciclus.zip "*/cycamore/*" -d conda-recipe +sed -i "s/- cyclus/- cyclus 0.0/g" conda-recipe/meta.yaml +conda build --no-test conda-recipe +conda install --use-local cycamore=0.0 \ No newline at end of file diff --git a/.travis.yml b/.travis.yml index f3b5eb5e8b..6eecf5b8a2 100644 --- a/.travis.yml +++ b/.travis.yml @@ -26,27 +26,15 @@ install: # Useful for debugging any issues with conda - conda info -a - # build cyclus - - pwd=$PWD - - echo "pwd $pwd" - - cd .. - - git clone https://github.com/gidden/cyclus - - cd cyclus + # install cyclus + - git clone https://github.com/gidden/cyclus ../cyclus + - cd ../cyclus - git checkout origin/travis - - wget https://github.com/gidden/ciclus/archive/travis.zip -O ciclus.zip - - unzip -j ciclus.zip "*/cyclus/*" -d conda-recipe - - conda build --no-test conda-recipe - - conda install --use-local cyclus=0.0 - - mv conda-recipe cyclus-recipe - - cd $pwd + - ./.travis-install.sh + - cd ../cycamore - # build cycamore - - wget https://github.com/gidden/ciclus/archive/travis.zip -O ciclus.zip - - unzip -j ciclus.zip "*/cycamore/*" -d conda-recipe - - sed -i "s/- cyclus/- cyclus 0.0/g" conda-recipe/meta.yaml - - conda build --no-test conda-recipe - - conda install --use-local cycamore=0.0 - - mv conda-recipe cycamore-recipe + # install cycamore + - ./.travis-install.sh script: - export PATH="$HOME/miniconda/bin:$PATH" From 9b7650f01b0a96aa900f11af982c6c3d1ec4be28 Mon Sep 17 00:00:00 2001 From: Matthew Gidden Date: Thu, 23 Apr 2015 10:25:51 -0500 Subject: [PATCH 18/80] matching find hdf5.cmakes with cyclus --- cmake/FindHDF5.cmake | 382 ++++++++++++++++++++++--------------------- 1 file changed, 192 insertions(+), 190 deletions(-) diff --git a/cmake/FindHDF5.cmake b/cmake/FindHDF5.cmake index 1722a7ea41..5b7cadd022 100644 --- a/cmake/FindHDF5.cmake +++ b/cmake/FindHDF5.cmake @@ -26,7 +26,7 @@ # In addition to finding the includes and libraries required to compile an HDF5 # client application, this module also makes an effort to find tools that come # with the HDF5 distribution that may be useful for regression testing. -# +# # This module will define the following variables: # HDF5_INCLUDE_DIRS - Location of the hdf5 includes # HDF5_INCLUDE_DIR - Location of the hdf5 includes (deprecated) @@ -60,268 +60,270 @@ include(SelectLibraryConfigurations) include(FindPackageHandleStandardArgs) # List of the valid HDF5 components -set(HDF5_VALID_COMPONENTS +set( HDF5_VALID_COMPONENTS C CXX - ) +) # try to find the HDF5 wrapper compilers -find_program(HDF5_C_COMPILER_EXECUTABLE +find_program( HDF5_C_COMPILER_EXECUTABLE NAMES h5cc h5pcc HINTS ENV HDF5_ROOT PATH_SUFFIXES bin Bin - DOC "HDF5 Wrapper compiler. Used only to detect HDF5 compile flags.") -mark_as_advanced(HDF5_C_COMPILER_EXECUTABLE) + DOC "HDF5 Wrapper compiler. Used only to detect HDF5 compile flags." ) +mark_as_advanced( HDF5_C_COMPILER_EXECUTABLE ) -find_program(HDF5_CXX_COMPILER_EXECUTABLE +find_program( HDF5_CXX_COMPILER_EXECUTABLE NAMES h5c++ h5pc++ HINTS ENV HDF5_ROOT PATH_SUFFIXES bin Bin - DOC "HDF5 C++ Wrapper compiler. Used only to detect HDF5 compile flags.") -mark_as_advanced(HDF5_CXX_COMPILER_EXECUTABLE) + DOC "HDF5 C++ Wrapper compiler. Used only to detect HDF5 compile flags." ) +mark_as_advanced( HDF5_CXX_COMPILER_EXECUTABLE ) -find_program(HDF5_DIFF_EXECUTABLE +find_program( HDF5_DIFF_EXECUTABLE NAMES h5diff HINTS ENV HDF5_ROOT - PATH_SUFFIXES bin Bin - DOC "HDF5 file differencing tool.") -mark_as_advanced(HDF5_DIFF_EXECUTABLE) + PATH_SUFFIXES bin Bin + DOC "HDF5 file differencing tool." ) +mark_as_advanced( HDF5_DIFF_EXECUTABLE ) # Invoke the HDF5 wrapper compiler. The compiler return value is stored to the # return_value argument, the text output is stored to the output variable. -macro(_HDF5_invoke_compiler language output return_value) - if(HDF5_${language}_COMPILER_EXECUTABLE) - exec_program(${HDF5_${language}_COMPILER_EXECUTABLE} +macro( _HDF5_invoke_compiler language output return_value ) + if( HDF5_${language}_COMPILER_EXECUTABLE ) + exec_program( ${HDF5_${language}_COMPILER_EXECUTABLE} ARGS -show OUTPUT_VARIABLE ${output} RETURN_VALUE ${return_value} - ) - if(${${return_value}} EQUAL 0) + ) + if( ${${return_value}} EQUAL 0 ) # do nothing else() - message(STATUS - "Unable to determine HDF5 ${language} flags from HDF5 wrapper.") + message( STATUS + "Unable to determine HDF5 ${language} flags from HDF5 wrapper." ) endif() endif() endmacro() # Parse a compile line for definitions, includes, library paths, and libraries. -macro(_HDF5_parse_compile_line - compile_line_var - include_paths - definitions - library_paths - libraries) +macro( _HDF5_parse_compile_line + compile_line_var + include_paths + definitions + library_paths + libraries ) # Match the include paths - string(REGEX MATCHALL "-I([^\" ]+)" include_path_flags + string( REGEX MATCHALL "-I([^\" ]+)" include_path_flags "${${compile_line_var}}" - ) - foreach(IPATH ${include_path_flags}) - string(REGEX REPLACE "^-I" "" IPATH ${IPATH}) - string(REGEX REPLACE "//" "/" IPATH ${IPATH}) - list(APPEND ${include_paths} ${IPATH}) + ) + foreach( IPATH ${include_path_flags} ) + string( REGEX REPLACE "^-I" "" IPATH ${IPATH} ) + string( REGEX REPLACE "//" "/" IPATH ${IPATH} ) + list( APPEND ${include_paths} ${IPATH} ) endforeach() # Match the definitions - string(REGEX MATCHALL "-D[^ ]*" definition_flags "${${compile_line_var}}") - foreach(DEF ${definition_flags}) - list(APPEND ${definitions} ${DEF}) + string( REGEX MATCHALL "-D[^ ]*" definition_flags "${${compile_line_var}}" ) + foreach( DEF ${definition_flags} ) + list( APPEND ${definitions} ${DEF} ) endforeach() # Match the library paths - string(REGEX MATCHALL "-L([^\" ]+|\"[^\"]+\")" library_path_flags + string( REGEX MATCHALL "-L([^\" ]+|\"[^\"]+\")" library_path_flags "${${compile_line_var}}" - ) - - foreach(LPATH ${library_path_flags}) - string(REGEX REPLACE "^-L" "" LPATH ${LPATH}) - string(REGEX REPLACE "//" "/" LPATH ${LPATH}) - list(APPEND ${library_paths} ${LPATH}) + ) + + foreach( LPATH ${library_path_flags} ) + string( REGEX REPLACE "^-L" "" LPATH ${LPATH} ) + string( REGEX REPLACE "//" "/" LPATH ${LPATH} ) + list( APPEND ${library_paths} ${LPATH} ) endforeach() # now search for the library names specified in the compile line (match -l...) # match only -l's preceded by a space or comma # this is to exclude directory names like xxx-linux/ - string(REGEX MATCHALL "[, ]-l([^\", ]+)" library_name_flags - "${${compile_line_var}}") + string( REGEX MATCHALL "[, ]-l([^\", ]+)" library_name_flags + "${${compile_line_var}}" ) # strip the -l from all of the library flags and add to the search list - foreach(LIB ${library_name_flags}) - string(REGEX REPLACE "^[, ]-l" "" LIB ${LIB}) - list(APPEND ${libraries} ${LIB}) + foreach( LIB ${library_name_flags} ) + string( REGEX REPLACE "^[, ]-l" "" LIB ${LIB} ) + list( APPEND ${libraries} ${LIB} ) endforeach() endmacro() -if(HDF5_INCLUDE_DIRS AND HDF5_LIBRARIES) +if( HDF5_INCLUDE_DIRS AND HDF5_LIBRARIES ) # Do nothing: we already have HDF5_INCLUDE_PATH and HDF5_LIBRARIES in the # cache, it would be a shame to override them else() - _HDF5_invoke_compiler(C HDF5_C_COMPILE_LINE HDF5_C_RETURN_VALUE) - _HDF5_invoke_compiler(CXX HDF5_CXX_COMPILE_LINE HDF5_CXX_RETURN_VALUE) + _HDF5_invoke_compiler( C HDF5_C_COMPILE_LINE HDF5_C_RETURN_VALUE ) + _HDF5_invoke_compiler( CXX HDF5_CXX_COMPILE_LINE HDF5_CXX_RETURN_VALUE ) - if(NOT HDF5_FIND_COMPONENTS) - set(HDF5_LANGUAGE_BINDINGS "C") + if( NOT HDF5_FIND_COMPONENTS ) + set( HDF5_LANGUAGE_BINDINGS "C" ) else() # add the extra specified components, ensuring that they are valid. - foreach(component ${HDF5_FIND_COMPONENTS}) - list(FIND HDF5_VALID_COMPONENTS ${component} component_location) - if(${component_location} EQUAL -1) - message(FATAL_ERROR - "\"${component}\" is not a valid HDF5 component.") + foreach( component ${HDF5_FIND_COMPONENTS} ) + list( FIND HDF5_VALID_COMPONENTS ${component} component_location ) + if( ${component_location} EQUAL -1 ) + message( FATAL_ERROR + "\"${component}\" is not a valid HDF5 component." ) else() - list(APPEND HDF5_LANGUAGE_BINDINGS ${component}) + list( APPEND HDF5_LANGUAGE_BINDINGS ${component} ) endif() endforeach() endif() - + # seed the initial lists of libraries to find with items we know we need - set(HDF5_C_LIBRARY_NAMES_INIT hdf5_hl hdf5) - set(HDF5_CXX_LIBRARY_NAMES_INIT hdf5_cpp ${HDF5_C_LIBRARY_NAMES_INIT}) - - foreach(LANGUAGE ${HDF5_LANGUAGE_BINDINGS}) - if(HDF5_${LANGUAGE}_COMPILE_LINE) - _HDF5_parse_compile_line(HDF5_${LANGUAGE}_COMPILE_LINE - HDF5_${LANGUAGE}_INCLUDE_FLAGS - HDF5_${LANGUAGE}_DEFINITIONS - HDF5_${LANGUAGE}_LIBRARY_DIRS - HDF5_${LANGUAGE}_LIBRARY_NAMES + set( HDF5_C_LIBRARY_NAMES_INIT hdf5_hl hdf5 ) + set( HDF5_CXX_LIBRARY_NAMES_INIT hdf5_cpp ${HDF5_C_LIBRARY_NAMES_INIT} ) + + foreach( LANGUAGE ${HDF5_LANGUAGE_BINDINGS} ) + if( HDF5_${LANGUAGE}_COMPILE_LINE ) + _HDF5_parse_compile_line( HDF5_${LANGUAGE}_COMPILE_LINE + HDF5_${LANGUAGE}_INCLUDE_FLAGS + HDF5_${LANGUAGE}_DEFINITIONS + HDF5_${LANGUAGE}_LIBRARY_DIRS + HDF5_${LANGUAGE}_LIBRARY_NAMES ) + + # take a guess that the includes may be in the 'include' sibling directory + # of a library directory. + foreach( dir ${HDF5_${LANGUAGE}_LIBRARY_DIRS} ) + list( APPEND HDF5_${LANGUAGE}_INCLUDE_FLAGS ${dir}/../include ) + endforeach() + endif() - # take a guess that the includes may be in the 'include' sibling directory - # of a library directory. - foreach(dir ${HDF5_${LANGUAGE}_LIBRARY_DIRS}) - list(APPEND HDF5_${LANGUAGE}_INCLUDE_FLAGS ${dir}/../include) - endforeach() - endif() - - # set the definitions for the language bindings. - list(APPEND HDF5_DEFINITIONS ${HDF5_${LANGUAGE}_DEFINITIONS}) - - # find the HDF5 include directories - find_path(HDF5_${LANGUAGE}_INCLUDE_DIR hdf5.h - HINTS - ${HDF5_${LANGUAGE}_INCLUDE_FLAGS} - ENV - HDF5_ROOT - PATHS - $ENV{HOME}/.local/include - PATH_SUFFIXES - include - Include + # set the definitions for the language bindings. + list( APPEND HDF5_DEFINITIONS ${HDF5_${LANGUAGE}_DEFINITIONS} ) + + # find the HDF5 include directories + find_path( HDF5_${LANGUAGE}_INCLUDE_DIR hdf5.h + HINTS + ${HDF5_${LANGUAGE}_INCLUDE_FLAGS} + ENV + HDF5_ROOT + PATHS + $ENV{HOME}/.local/include + PATH_SUFFIXES + include + Include ) - mark_as_advanced(HDF5_${LANGUAGE}_INCLUDE_DIR) - list(APPEND HDF5_INCLUDE_DIRS ${HDF5_${LANGUAGE}_INCLUDE_DIR}) - - set(HDF5_${LANGUAGE}_LIBRARY_NAMES - ${HDF5_${LANGUAGE}_LIBRARY_NAMES_INIT} - ${HDF5_${LANGUAGE}_LIBRARY_NAMES}) - - # find the HDF5 libraries - foreach(LIB ${HDF5_${LANGUAGE}_LIBRARY_NAMES}) - if(UNIX AND HDF5_USE_STATIC_LIBRARIES) - # According to bug 1643 on the CMake bug tracker, this is the - # preferred method for searching for a static library. - # See http://www.cmake.org/Bug/view.php?id=1643. We search - # first for the full static library name, but fall back to a - # generic search on the name if the static search fails. - set(THIS_LIBRARY_SEARCH_DEBUG lib${LIB}d.a ${LIB}d) - set(THIS_LIBRARY_SEARCH_RELEASE lib${LIB}.a ${LIB}) - else() - set(THIS_LIBRARY_SEARCH_DEBUG ${LIB}d) - set(THIS_LIBRARY_SEARCH_RELEASE ${LIB}) - endif() - find_library(HDF5_${LIB}_LIBRARY_DEBUG - NAMES ${THIS_LIBRARY_SEARCH_DEBUG} - HINTS ${HDF5_${LANGUAGE}_LIBRARY_DIRS} - ENV HDF5_ROOT - PATH_SUFFIXES lib Lib) - find_library(HDF5_${LIB}_LIBRARY_RELEASE - NAMES ${THIS_LIBRARY_SEARCH_RELEASE} - HINTS ${HDF5_${LANGUAGE}_LIBRARY_DIRS} - ENV HDF5_ROOT - PATH_SUFFIXES lib Lib) - select_library_configurations(HDF5_${LIB}) - # even though we adjusted the individual library names in - # select_library_configurations, we still need to distinguish - # between debug and release variants because HDF5_LIBRARIES will - # need to specify different lists for debug and optimized builds. - # We can't just use the HDF5_${LIB}_LIBRARY variable (which was set - # up by the selection macro above) because it may specify debug and - # optimized variants for a particular library, but a list of - # libraries is allowed to specify debug and optimized only once. - list(APPEND HDF5_${LANGUAGE}_LIBRARIES_DEBUG - ${HDF5_${LIB}_LIBRARY_DEBUG}) - list(APPEND HDF5_${LANGUAGE}_LIBRARIES_RELEASE - ${HDF5_${LIB}_LIBRARY_RELEASE}) + mark_as_advanced( HDF5_${LANGUAGE}_INCLUDE_DIR ) + list( APPEND HDF5_INCLUDE_DIRS ${HDF5_${LANGUAGE}_INCLUDE_DIR} ) + + set( HDF5_${LANGUAGE}_LIBRARY_NAMES + ${HDF5_${LANGUAGE}_LIBRARY_NAMES_INIT} + ${HDF5_${LANGUAGE}_LIBRARY_NAMES} ) + + # find the HDF5 libraries + foreach( LIB ${HDF5_${LANGUAGE}_LIBRARY_NAMES} ) + if( UNIX AND HDF5_USE_STATIC_LIBRARIES ) + # According to bug 1643 on the CMake bug tracker, this is the + # preferred method for searching for a static library. + # See http://www.cmake.org/Bug/view.php?id=1643. We search + # first for the full static library name, but fall back to a + # generic search on the name if the static search fails. + set( THIS_LIBRARY_SEARCH_DEBUG lib${LIB}d.a ${LIB}d ) + set( THIS_LIBRARY_SEARCH_RELEASE lib${LIB}.a ${LIB} ) + else() + set( THIS_LIBRARY_SEARCH_DEBUG ${LIB}d ) + set( THIS_LIBRARY_SEARCH_RELEASE ${LIB} ) + endif() + find_library( HDF5_${LIB}_LIBRARY_DEBUG + NAMES ${THIS_LIBRARY_SEARCH_DEBUG} + HINTS ${HDF5_${LANGUAGE}_LIBRARY_DIRS} + ENV HDF5_ROOT + PATH_SUFFIXES lib Lib ) + find_library( HDF5_${LIB}_LIBRARY_RELEASE + NAMES ${THIS_LIBRARY_SEARCH_RELEASE} + HINTS ${HDF5_${LANGUAGE}_LIBRARY_DIRS} + ENV HDF5_ROOT + PATH_SUFFIXES lib Lib ) + select_library_configurations( HDF5_${LIB} ) + # even though we adjusted the individual library names in + # select_library_configurations, we still need to distinguish + # between debug and release variants because HDF5_LIBRARIES will + # need to specify different lists for debug and optimized builds. + # We can't just use the HDF5_${LIB}_LIBRARY variable (which was set + # up by the selection macro above) because it may specify debug and + # optimized variants for a particular library, but a list of + # libraries is allowed to specify debug and optimized only once. + list( APPEND HDF5_${LANGUAGE}_LIBRARIES_DEBUG + ${HDF5_${LIB}_LIBRARY_DEBUG} ) + list( APPEND HDF5_${LANGUAGE}_LIBRARIES_RELEASE + ${HDF5_${LIB}_LIBRARY_RELEASE} ) + endforeach() + list( APPEND HDF5_LIBRARY_DIRS ${HDF5_${LANGUAGE}_LIBRARY_DIRS} ) + + # Append the libraries for this language binding to the list of all + # required libraries. + list( APPEND HDF5_LIBRARIES_DEBUG + ${HDF5_${LANGUAGE}_LIBRARIES_DEBUG} ) + list( APPEND HDF5_LIBRARIES_RELEASE + ${HDF5_${LANGUAGE}_LIBRARIES_RELEASE} ) endforeach() - list(APPEND HDF5_LIBRARY_DIRS ${HDF5_${LANGUAGE}_LIBRARY_DIRS}) - - # Append the libraries for this language binding to the list of all - # required libraries. - list(APPEND HDF5_LIBRARIES_DEBUG - ${HDF5_${LANGUAGE}_LIBRARIES_DEBUG}) - list(APPEND HDF5_LIBRARIES_RELEASE - ${HDF5_${LANGUAGE}_LIBRARIES_RELEASE}) -endforeach() -# We may have picked up some duplicates in various lists during the above -# process for the language bindings (both the C and C++ bindings depend on -# libz for example). Remove the duplicates. -if(HDF5_INCLUDE_DIRS) - list(REMOVE_DUPLICATES HDF5_INCLUDE_DIRS) -endif() -if(HDF5_LIBRARIES_DEBUG) - list(REMOVE_DUPLICATES HDF5_LIBRARIES_DEBUG) -endif() -if(HDF5_LIBRARIES_RELEASE) - list(REMOVE_DUPLICATES HDF5_LIBRARIES_RELEASE) -endif() -if(HDF5_LIBRARY_DIRS) - list(REMOVE_DUPLICATES HDF5_LIBRARY_DIRS) -endif() + # We may have picked up some duplicates in various lists during the above + # process for the language bindings (both the C and C++ bindings depend on + # libz for example). Remove the duplicates. + if( HDF5_INCLUDE_DIRS ) + list( REMOVE_DUPLICATES HDF5_INCLUDE_DIRS ) + endif() + if( HDF5_LIBRARIES_DEBUG ) + list( REMOVE_DUPLICATES HDF5_LIBRARIES_DEBUG ) + endif() + if( HDF5_LIBRARIES_RELEASE ) + list( REMOVE_DUPLICATES HDF5_LIBRARIES_RELEASE ) + endif() + if( HDF5_LIBRARY_DIRS ) + list( REMOVE_DUPLICATES HDF5_LIBRARY_DIRS ) + endif() -# Construct the complete list of HDF5 libraries with debug and optimized -# variants when the generator supports them. -if(CMAKE_CONFIGURATION_TYPES OR CMAKE_BUILD_TYPE) - set(HDF5_LIBRARIES - debug ${HDF5_LIBRARIES_DEBUG} - optimized ${HDF5_LIBRARIES_RELEASE}) -else() - set(HDF5_LIBRARIES ${HDF5_LIBRARIES_RELEASE}) -endif() + # Construct the complete list of HDF5 libraries with debug and optimized + # variants when the generator supports them. + if( CMAKE_CONFIGURATION_TYPES OR CMAKE_BUILD_TYPE ) + set( HDF5_LIBRARIES + debug ${HDF5_LIBRARIES_DEBUG} + optimized ${HDF5_LIBRARIES_RELEASE} ) + else() + set( HDF5_LIBRARIES ${HDF5_LIBRARIES_RELEASE} ) + endif() -# If the HDF5 include directory was found, open H5pubconf.h to determine if -# HDF5 was compiled with parallel IO support -set(HDF5_IS_PARALLEL FALSE) -foreach(_dir HDF5_INCLUDE_DIRS) - if(EXISTS "${_dir}/H5pubconf.h") - file(STRINGS "${_dir}/H5pubconf.h" - HDF5_HAVE_PARALLEL_DEFINE - REGEX "HAVE_PARALLEL 1") - if(HDF5_HAVE_PARALLEL_DEFINE) - set(HDF5_IS_PARALLEL TRUE) + # If the HDF5 include directory was found, open H5pubconf.h to determine if + # HDF5 was compiled with parallel IO support + set( HDF5_IS_PARALLEL FALSE ) + foreach( _dir HDF5_INCLUDE_DIRS ) + if( EXISTS "${_dir}/H5pubconf.h" ) + file( STRINGS "${_dir}/H5pubconf.h" + HDF5_HAVE_PARALLEL_DEFINE + REGEX "HAVE_PARALLEL 1" ) + if( HDF5_HAVE_PARALLEL_DEFINE ) + set( HDF5_IS_PARALLEL TRUE ) + endif() endif() - endif() -endforeach() -set(HDF5_IS_PARALLEL ${HDF5_IS_PARALLEL} CACHE BOOL - "HDF5 library compiled with parallel IO support") -mark_as_advanced(HDF5_IS_PARALLEL) + endforeach() + set( HDF5_IS_PARALLEL ${HDF5_IS_PARALLEL} CACHE BOOL + "HDF5 library compiled with parallel IO support" ) + mark_as_advanced( HDF5_IS_PARALLEL ) endif() -find_package_handle_standard_args(HDF5 DEFAULT_MSG - HDF5_LIBRARIES +find_package_handle_standard_args( HDF5 DEFAULT_MSG + HDF5_LIBRARIES HDF5_INCLUDE_DIRS - ) +) -mark_as_advanced( - HDF5_INCLUDE_DIRS - HDF5_LIBRARIES +mark_as_advanced( + HDF5_INCLUDE_DIRS + HDF5_LIBRARIES HDF5_DEFINTIONS HDF5_LIBRARY_DIRS HDF5_C_COMPILER_EXECUTABLE - HDF5_CXX_COMPILER_EXECUTABLE) + HDF5_CXX_COMPILER_EXECUTABLE ) # For backwards compatibility we set HDF5_INCLUDE_DIR to the value of # HDF5_INCLUDE_DIRS -set(HDF5_INCLUDE_DIR "${HDF5_INCLUDE_DIRS}") +set( HDF5_INCLUDE_DIR "${HDF5_INCLUDE_DIRS}" ) + + From cce530514540be30109a6f4542a2582d4d06d48d Mon Sep 17 00:00:00 2001 From: Matthew Gidden Date: Thu, 23 Apr 2015 10:27:41 -0500 Subject: [PATCH 19/80] tables->pytables --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 6eecf5b8a2..5153f20149 100644 --- a/.travis.yml +++ b/.travis.yml @@ -42,6 +42,6 @@ script: #- ls -l $HOME/miniconda/lib #- ls -l $HOME/miniconda/envs/_build/lib - cycamore_unit_tests - - conda install numpy tables + - conda install numpy pytables - nosetests -w tests From 4f25661c7fe06f815000ea851fa0a9d127678335 Mon Sep 17 00:00:00 2001 From: Robert Carlsen Date: Tue, 17 Feb 2015 12:50:14 -0600 Subject: [PATCH 20/80] Squashing commits from cyclus/cycamore#301. This should fail on CI. --- src/CMakeLists.txt | 2 + src/foo.cc | 171 +++++++++++++++++++++++++++++++++++++ src/foo.h | 204 +++++++++++++++++++++++++++++++++++++++++++++ src/foo_tests.cc | 204 +++++++++++++++++++++++++++++++++++++++++++++ src/foo_tests.h | 34 ++++++++ 5 files changed, 615 insertions(+) create mode 100644 src/foo.cc create mode 100644 src/foo.h create mode 100644 src/foo_tests.cc create mode 100644 src/foo_tests.h diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 5701534c73..0f0ef9eea2 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -10,6 +10,8 @@ USE_CYCLUS("cycamore" "sink") USE_CYCLUS("cycamore" "source") +USE_CYCLUS("cycamore" "foo") + USE_CYCLUS("cycamore" "deploy_inst") USE_CYCLUS("cycamore" "manager_inst") diff --git a/src/foo.cc b/src/foo.cc new file mode 100644 index 0000000000..9ad8ada201 --- /dev/null +++ b/src/foo.cc @@ -0,0 +1,171 @@ +#include "foo.h" + +#include +#include + +#include + +namespace cycamore { + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +Foo::Foo(cyclus::Context* ctx) + : cyclus::Facility(ctx), + out_commod(""), + recipe_name(""), + capacity(std::numeric_limits::max()) {} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +Foo::~Foo() {} + +#pragma cyclus def clone cycamore::Foo + +#pragma cyclus def schema cycamore::Foo + +#pragma cyclus def annotations cycamore::Foo + +#pragma cyclus def infiletodb cycamore::Foo + +#pragma cyclus def snapshot cycamore::Foo + +#pragma cyclus def snapshotinv cycamore::Foo + +#pragma cyclus def initinv cycamore::Foo + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +void Foo::InitFrom(Foo* m) { + #pragma cyclus impl initfromcopy cycamore::Foo + cyclus::toolkit::CommodityProducer::Copy(m); +} + +void Foo::InitFrom(cyclus::QueryableBackend* b) { + #pragma cyclus impl initfromdb cycamore::Foo + + commod_ = cyclus::toolkit::Commodity(out_commod); + cyclus::toolkit::CommodityProducer::Add(commod_); + cyclus::toolkit::CommodityProducer::SetCapacity(commod_, capacity); + cyclus::toolkit::CommodityProducer::SetCost(commod_, capacity); +} + +void Foo::EnterNotify() { + Facility::EnterNotify(); + commod_ = cyclus::toolkit::Commodity(out_commod); + cyclus::toolkit::CommodityProducer::Add(commod_); + cyclus::toolkit::CommodityProducer::SetCapacity(commod_, capacity); + cyclus::toolkit::CommodityProducer::SetCost(commod_, capacity); +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +std::string Foo::str() { + std::stringstream ss; + std::string ans; + if (cyclus::toolkit::CommodityProducer:: + Produces(cyclus::toolkit::Commodity(out_commod))) { + ans = "yes"; + } else { + ans = "no"; + } + ss << cyclus::Facility::str() + << " supplies commodity '" + << out_commod << "' with recipe '" + << recipe_name << "' at a capacity of " + << capacity << " kg per time step " + << " commod producer members: " << " produces " + << out_commod << "?: " << ans + << " capacity: " << cyclus::toolkit::CommodityProducer::Capacity(commod_) + << " cost: " << cyclus::toolkit::CommodityProducer::Cost(commod_); + return ss.str(); +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +void Foo::Tick() { + LOG(cyclus::LEV_INFO3, "SrcFac") << prototype() << " is ticking {"; + LOG(cyclus::LEV_INFO4, "SrcFac") << "will offer " << capacity + << " kg of " + << out_commod << "."; + LOG(cyclus::LEV_INFO3, "SrcFac") << "Stats: " << str(); + LOG(cyclus::LEV_INFO3, "SrcFac") << "}"; + current_capacity = capacity; // reset capacity +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +void Foo::Tock() { + LOG(cyclus::LEV_INFO3, "SrcFac") << prototype() << " is tocking {"; + LOG(cyclus::LEV_INFO3, "SrcFac") << "}"; +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +cyclus::Material::Ptr Foo::GetOffer( + const cyclus::Material::Ptr target) const { + using cyclus::Material; + double qty = std::min(target->quantity(), capacity); + return Material::CreateUntracked(qty, context()->GetRecipe(recipe_name)); +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +std::set::Ptr> +Foo::GetMatlBids( + cyclus::CommodMap::type& commod_requests) { + using cyclus::Bid; + using cyclus::BidPortfolio; + using cyclus::CapacityConstraint; + using cyclus::Material; + using cyclus::Request; + + std::set::Ptr> ports; + + if (commod_requests.count(out_commod) > 0) { + BidPortfolio::Ptr port(new BidPortfolio()); + + std::vector*>& requests = + commod_requests[out_commod]; + + std::vector*>::iterator it; + for (it = requests.begin(); it != requests.end(); ++it) { + Request* req = *it; + Material::Ptr offer = GetOffer(req->target()); + port->AddBid(req, offer, this); + } + + CapacityConstraint cc(capacity); + port->AddConstraint(cc); + ports.insert(port); + } + return ports; +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +void Foo::GetMatlTrades( + const std::vector< cyclus::Trade >& trades, + std::vector, + cyclus::Material::Ptr> >& responses) { + using cyclus::Material; + using cyclus::Trade; + + double provided = 0; + std::vector< cyclus::Trade >::const_iterator it; + for (it = trades.begin(); it != trades.end(); ++it) { + double qty = it->amt; + current_capacity -= qty; + provided += qty; + // @TODO we need a policy on negatives.. + Material::Ptr response = Material::Create(this, qty, + context()->GetRecipe(recipe_name)); + responses.push_back(std::make_pair(*it, response)); + LOG(cyclus::LEV_INFO5, "SrcFac") << prototype() << " just received an order" + << " for " << qty + << " of " << out_commod; + } + if (cyclus::IsNegative(current_capacity)) { + std::stringstream ss; + ss << "is being asked to provide " << provided + << " but its capacity is " << capacity << "."; + throw cyclus::ValueError(Agent::InformErrorMsg(ss.str())); + } +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +extern "C" cyclus::Agent* ConstructFoo(cyclus::Context* ctx) { + return new Foo(ctx); +} + +} // namespace cycamore diff --git a/src/foo.h b/src/foo.h new file mode 100644 index 0000000000..e35ab83d99 --- /dev/null +++ b/src/foo.h @@ -0,0 +1,204 @@ +#ifndef CYCAMORE_SRC_FOO_H_ +#define CYCAMORE_SRC_FOO_H_ + +#include +#include + +#include "cyclus.h" + +namespace cycamore { + +class Context; + +/// @class Foo +/// This cyclus::Facility provides a simple source of some capacity +/// (possibly infinite) of some commodity/Recipe. + +/// The Foo class inherits from the cyclus::Facility class and is +/// dynamically loaded by the Agent class when requested. + +/// @section introduction Introduction +/// The Foo is a facility type in Cyclus capable of providing +/// a finite or infinite.Supply of a particular material to the +/// simulation. A Foo generates material of a certain +/// composition and commodity type, then offers that material on the +/// appropriate market. Shipments of this material are executed when the +/// market issues an order that the offer has been matched with a +/// request. + +/// @section agentparams Agent Parameters +/// Foo behavior is comprehensively defined by the following +/// parameters: +/// - double capacity: The production capacity of the facility (units +/// vary, but typically kg/month). Capacity is infinite if a negative +/// value is provided. +/// - int startDate: The date on which the facility begins to operate +/// (months). +/// - int lifeTime: The length of time that the facility operates +/// (months). - std::string outCommod: the commodity that this facility +/// produces - double inventorysize: the maximum quantity of material to +/// be held in the inventory +/// - double commodprice: the price of the output material PER UNIT +/// - map outComp + +/// @section optionalparams Optional Parameters +/// Foo behavior may also be specified with the following +/// optional parameters which have default values listed here. +/// - double capacityFactor: The ratio of actual production capacity to +/// the rated production capacity. Default is 1 (actual/rated). +/// - double availFactor: The percent of time the facility operates at +/// its capacity factor. Default is 100%. +/// - double capitalCost: The cost of constructing and commissioning +/// this facility. Default is 0 ($). +/// - double opCost: The annual cost of operation and maintenance of +/// this facility. Default is 0 ( $/year). +/// - int constrTime: The number of months it takes to construct and +/// commission this facility. Default is 0 (months). +/// - int decomTime: The number of months it takes to deconstruct and +/// decommission this facility. Default is 0 (months). +/// - Inst* inst: The institution responsible for this facility. +/// - string name: A non-generic name for this facility. + +/// @section detailed Detailed Behavior +/// @subsection finite If Finite Capacity: +/// The Foo starts operation when the simulation reaches the +/// month specified as the startDate. It immediately begins to produce +/// material at the rate defined by its capacity. Each month the +/// Foo adds the amount it has produced to its inventory. It +/// then offers to the appropriate market exactly as much material as it +/// has in its inventory. If an offer is matched with a request, the +/// Foo executes that order by subtracting the quantity from +/// its inventory and sending that amount to the requesting facility. +/// When the simulation time equals the startDate plus the lifeTime, the +/// facility ceases to operate. +/// @subsection infinite If Infinite Capacity: +/// The Foo starts operation when the simulation reaches the +/// month specified as the startDate. Each month the Foo +/// offers an infinite amount of material to the appropriate market. If +/// there is a request for that material, the Foo executes +/// that order by sending that amount to the requesting facility. When +/// the simulation time equals the startDate plus the lifeTime, the +/// facility ceases to operate. + +/// @subsection question Question: +/// What is the best way to allow offers of an infinite amount of +/// material on a market? + +class Foo : public cyclus::Facility, + public cyclus::toolkit::CommodityProducer { + public: + // --- Module Members --- + /// Constructor for the Foo class + /// @param ctx the cyclus context for access to simulation-wide parameters + Foo(cyclus::Context* ctx); + + virtual ~Foo() + + #pragma cyclus decl + + #pragma cyclus note {"doc": "A source facility that provides a " \ + "commodity with a given capacity"} + + /// Print information about this agent + virtual std::string str(); + // --- + + // --- Agent Members --- + virtual void EnterNotify(); + + /// Each facility is prompted to do its beginning-of-time-step + /// stuff at the tick of the timer. + + /// @param time is the time to perform the tick + virtual void Tick(); + + /// Each facility is prompted to its end-of-time-step + /// stuff on the tock of the timer. + + /// @param time is the time to perform the tock + virtual void Tock(); + + /// @brief Responds to each request for this source facility's commodity. + /// If a given request is more than this facility's capacity, it will offer + /// its capacity. + virtual std::set::Ptr> + GetMatlBids(cyclus::CommodMap::type& + commod_requests); + + /// @brief respond to each trade with a material made from this facility's + /// recipe + /// + /// @param trades all trades in which this trader is the supplier + /// @param responses a container to populate with responses to each trade + virtual void GetMatlTrades( + const std::vector< cyclus::Trade >& trades, + std::vector, + cyclus::Material::Ptr> >& responses); + // --- + + // --- Foo Members --- + /// @brief creates a material object to offer to a requester + /// @param target the material target a request desires + cyclus::Material::Ptr GetOffer(const cyclus::Material::Ptr target) const; + + /// sets the output commodity name + /// @param name the commodity name + inline void commodity(std::string name) { out_commod = name; } + + /// @return the output commodity + inline std::string commodity() const { return out_commod; } + + /// sets the capacity of a material generated at any given time step + /// @param capacity the production capacity + inline void Capacity(double cap) { + capacity = cap; + current_capacity = capacity; + } + + /// @return the production capacity at any given time step + inline double Capacity() const { return capacity; } + + /// sets the name of the recipe to be produced + /// @param name the recipe name + inline void recipe(std::string name) { recipe_name = name; } + + /// @return the name of the output recipe + inline std::string recipe() const { return recipe_name; } + + /// @return the current timestep's capacity + inline double CurrentCapacity() const { return current_capacity; } + + private: + cyclus::toolkit::Commodity commod_; + + /// This facility has only one output commodity + #pragma cyclus var {"tooltip": "source output commodity", \ + "doc": "output commodity that the source facility " \ + "supplies", \ + "uitype": "outcommodity"} + std::string out_commod; + + /// Name of the recipe this facility uses. + #pragma cyclus var {"tooltip": "commodity recipe name", \ + "doc": "recipe name for source facility's commodity", \ + "uitype": "recipe"} + std::string recipe_name; + + /// The capacity is defined in terms of the number of units of the + /// recipe that can be provided each time step. A very large number + /// can be provided to represent infinte capacity. + #pragma cyclus var {"default": 1e299, "tooltip": "source capacity", \ + "doc": "amount of commodity that can be supplied " \ + "at each time step"} + double capacity; + + /// The capacity at the current time step + #pragma cyclus var {'derived_init': 'current_capacity = capacity;'} + double current_capacity; + + // --- +}; + +} // namespace cycamore + +#endif // CYCAMORE_SRC_FOO_H_ diff --git a/src/foo_tests.cc b/src/foo_tests.cc new file mode 100644 index 0000000000..0973e794d0 --- /dev/null +++ b/src/foo_tests.cc @@ -0,0 +1,204 @@ +#include "foo_tests.h" + +#include + +#include + +#include "cyc_limits.h" +#include "resource_helpers.h" +#include "test_context.h" + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +void FooTest::SetUp() { + src_facility = new cycamore::Foo(tc.get()); + trader = tc.trader(); + InitParameters(); + SetUpFoo(); +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +void FooTest::TearDown() { + delete src_facility; +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +void FooTest::InitParameters() { + commod = "commod"; + recipe_name = "recipe"; + capacity = 5; // some magic number.. + + recipe = cyclus::Composition::CreateFromAtom(cyclus::CompMap()); + tc.get()->AddRecipe(recipe_name, recipe); +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +void FooTest::SetUpFoo() { + src_facility->commodity(commod); + src_facility->recipe(recipe_name); + src_facility->Capacity(capacity); +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +TEST_F(FooTest, InitialState) { + EXPECT_EQ(src_facility->Capacity(), capacity); + EXPECT_EQ(src_facility->commodity(), commod); + EXPECT_EQ(src_facility->recipe(), recipe_name); + EXPECT_EQ(src_facility->CurrentCapacity(), capacity); +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +TEST_F(FooTest, Clone) { + cyclus::Context* ctx = tc.get(); + cycamore::Foo* cloned_fac = dynamic_cast + (src_facility->Clone()); + + EXPECT_EQ(src_facility->commodity(), cloned_fac->commodity()); + EXPECT_EQ(src_facility->Capacity(), cloned_fac->Capacity()); + EXPECT_EQ(src_facility->recipe(), cloned_fac->recipe()); + EXPECT_EQ(src_facility->Capacity(), cloned_fac->CurrentCapacity()); + + delete cloned_fac; +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +TEST_F(FooTest, Print) { + EXPECT_NO_THROW(std::string s = src_facility->str()); +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +TEST_F(FooTest, GetOffer) { + using cyclus::Material; + + double qty = capacity - 1; + Material::Ptr mat = cyclus::NewBlankMaterial(qty); + Material::Ptr obs_mat = src_facility->GetOffer(mat); + EXPECT_EQ(obs_mat->quantity(), qty); + EXPECT_EQ(obs_mat->comp(), recipe); + + qty = capacity + 1; + mat = cyclus::NewBlankMaterial(qty); + obs_mat = src_facility->GetOffer(mat); + EXPECT_EQ(obs_mat->quantity(), capacity); + EXPECT_EQ(obs_mat->comp(), recipe); + + qty = capacity; + mat = cyclus::NewBlankMaterial(qty); + obs_mat = src_facility->GetOffer(mat); + EXPECT_EQ(obs_mat->quantity(), capacity); + EXPECT_EQ(obs_mat->comp(), recipe); +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +TEST_F(FooTest, AddBids) { + using cyclus::Bid; + using cyclus::BidPortfolio; + using cyclus::CapacityConstraint; + using cyclus::ExchangeContext; + using cyclus::Material; + + int nreqs = 5; + + boost::shared_ptr< cyclus::ExchangeContext > + ec = GetContext(nreqs, commod); + + std::set::Ptr> ports = + src_facility->GetMatlBids(ec.get()->commod_requests); + + ASSERT_TRUE(ports.size() > 0); + EXPECT_EQ(ports.size(), 1); + + BidPortfolio::Ptr port = *ports.begin(); + EXPECT_EQ(port->bidder(), src_facility); + EXPECT_EQ(port->bids().size(), nreqs); + + const std::set< CapacityConstraint >& constrs = port->constraints(); + ASSERT_TRUE(constrs.size() > 0); + EXPECT_EQ(constrs.size(), 1); + EXPECT_EQ(*constrs.begin(), CapacityConstraint(capacity)); +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +TEST_F(FooTest, Response) { + using cyclus::Bid; + using cyclus::Material; + using cyclus::Request; + using cyclus::Trade; + using test_helpers::get_mat; + + std::vector< cyclus::Trade > trades; + std::vector, + cyclus::Material::Ptr> > responses; + + // Null response + EXPECT_NO_THROW(src_facility->GetMatlTrades(trades, responses)); + EXPECT_EQ(responses.size(), 0); + + double qty = capacity / 3; + Request* request = + Request::Create(get_mat(), trader, commod); + Bid* bid = + Bid::Create(request, get_mat(), src_facility); + + Trade trade(request, bid, qty); + trades.push_back(trade); + + // 1 trade + ASSERT_EQ(src_facility->CurrentCapacity(), capacity); + src_facility->GetMatlTrades(trades, responses); + EXPECT_EQ(responses.size(), 1); + EXPECT_EQ(responses[0].second->quantity(), qty); + EXPECT_EQ(responses[0].second->comp(), recipe); + + // 2 trades, total qty = capacity + ASSERT_DOUBLE_EQ(src_facility->CurrentCapacity(), capacity - qty); + ASSERT_GT(src_facility->CurrentCapacity() - 2 * qty, -1 * cyclus::eps()); + trades.push_back(trade); + responses.clear(); + EXPECT_NO_THROW(src_facility->GetMatlTrades(trades, responses)); + EXPECT_EQ(responses.size(), 2); + ASSERT_TRUE(cyclus::AlmostEq(src_facility->CurrentCapacity(), 0)); + + // too much qty, capn! + EXPECT_THROW(src_facility->GetMatlTrades(trades, responses), + cyclus::ValueError); + + // reset! + src_facility->Tick(); + ASSERT_DOUBLE_EQ(src_facility->CurrentCapacity(), capacity); + + delete request; + delete bid; +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +boost::shared_ptr< cyclus::ExchangeContext > +FooTest::GetContext(int nreqs, std::string commod) { + using cyclus::Material; + using cyclus::Request; + using cyclus::ExchangeContext; + using test_helpers::get_mat; + + double qty = 3; + boost::shared_ptr< ExchangeContext > + ec(new ExchangeContext()); + for (int i = 0; i < nreqs; i++) { + ec->AddRequest(Request::Create(get_mat(), trader, commod)); + } + return ec; +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +cyclus::Agent* FooConstructor(cyclus::Context* ctx) { + return new cycamore::Foo(ctx); +} + +// required to get functionality in cyclus agent unit tests library +#ifndef CYCLUS_AGENT_TESTS_CONNECTED +int ConnectAgentTests(); +static int cyclus_agent_tests_connected = ConnectAgentTests(); +#define CYCLUS_AGENT_TESTS_CONNECTED cyclus_agent_tests_connected +#endif // CYCLUS_AGENT_TESTS_CONNECTED + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +INSTANTIATE_TEST_CASE_P(FooFac, FacilityTests, Values(&FooConstructor)); +INSTANTIATE_TEST_CASE_P(FooFac, AgentTests, Values(&FooConstructor)); diff --git a/src/foo_tests.h b/src/foo_tests.h new file mode 100644 index 0000000000..59888926b7 --- /dev/null +++ b/src/foo_tests.h @@ -0,0 +1,34 @@ +#ifndef CYCAMORE_SRC_FOO_TESTS_H_ +#define CYCAMORE_SRC_FOO_TESTS_H_ +#include "foo.h" + +#include + +#include + +#include "agent_tests.h" +#include "context.h" +#include "exchange_context.h" +#include "facility_tests.h" +#include "material.h" + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +class FooTest : public ::testing::Test { + public: + cyclus::TestContext tc; + TestFacility* trader; + cycamore::Foo* src_facility; + std::string commod, recipe_name; + double capacity; + cyclus::Composition::Ptr recipe; + + virtual void SetUp(); + virtual void TearDown(); + void InitParameters(); + void SetUpFoo(); + + boost::shared_ptr< cyclus::ExchangeContext > + GetContext(int nreqs, std::string commodity); +}; + +#endif // CYCAMORE_SRC_FOO_TESTS_H_ From 3d7a9f497f816a2e8fc6ef5ef4c5bd6d6b4b4580 Mon Sep 17 00:00:00 2001 From: Matthew Gidden Date: Thu, 23 Apr 2015 10:56:49 -0500 Subject: [PATCH 21/80] adding same hdf5 messages as cyclus --- CMakeLists.txt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 4985e62e56..f2d1f2b451 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -104,6 +104,10 @@ IF(NOT CYCLUS_DOC_ONLY) FIND_PACKAGE(HDF5 REQUIRED) ADD_DEFINITIONS(${HDF5_DEFINITIONS}) set(LIBS ${LIBS} ${HDF5_LIBRARIES}) + MESSAGE("-- HDF5 Root: ${HDF5_ROOT}") + MESSAGE("-- HDF5 Include directory: ${HDF5_INCLUDE_DIR}") + MESSAGE("-- HDF5 Library directories: ${HDF5_LIBRARY_DIRS}") + MESSAGE("-- HDF5 Libraries: ${HDF5_LIBRARIES}") # find coin and link to it FIND_PACKAGE(COIN REQUIRED) From bbf0a815bd7e9f1436914a9ee4d8e0db1d2dbd92 Mon Sep 17 00:00:00 2001 From: Matthew Gidden Date: Thu, 23 Apr 2015 11:07:56 -0500 Subject: [PATCH 22/80] matching cyclus findhdf --- cmake/FindHDF5.cmake | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/cmake/FindHDF5.cmake b/cmake/FindHDF5.cmake index 5b7cadd022..c7f7d73bee 100644 --- a/cmake/FindHDF5.cmake +++ b/cmake/FindHDF5.cmake @@ -20,8 +20,9 @@ # HDF5_USE_STATIC_LIBRARIES variable is set before the call to find_package. # # To provide the module with a hint about where to find your HDF5 installation, -# you can set the environment variable HDF5_ROOT. The Find module will then -# look in this path when searching for HDF5 executables, paths, and libraries. +# you can set the CMAKE variable -OR- environment variable HDF5_ROOT. The Find +# module will then look in this path when searching for HDF5 executables, paths, +# and libraries. # # In addition to finding the includes and libraries required to compile an HDF5 # client application, this module also makes an effort to find tools that come @@ -68,21 +69,21 @@ set( HDF5_VALID_COMPONENTS # try to find the HDF5 wrapper compilers find_program( HDF5_C_COMPILER_EXECUTABLE NAMES h5cc h5pcc - HINTS ENV HDF5_ROOT + HINTS "${HDF5_ROOT}" ENV HDF5_ROOT PATH_SUFFIXES bin Bin DOC "HDF5 Wrapper compiler. Used only to detect HDF5 compile flags." ) mark_as_advanced( HDF5_C_COMPILER_EXECUTABLE ) find_program( HDF5_CXX_COMPILER_EXECUTABLE NAMES h5c++ h5pc++ - HINTS ENV HDF5_ROOT + HINTS "${HDF5_ROOT}" ENV HDF5_ROOT PATH_SUFFIXES bin Bin DOC "HDF5 C++ Wrapper compiler. Used only to detect HDF5 compile flags." ) mark_as_advanced( HDF5_CXX_COMPILER_EXECUTABLE ) find_program( HDF5_DIFF_EXECUTABLE NAMES h5diff - HINTS ENV HDF5_ROOT + HINTS "${HDF5_ROOT}" ENV HDF5_ROOT PATH_SUFFIXES bin Bin DOC "HDF5 file differencing tool." ) mark_as_advanced( HDF5_DIFF_EXECUTABLE ) @@ -200,6 +201,7 @@ else() # find the HDF5 include directories find_path( HDF5_${LANGUAGE}_INCLUDE_DIR hdf5.h HINTS + "${HDF5_ROOT}" ${HDF5_${LANGUAGE}_INCLUDE_FLAGS} ENV HDF5_ROOT @@ -232,12 +234,12 @@ else() endif() find_library( HDF5_${LIB}_LIBRARY_DEBUG NAMES ${THIS_LIBRARY_SEARCH_DEBUG} - HINTS ${HDF5_${LANGUAGE}_LIBRARY_DIRS} + HINTS "${HDF5_ROOT}" ${HDF5_${LANGUAGE}_LIBRARY_DIRS} ENV HDF5_ROOT PATH_SUFFIXES lib Lib ) find_library( HDF5_${LIB}_LIBRARY_RELEASE NAMES ${THIS_LIBRARY_SEARCH_RELEASE} - HINTS ${HDF5_${LANGUAGE}_LIBRARY_DIRS} + HINTS "${HDF5_ROOT}" ${HDF5_${LANGUAGE}_LIBRARY_DIRS} ENV HDF5_ROOT PATH_SUFFIXES lib Lib ) select_library_configurations( HDF5_${LIB} ) From 08499af805a4d3edc6b3140869ef3c28f466fc84 Mon Sep 17 00:00:00 2001 From: Matthew Gidden Date: Thu, 23 Apr 2015 11:19:12 -0500 Subject: [PATCH 23/80] early exit on failure --- .travis-install.sh | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/.travis-install.sh b/.travis-install.sh index 0ab998f721..46059223a9 100755 --- a/.travis-install.sh +++ b/.travis-install.sh @@ -2,4 +2,11 @@ wget https://github.com/gidden/ciclus/archive/travis.zip -O ciclus.zip unzip -j ciclus.zip "*/cycamore/*" -d conda-recipe sed -i "s/- cyclus/- cyclus 0.0/g" conda-recipe/meta.yaml conda build --no-test conda-recipe -conda install --use-local cycamore=0.0 \ No newline at end of file + +if [[ $? != 0 ]]; then + exit $? + +conda install --use-local cycamore=0.0 + +if [[ $? != 0 ]]; then + exit $? From 690a9153ffddd6ecc145dbb9e46ba2813939b3a5 Mon Sep 17 00:00:00 2001 From: Matthew Gidden Date: Thu, 23 Apr 2015 11:19:37 -0500 Subject: [PATCH 24/80] Revert "Squashing commits from cyclus/cycamore#301. This should fail on CI." This reverts commit 4f25661c7fe06f815000ea851fa0a9d127678335. --- src/CMakeLists.txt | 2 - src/foo.cc | 171 ------------------------------------- src/foo.h | 204 --------------------------------------------- src/foo_tests.cc | 204 --------------------------------------------- src/foo_tests.h | 34 -------- 5 files changed, 615 deletions(-) delete mode 100644 src/foo.cc delete mode 100644 src/foo.h delete mode 100644 src/foo_tests.cc delete mode 100644 src/foo_tests.h diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 0f0ef9eea2..5701534c73 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -10,8 +10,6 @@ USE_CYCLUS("cycamore" "sink") USE_CYCLUS("cycamore" "source") -USE_CYCLUS("cycamore" "foo") - USE_CYCLUS("cycamore" "deploy_inst") USE_CYCLUS("cycamore" "manager_inst") diff --git a/src/foo.cc b/src/foo.cc deleted file mode 100644 index 9ad8ada201..0000000000 --- a/src/foo.cc +++ /dev/null @@ -1,171 +0,0 @@ -#include "foo.h" - -#include -#include - -#include - -namespace cycamore { - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Foo::Foo(cyclus::Context* ctx) - : cyclus::Facility(ctx), - out_commod(""), - recipe_name(""), - capacity(std::numeric_limits::max()) {} - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Foo::~Foo() {} - -#pragma cyclus def clone cycamore::Foo - -#pragma cyclus def schema cycamore::Foo - -#pragma cyclus def annotations cycamore::Foo - -#pragma cyclus def infiletodb cycamore::Foo - -#pragma cyclus def snapshot cycamore::Foo - -#pragma cyclus def snapshotinv cycamore::Foo - -#pragma cyclus def initinv cycamore::Foo - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void Foo::InitFrom(Foo* m) { - #pragma cyclus impl initfromcopy cycamore::Foo - cyclus::toolkit::CommodityProducer::Copy(m); -} - -void Foo::InitFrom(cyclus::QueryableBackend* b) { - #pragma cyclus impl initfromdb cycamore::Foo - - commod_ = cyclus::toolkit::Commodity(out_commod); - cyclus::toolkit::CommodityProducer::Add(commod_); - cyclus::toolkit::CommodityProducer::SetCapacity(commod_, capacity); - cyclus::toolkit::CommodityProducer::SetCost(commod_, capacity); -} - -void Foo::EnterNotify() { - Facility::EnterNotify(); - commod_ = cyclus::toolkit::Commodity(out_commod); - cyclus::toolkit::CommodityProducer::Add(commod_); - cyclus::toolkit::CommodityProducer::SetCapacity(commod_, capacity); - cyclus::toolkit::CommodityProducer::SetCost(commod_, capacity); -} - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -std::string Foo::str() { - std::stringstream ss; - std::string ans; - if (cyclus::toolkit::CommodityProducer:: - Produces(cyclus::toolkit::Commodity(out_commod))) { - ans = "yes"; - } else { - ans = "no"; - } - ss << cyclus::Facility::str() - << " supplies commodity '" - << out_commod << "' with recipe '" - << recipe_name << "' at a capacity of " - << capacity << " kg per time step " - << " commod producer members: " << " produces " - << out_commod << "?: " << ans - << " capacity: " << cyclus::toolkit::CommodityProducer::Capacity(commod_) - << " cost: " << cyclus::toolkit::CommodityProducer::Cost(commod_); - return ss.str(); -} - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void Foo::Tick() { - LOG(cyclus::LEV_INFO3, "SrcFac") << prototype() << " is ticking {"; - LOG(cyclus::LEV_INFO4, "SrcFac") << "will offer " << capacity - << " kg of " - << out_commod << "."; - LOG(cyclus::LEV_INFO3, "SrcFac") << "Stats: " << str(); - LOG(cyclus::LEV_INFO3, "SrcFac") << "}"; - current_capacity = capacity; // reset capacity -} - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void Foo::Tock() { - LOG(cyclus::LEV_INFO3, "SrcFac") << prototype() << " is tocking {"; - LOG(cyclus::LEV_INFO3, "SrcFac") << "}"; -} - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -cyclus::Material::Ptr Foo::GetOffer( - const cyclus::Material::Ptr target) const { - using cyclus::Material; - double qty = std::min(target->quantity(), capacity); - return Material::CreateUntracked(qty, context()->GetRecipe(recipe_name)); -} - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -std::set::Ptr> -Foo::GetMatlBids( - cyclus::CommodMap::type& commod_requests) { - using cyclus::Bid; - using cyclus::BidPortfolio; - using cyclus::CapacityConstraint; - using cyclus::Material; - using cyclus::Request; - - std::set::Ptr> ports; - - if (commod_requests.count(out_commod) > 0) { - BidPortfolio::Ptr port(new BidPortfolio()); - - std::vector*>& requests = - commod_requests[out_commod]; - - std::vector*>::iterator it; - for (it = requests.begin(); it != requests.end(); ++it) { - Request* req = *it; - Material::Ptr offer = GetOffer(req->target()); - port->AddBid(req, offer, this); - } - - CapacityConstraint cc(capacity); - port->AddConstraint(cc); - ports.insert(port); - } - return ports; -} - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void Foo::GetMatlTrades( - const std::vector< cyclus::Trade >& trades, - std::vector, - cyclus::Material::Ptr> >& responses) { - using cyclus::Material; - using cyclus::Trade; - - double provided = 0; - std::vector< cyclus::Trade >::const_iterator it; - for (it = trades.begin(); it != trades.end(); ++it) { - double qty = it->amt; - current_capacity -= qty; - provided += qty; - // @TODO we need a policy on negatives.. - Material::Ptr response = Material::Create(this, qty, - context()->GetRecipe(recipe_name)); - responses.push_back(std::make_pair(*it, response)); - LOG(cyclus::LEV_INFO5, "SrcFac") << prototype() << " just received an order" - << " for " << qty - << " of " << out_commod; - } - if (cyclus::IsNegative(current_capacity)) { - std::stringstream ss; - ss << "is being asked to provide " << provided - << " but its capacity is " << capacity << "."; - throw cyclus::ValueError(Agent::InformErrorMsg(ss.str())); - } -} - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -extern "C" cyclus::Agent* ConstructFoo(cyclus::Context* ctx) { - return new Foo(ctx); -} - -} // namespace cycamore diff --git a/src/foo.h b/src/foo.h deleted file mode 100644 index e35ab83d99..0000000000 --- a/src/foo.h +++ /dev/null @@ -1,204 +0,0 @@ -#ifndef CYCAMORE_SRC_FOO_H_ -#define CYCAMORE_SRC_FOO_H_ - -#include -#include - -#include "cyclus.h" - -namespace cycamore { - -class Context; - -/// @class Foo -/// This cyclus::Facility provides a simple source of some capacity -/// (possibly infinite) of some commodity/Recipe. - -/// The Foo class inherits from the cyclus::Facility class and is -/// dynamically loaded by the Agent class when requested. - -/// @section introduction Introduction -/// The Foo is a facility type in Cyclus capable of providing -/// a finite or infinite.Supply of a particular material to the -/// simulation. A Foo generates material of a certain -/// composition and commodity type, then offers that material on the -/// appropriate market. Shipments of this material are executed when the -/// market issues an order that the offer has been matched with a -/// request. - -/// @section agentparams Agent Parameters -/// Foo behavior is comprehensively defined by the following -/// parameters: -/// - double capacity: The production capacity of the facility (units -/// vary, but typically kg/month). Capacity is infinite if a negative -/// value is provided. -/// - int startDate: The date on which the facility begins to operate -/// (months). -/// - int lifeTime: The length of time that the facility operates -/// (months). - std::string outCommod: the commodity that this facility -/// produces - double inventorysize: the maximum quantity of material to -/// be held in the inventory -/// - double commodprice: the price of the output material PER UNIT -/// - map outComp - -/// @section optionalparams Optional Parameters -/// Foo behavior may also be specified with the following -/// optional parameters which have default values listed here. -/// - double capacityFactor: The ratio of actual production capacity to -/// the rated production capacity. Default is 1 (actual/rated). -/// - double availFactor: The percent of time the facility operates at -/// its capacity factor. Default is 100%. -/// - double capitalCost: The cost of constructing and commissioning -/// this facility. Default is 0 ($). -/// - double opCost: The annual cost of operation and maintenance of -/// this facility. Default is 0 ( $/year). -/// - int constrTime: The number of months it takes to construct and -/// commission this facility. Default is 0 (months). -/// - int decomTime: The number of months it takes to deconstruct and -/// decommission this facility. Default is 0 (months). -/// - Inst* inst: The institution responsible for this facility. -/// - string name: A non-generic name for this facility. - -/// @section detailed Detailed Behavior -/// @subsection finite If Finite Capacity: -/// The Foo starts operation when the simulation reaches the -/// month specified as the startDate. It immediately begins to produce -/// material at the rate defined by its capacity. Each month the -/// Foo adds the amount it has produced to its inventory. It -/// then offers to the appropriate market exactly as much material as it -/// has in its inventory. If an offer is matched with a request, the -/// Foo executes that order by subtracting the quantity from -/// its inventory and sending that amount to the requesting facility. -/// When the simulation time equals the startDate plus the lifeTime, the -/// facility ceases to operate. -/// @subsection infinite If Infinite Capacity: -/// The Foo starts operation when the simulation reaches the -/// month specified as the startDate. Each month the Foo -/// offers an infinite amount of material to the appropriate market. If -/// there is a request for that material, the Foo executes -/// that order by sending that amount to the requesting facility. When -/// the simulation time equals the startDate plus the lifeTime, the -/// facility ceases to operate. - -/// @subsection question Question: -/// What is the best way to allow offers of an infinite amount of -/// material on a market? - -class Foo : public cyclus::Facility, - public cyclus::toolkit::CommodityProducer { - public: - // --- Module Members --- - /// Constructor for the Foo class - /// @param ctx the cyclus context for access to simulation-wide parameters - Foo(cyclus::Context* ctx); - - virtual ~Foo() - - #pragma cyclus decl - - #pragma cyclus note {"doc": "A source facility that provides a " \ - "commodity with a given capacity"} - - /// Print information about this agent - virtual std::string str(); - // --- - - // --- Agent Members --- - virtual void EnterNotify(); - - /// Each facility is prompted to do its beginning-of-time-step - /// stuff at the tick of the timer. - - /// @param time is the time to perform the tick - virtual void Tick(); - - /// Each facility is prompted to its end-of-time-step - /// stuff on the tock of the timer. - - /// @param time is the time to perform the tock - virtual void Tock(); - - /// @brief Responds to each request for this source facility's commodity. - /// If a given request is more than this facility's capacity, it will offer - /// its capacity. - virtual std::set::Ptr> - GetMatlBids(cyclus::CommodMap::type& - commod_requests); - - /// @brief respond to each trade with a material made from this facility's - /// recipe - /// - /// @param trades all trades in which this trader is the supplier - /// @param responses a container to populate with responses to each trade - virtual void GetMatlTrades( - const std::vector< cyclus::Trade >& trades, - std::vector, - cyclus::Material::Ptr> >& responses); - // --- - - // --- Foo Members --- - /// @brief creates a material object to offer to a requester - /// @param target the material target a request desires - cyclus::Material::Ptr GetOffer(const cyclus::Material::Ptr target) const; - - /// sets the output commodity name - /// @param name the commodity name - inline void commodity(std::string name) { out_commod = name; } - - /// @return the output commodity - inline std::string commodity() const { return out_commod; } - - /// sets the capacity of a material generated at any given time step - /// @param capacity the production capacity - inline void Capacity(double cap) { - capacity = cap; - current_capacity = capacity; - } - - /// @return the production capacity at any given time step - inline double Capacity() const { return capacity; } - - /// sets the name of the recipe to be produced - /// @param name the recipe name - inline void recipe(std::string name) { recipe_name = name; } - - /// @return the name of the output recipe - inline std::string recipe() const { return recipe_name; } - - /// @return the current timestep's capacity - inline double CurrentCapacity() const { return current_capacity; } - - private: - cyclus::toolkit::Commodity commod_; - - /// This facility has only one output commodity - #pragma cyclus var {"tooltip": "source output commodity", \ - "doc": "output commodity that the source facility " \ - "supplies", \ - "uitype": "outcommodity"} - std::string out_commod; - - /// Name of the recipe this facility uses. - #pragma cyclus var {"tooltip": "commodity recipe name", \ - "doc": "recipe name for source facility's commodity", \ - "uitype": "recipe"} - std::string recipe_name; - - /// The capacity is defined in terms of the number of units of the - /// recipe that can be provided each time step. A very large number - /// can be provided to represent infinte capacity. - #pragma cyclus var {"default": 1e299, "tooltip": "source capacity", \ - "doc": "amount of commodity that can be supplied " \ - "at each time step"} - double capacity; - - /// The capacity at the current time step - #pragma cyclus var {'derived_init': 'current_capacity = capacity;'} - double current_capacity; - - // --- -}; - -} // namespace cycamore - -#endif // CYCAMORE_SRC_FOO_H_ diff --git a/src/foo_tests.cc b/src/foo_tests.cc deleted file mode 100644 index 0973e794d0..0000000000 --- a/src/foo_tests.cc +++ /dev/null @@ -1,204 +0,0 @@ -#include "foo_tests.h" - -#include - -#include - -#include "cyc_limits.h" -#include "resource_helpers.h" -#include "test_context.h" - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void FooTest::SetUp() { - src_facility = new cycamore::Foo(tc.get()); - trader = tc.trader(); - InitParameters(); - SetUpFoo(); -} - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void FooTest::TearDown() { - delete src_facility; -} - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void FooTest::InitParameters() { - commod = "commod"; - recipe_name = "recipe"; - capacity = 5; // some magic number.. - - recipe = cyclus::Composition::CreateFromAtom(cyclus::CompMap()); - tc.get()->AddRecipe(recipe_name, recipe); -} - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void FooTest::SetUpFoo() { - src_facility->commodity(commod); - src_facility->recipe(recipe_name); - src_facility->Capacity(capacity); -} - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -TEST_F(FooTest, InitialState) { - EXPECT_EQ(src_facility->Capacity(), capacity); - EXPECT_EQ(src_facility->commodity(), commod); - EXPECT_EQ(src_facility->recipe(), recipe_name); - EXPECT_EQ(src_facility->CurrentCapacity(), capacity); -} - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -TEST_F(FooTest, Clone) { - cyclus::Context* ctx = tc.get(); - cycamore::Foo* cloned_fac = dynamic_cast - (src_facility->Clone()); - - EXPECT_EQ(src_facility->commodity(), cloned_fac->commodity()); - EXPECT_EQ(src_facility->Capacity(), cloned_fac->Capacity()); - EXPECT_EQ(src_facility->recipe(), cloned_fac->recipe()); - EXPECT_EQ(src_facility->Capacity(), cloned_fac->CurrentCapacity()); - - delete cloned_fac; -} - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -TEST_F(FooTest, Print) { - EXPECT_NO_THROW(std::string s = src_facility->str()); -} - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -TEST_F(FooTest, GetOffer) { - using cyclus::Material; - - double qty = capacity - 1; - Material::Ptr mat = cyclus::NewBlankMaterial(qty); - Material::Ptr obs_mat = src_facility->GetOffer(mat); - EXPECT_EQ(obs_mat->quantity(), qty); - EXPECT_EQ(obs_mat->comp(), recipe); - - qty = capacity + 1; - mat = cyclus::NewBlankMaterial(qty); - obs_mat = src_facility->GetOffer(mat); - EXPECT_EQ(obs_mat->quantity(), capacity); - EXPECT_EQ(obs_mat->comp(), recipe); - - qty = capacity; - mat = cyclus::NewBlankMaterial(qty); - obs_mat = src_facility->GetOffer(mat); - EXPECT_EQ(obs_mat->quantity(), capacity); - EXPECT_EQ(obs_mat->comp(), recipe); -} - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -TEST_F(FooTest, AddBids) { - using cyclus::Bid; - using cyclus::BidPortfolio; - using cyclus::CapacityConstraint; - using cyclus::ExchangeContext; - using cyclus::Material; - - int nreqs = 5; - - boost::shared_ptr< cyclus::ExchangeContext > - ec = GetContext(nreqs, commod); - - std::set::Ptr> ports = - src_facility->GetMatlBids(ec.get()->commod_requests); - - ASSERT_TRUE(ports.size() > 0); - EXPECT_EQ(ports.size(), 1); - - BidPortfolio::Ptr port = *ports.begin(); - EXPECT_EQ(port->bidder(), src_facility); - EXPECT_EQ(port->bids().size(), nreqs); - - const std::set< CapacityConstraint >& constrs = port->constraints(); - ASSERT_TRUE(constrs.size() > 0); - EXPECT_EQ(constrs.size(), 1); - EXPECT_EQ(*constrs.begin(), CapacityConstraint(capacity)); -} - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -TEST_F(FooTest, Response) { - using cyclus::Bid; - using cyclus::Material; - using cyclus::Request; - using cyclus::Trade; - using test_helpers::get_mat; - - std::vector< cyclus::Trade > trades; - std::vector, - cyclus::Material::Ptr> > responses; - - // Null response - EXPECT_NO_THROW(src_facility->GetMatlTrades(trades, responses)); - EXPECT_EQ(responses.size(), 0); - - double qty = capacity / 3; - Request* request = - Request::Create(get_mat(), trader, commod); - Bid* bid = - Bid::Create(request, get_mat(), src_facility); - - Trade trade(request, bid, qty); - trades.push_back(trade); - - // 1 trade - ASSERT_EQ(src_facility->CurrentCapacity(), capacity); - src_facility->GetMatlTrades(trades, responses); - EXPECT_EQ(responses.size(), 1); - EXPECT_EQ(responses[0].second->quantity(), qty); - EXPECT_EQ(responses[0].second->comp(), recipe); - - // 2 trades, total qty = capacity - ASSERT_DOUBLE_EQ(src_facility->CurrentCapacity(), capacity - qty); - ASSERT_GT(src_facility->CurrentCapacity() - 2 * qty, -1 * cyclus::eps()); - trades.push_back(trade); - responses.clear(); - EXPECT_NO_THROW(src_facility->GetMatlTrades(trades, responses)); - EXPECT_EQ(responses.size(), 2); - ASSERT_TRUE(cyclus::AlmostEq(src_facility->CurrentCapacity(), 0)); - - // too much qty, capn! - EXPECT_THROW(src_facility->GetMatlTrades(trades, responses), - cyclus::ValueError); - - // reset! - src_facility->Tick(); - ASSERT_DOUBLE_EQ(src_facility->CurrentCapacity(), capacity); - - delete request; - delete bid; -} - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -boost::shared_ptr< cyclus::ExchangeContext > -FooTest::GetContext(int nreqs, std::string commod) { - using cyclus::Material; - using cyclus::Request; - using cyclus::ExchangeContext; - using test_helpers::get_mat; - - double qty = 3; - boost::shared_ptr< ExchangeContext > - ec(new ExchangeContext()); - for (int i = 0; i < nreqs; i++) { - ec->AddRequest(Request::Create(get_mat(), trader, commod)); - } - return ec; -} - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -cyclus::Agent* FooConstructor(cyclus::Context* ctx) { - return new cycamore::Foo(ctx); -} - -// required to get functionality in cyclus agent unit tests library -#ifndef CYCLUS_AGENT_TESTS_CONNECTED -int ConnectAgentTests(); -static int cyclus_agent_tests_connected = ConnectAgentTests(); -#define CYCLUS_AGENT_TESTS_CONNECTED cyclus_agent_tests_connected -#endif // CYCLUS_AGENT_TESTS_CONNECTED - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -INSTANTIATE_TEST_CASE_P(FooFac, FacilityTests, Values(&FooConstructor)); -INSTANTIATE_TEST_CASE_P(FooFac, AgentTests, Values(&FooConstructor)); diff --git a/src/foo_tests.h b/src/foo_tests.h deleted file mode 100644 index 59888926b7..0000000000 --- a/src/foo_tests.h +++ /dev/null @@ -1,34 +0,0 @@ -#ifndef CYCAMORE_SRC_FOO_TESTS_H_ -#define CYCAMORE_SRC_FOO_TESTS_H_ -#include "foo.h" - -#include - -#include - -#include "agent_tests.h" -#include "context.h" -#include "exchange_context.h" -#include "facility_tests.h" -#include "material.h" - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -class FooTest : public ::testing::Test { - public: - cyclus::TestContext tc; - TestFacility* trader; - cycamore::Foo* src_facility; - std::string commod, recipe_name; - double capacity; - cyclus::Composition::Ptr recipe; - - virtual void SetUp(); - virtual void TearDown(); - void InitParameters(); - void SetUpFoo(); - - boost::shared_ptr< cyclus::ExchangeContext > - GetContext(int nreqs, std::string commodity); -}; - -#endif // CYCAMORE_SRC_FOO_TESTS_H_ From cdf4ab29ed9511ee7db06f9ecf3c7dd56f4fd3c5 Mon Sep 17 00:00:00 2001 From: Matthew Gidden Date: Thu, 23 Apr 2015 11:38:35 -0500 Subject: [PATCH 25/80] explicit status var --- .travis-install.sh | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/.travis-install.sh b/.travis-install.sh index 46059223a9..40e99c99c5 100755 --- a/.travis-install.sh +++ b/.travis-install.sh @@ -3,10 +3,12 @@ unzip -j ciclus.zip "*/cycamore/*" -d conda-recipe sed -i "s/- cyclus/- cyclus 0.0/g" conda-recipe/meta.yaml conda build --no-test conda-recipe -if [[ $? != 0 ]]; then - exit $? +status=$? +if [[ $status != 0 ]]; then + exit $status conda install --use-local cycamore=0.0 -if [[ $? != 0 ]]; then - exit $? +status=$? +if [[ $status != 0 ]]; then + exit $status From 9891a950edf4cfb428825aa75cb4feb43424ae37 Mon Sep 17 00:00:00 2001 From: Matthew Gidden Date: Thu, 23 Apr 2015 12:09:19 -0500 Subject: [PATCH 26/80] fixed syntax errors added logging --- .travis-install.sh | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/.travis-install.sh b/.travis-install.sh index 40e99c99c5..1e53559839 100755 --- a/.travis-install.sh +++ b/.travis-install.sh @@ -1,14 +1,26 @@ +#!/bin/bash + +# setup conda recipe wget https://github.com/gidden/ciclus/archive/travis.zip -O ciclus.zip unzip -j ciclus.zip "*/cycamore/*" -d conda-recipe sed -i "s/- cyclus/- cyclus 0.0/g" conda-recipe/meta.yaml -conda build --no-test conda-recipe +# build +cmd="conda build --no-test conda-recipe" +echo "cmd: $cmd" +$cmd status=$? +echo "status: $status" if [[ $status != 0 ]]; then exit $status +fi -conda install --use-local cycamore=0.0 - +# install +cmd="conda install --use-local cycamore=0.0" +echo "cmd: $cmd" +$cmd status=$? +echo "status: $status" if [[ $status != 0 ]]; then exit $status +fi From 42fea0add138d2d30b182dae84f9468b85594aa7 Mon Sep 17 00:00:00 2001 From: Matthew Gidden Date: Thu, 23 Apr 2015 12:45:13 -0500 Subject: [PATCH 27/80] should fail --- src/reactor_tests.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/reactor_tests.cc b/src/reactor_tests.cc index 8c743e5cf4..7ba33e8cc0 100644 --- a/src/reactor_tests.cc +++ b/src/reactor_tests.cc @@ -131,7 +131,7 @@ TEST(ReactorTests, RefuelTimes) { QueryResult qr = sim.db().Query("Transactions", NULL); int cyclet = 4; - int refuelt = 3; + int refuelt = 2; int n_assem_want = simdur/(cyclet+refuelt)+1; // +1 for initial core EXPECT_EQ(n_assem_want, qr.rows.size()); } From ee2eab2d9766383352cca7bcac82a69db0c4b58b Mon Sep 17 00:00:00 2001 From: Matthew Gidden Date: Thu, 23 Apr 2015 12:45:21 -0500 Subject: [PATCH 28/80] Revert "should fail" This reverts commit 42fea0add138d2d30b182dae84f9468b85594aa7. --- src/reactor_tests.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/reactor_tests.cc b/src/reactor_tests.cc index 7ba33e8cc0..8c743e5cf4 100644 --- a/src/reactor_tests.cc +++ b/src/reactor_tests.cc @@ -131,7 +131,7 @@ TEST(ReactorTests, RefuelTimes) { QueryResult qr = sim.db().Query("Transactions", NULL); int cyclet = 4; - int refuelt = 2; + int refuelt = 3; int n_assem_want = simdur/(cyclet+refuelt)+1; // +1 for initial core EXPECT_EQ(n_assem_want, qr.rows.size()); } From 3bb92b3be3c5ccf879bc11c9c50243ab1a206bf0 Mon Sep 17 00:00:00 2001 From: Robert Carlsen Date: Tue, 17 Feb 2015 12:50:14 -0600 Subject: [PATCH 29/80] Squashing commits from cyclus/cycamore#301. This should fail on CI. --- src/CMakeLists.txt | 2 + src/foo.cc | 171 +++++++++++++++++++++++++++++++++++++ src/foo.h | 204 +++++++++++++++++++++++++++++++++++++++++++++ src/foo_tests.cc | 204 +++++++++++++++++++++++++++++++++++++++++++++ src/foo_tests.h | 34 ++++++++ 5 files changed, 615 insertions(+) create mode 100644 src/foo.cc create mode 100644 src/foo.h create mode 100644 src/foo_tests.cc create mode 100644 src/foo_tests.h diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 5701534c73..0f0ef9eea2 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -10,6 +10,8 @@ USE_CYCLUS("cycamore" "sink") USE_CYCLUS("cycamore" "source") +USE_CYCLUS("cycamore" "foo") + USE_CYCLUS("cycamore" "deploy_inst") USE_CYCLUS("cycamore" "manager_inst") diff --git a/src/foo.cc b/src/foo.cc new file mode 100644 index 0000000000..9ad8ada201 --- /dev/null +++ b/src/foo.cc @@ -0,0 +1,171 @@ +#include "foo.h" + +#include +#include + +#include + +namespace cycamore { + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +Foo::Foo(cyclus::Context* ctx) + : cyclus::Facility(ctx), + out_commod(""), + recipe_name(""), + capacity(std::numeric_limits::max()) {} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +Foo::~Foo() {} + +#pragma cyclus def clone cycamore::Foo + +#pragma cyclus def schema cycamore::Foo + +#pragma cyclus def annotations cycamore::Foo + +#pragma cyclus def infiletodb cycamore::Foo + +#pragma cyclus def snapshot cycamore::Foo + +#pragma cyclus def snapshotinv cycamore::Foo + +#pragma cyclus def initinv cycamore::Foo + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +void Foo::InitFrom(Foo* m) { + #pragma cyclus impl initfromcopy cycamore::Foo + cyclus::toolkit::CommodityProducer::Copy(m); +} + +void Foo::InitFrom(cyclus::QueryableBackend* b) { + #pragma cyclus impl initfromdb cycamore::Foo + + commod_ = cyclus::toolkit::Commodity(out_commod); + cyclus::toolkit::CommodityProducer::Add(commod_); + cyclus::toolkit::CommodityProducer::SetCapacity(commod_, capacity); + cyclus::toolkit::CommodityProducer::SetCost(commod_, capacity); +} + +void Foo::EnterNotify() { + Facility::EnterNotify(); + commod_ = cyclus::toolkit::Commodity(out_commod); + cyclus::toolkit::CommodityProducer::Add(commod_); + cyclus::toolkit::CommodityProducer::SetCapacity(commod_, capacity); + cyclus::toolkit::CommodityProducer::SetCost(commod_, capacity); +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +std::string Foo::str() { + std::stringstream ss; + std::string ans; + if (cyclus::toolkit::CommodityProducer:: + Produces(cyclus::toolkit::Commodity(out_commod))) { + ans = "yes"; + } else { + ans = "no"; + } + ss << cyclus::Facility::str() + << " supplies commodity '" + << out_commod << "' with recipe '" + << recipe_name << "' at a capacity of " + << capacity << " kg per time step " + << " commod producer members: " << " produces " + << out_commod << "?: " << ans + << " capacity: " << cyclus::toolkit::CommodityProducer::Capacity(commod_) + << " cost: " << cyclus::toolkit::CommodityProducer::Cost(commod_); + return ss.str(); +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +void Foo::Tick() { + LOG(cyclus::LEV_INFO3, "SrcFac") << prototype() << " is ticking {"; + LOG(cyclus::LEV_INFO4, "SrcFac") << "will offer " << capacity + << " kg of " + << out_commod << "."; + LOG(cyclus::LEV_INFO3, "SrcFac") << "Stats: " << str(); + LOG(cyclus::LEV_INFO3, "SrcFac") << "}"; + current_capacity = capacity; // reset capacity +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +void Foo::Tock() { + LOG(cyclus::LEV_INFO3, "SrcFac") << prototype() << " is tocking {"; + LOG(cyclus::LEV_INFO3, "SrcFac") << "}"; +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +cyclus::Material::Ptr Foo::GetOffer( + const cyclus::Material::Ptr target) const { + using cyclus::Material; + double qty = std::min(target->quantity(), capacity); + return Material::CreateUntracked(qty, context()->GetRecipe(recipe_name)); +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +std::set::Ptr> +Foo::GetMatlBids( + cyclus::CommodMap::type& commod_requests) { + using cyclus::Bid; + using cyclus::BidPortfolio; + using cyclus::CapacityConstraint; + using cyclus::Material; + using cyclus::Request; + + std::set::Ptr> ports; + + if (commod_requests.count(out_commod) > 0) { + BidPortfolio::Ptr port(new BidPortfolio()); + + std::vector*>& requests = + commod_requests[out_commod]; + + std::vector*>::iterator it; + for (it = requests.begin(); it != requests.end(); ++it) { + Request* req = *it; + Material::Ptr offer = GetOffer(req->target()); + port->AddBid(req, offer, this); + } + + CapacityConstraint cc(capacity); + port->AddConstraint(cc); + ports.insert(port); + } + return ports; +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +void Foo::GetMatlTrades( + const std::vector< cyclus::Trade >& trades, + std::vector, + cyclus::Material::Ptr> >& responses) { + using cyclus::Material; + using cyclus::Trade; + + double provided = 0; + std::vector< cyclus::Trade >::const_iterator it; + for (it = trades.begin(); it != trades.end(); ++it) { + double qty = it->amt; + current_capacity -= qty; + provided += qty; + // @TODO we need a policy on negatives.. + Material::Ptr response = Material::Create(this, qty, + context()->GetRecipe(recipe_name)); + responses.push_back(std::make_pair(*it, response)); + LOG(cyclus::LEV_INFO5, "SrcFac") << prototype() << " just received an order" + << " for " << qty + << " of " << out_commod; + } + if (cyclus::IsNegative(current_capacity)) { + std::stringstream ss; + ss << "is being asked to provide " << provided + << " but its capacity is " << capacity << "."; + throw cyclus::ValueError(Agent::InformErrorMsg(ss.str())); + } +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +extern "C" cyclus::Agent* ConstructFoo(cyclus::Context* ctx) { + return new Foo(ctx); +} + +} // namespace cycamore diff --git a/src/foo.h b/src/foo.h new file mode 100644 index 0000000000..e35ab83d99 --- /dev/null +++ b/src/foo.h @@ -0,0 +1,204 @@ +#ifndef CYCAMORE_SRC_FOO_H_ +#define CYCAMORE_SRC_FOO_H_ + +#include +#include + +#include "cyclus.h" + +namespace cycamore { + +class Context; + +/// @class Foo +/// This cyclus::Facility provides a simple source of some capacity +/// (possibly infinite) of some commodity/Recipe. + +/// The Foo class inherits from the cyclus::Facility class and is +/// dynamically loaded by the Agent class when requested. + +/// @section introduction Introduction +/// The Foo is a facility type in Cyclus capable of providing +/// a finite or infinite.Supply of a particular material to the +/// simulation. A Foo generates material of a certain +/// composition and commodity type, then offers that material on the +/// appropriate market. Shipments of this material are executed when the +/// market issues an order that the offer has been matched with a +/// request. + +/// @section agentparams Agent Parameters +/// Foo behavior is comprehensively defined by the following +/// parameters: +/// - double capacity: The production capacity of the facility (units +/// vary, but typically kg/month). Capacity is infinite if a negative +/// value is provided. +/// - int startDate: The date on which the facility begins to operate +/// (months). +/// - int lifeTime: The length of time that the facility operates +/// (months). - std::string outCommod: the commodity that this facility +/// produces - double inventorysize: the maximum quantity of material to +/// be held in the inventory +/// - double commodprice: the price of the output material PER UNIT +/// - map outComp + +/// @section optionalparams Optional Parameters +/// Foo behavior may also be specified with the following +/// optional parameters which have default values listed here. +/// - double capacityFactor: The ratio of actual production capacity to +/// the rated production capacity. Default is 1 (actual/rated). +/// - double availFactor: The percent of time the facility operates at +/// its capacity factor. Default is 100%. +/// - double capitalCost: The cost of constructing and commissioning +/// this facility. Default is 0 ($). +/// - double opCost: The annual cost of operation and maintenance of +/// this facility. Default is 0 ( $/year). +/// - int constrTime: The number of months it takes to construct and +/// commission this facility. Default is 0 (months). +/// - int decomTime: The number of months it takes to deconstruct and +/// decommission this facility. Default is 0 (months). +/// - Inst* inst: The institution responsible for this facility. +/// - string name: A non-generic name for this facility. + +/// @section detailed Detailed Behavior +/// @subsection finite If Finite Capacity: +/// The Foo starts operation when the simulation reaches the +/// month specified as the startDate. It immediately begins to produce +/// material at the rate defined by its capacity. Each month the +/// Foo adds the amount it has produced to its inventory. It +/// then offers to the appropriate market exactly as much material as it +/// has in its inventory. If an offer is matched with a request, the +/// Foo executes that order by subtracting the quantity from +/// its inventory and sending that amount to the requesting facility. +/// When the simulation time equals the startDate plus the lifeTime, the +/// facility ceases to operate. +/// @subsection infinite If Infinite Capacity: +/// The Foo starts operation when the simulation reaches the +/// month specified as the startDate. Each month the Foo +/// offers an infinite amount of material to the appropriate market. If +/// there is a request for that material, the Foo executes +/// that order by sending that amount to the requesting facility. When +/// the simulation time equals the startDate plus the lifeTime, the +/// facility ceases to operate. + +/// @subsection question Question: +/// What is the best way to allow offers of an infinite amount of +/// material on a market? + +class Foo : public cyclus::Facility, + public cyclus::toolkit::CommodityProducer { + public: + // --- Module Members --- + /// Constructor for the Foo class + /// @param ctx the cyclus context for access to simulation-wide parameters + Foo(cyclus::Context* ctx); + + virtual ~Foo() + + #pragma cyclus decl + + #pragma cyclus note {"doc": "A source facility that provides a " \ + "commodity with a given capacity"} + + /// Print information about this agent + virtual std::string str(); + // --- + + // --- Agent Members --- + virtual void EnterNotify(); + + /// Each facility is prompted to do its beginning-of-time-step + /// stuff at the tick of the timer. + + /// @param time is the time to perform the tick + virtual void Tick(); + + /// Each facility is prompted to its end-of-time-step + /// stuff on the tock of the timer. + + /// @param time is the time to perform the tock + virtual void Tock(); + + /// @brief Responds to each request for this source facility's commodity. + /// If a given request is more than this facility's capacity, it will offer + /// its capacity. + virtual std::set::Ptr> + GetMatlBids(cyclus::CommodMap::type& + commod_requests); + + /// @brief respond to each trade with a material made from this facility's + /// recipe + /// + /// @param trades all trades in which this trader is the supplier + /// @param responses a container to populate with responses to each trade + virtual void GetMatlTrades( + const std::vector< cyclus::Trade >& trades, + std::vector, + cyclus::Material::Ptr> >& responses); + // --- + + // --- Foo Members --- + /// @brief creates a material object to offer to a requester + /// @param target the material target a request desires + cyclus::Material::Ptr GetOffer(const cyclus::Material::Ptr target) const; + + /// sets the output commodity name + /// @param name the commodity name + inline void commodity(std::string name) { out_commod = name; } + + /// @return the output commodity + inline std::string commodity() const { return out_commod; } + + /// sets the capacity of a material generated at any given time step + /// @param capacity the production capacity + inline void Capacity(double cap) { + capacity = cap; + current_capacity = capacity; + } + + /// @return the production capacity at any given time step + inline double Capacity() const { return capacity; } + + /// sets the name of the recipe to be produced + /// @param name the recipe name + inline void recipe(std::string name) { recipe_name = name; } + + /// @return the name of the output recipe + inline std::string recipe() const { return recipe_name; } + + /// @return the current timestep's capacity + inline double CurrentCapacity() const { return current_capacity; } + + private: + cyclus::toolkit::Commodity commod_; + + /// This facility has only one output commodity + #pragma cyclus var {"tooltip": "source output commodity", \ + "doc": "output commodity that the source facility " \ + "supplies", \ + "uitype": "outcommodity"} + std::string out_commod; + + /// Name of the recipe this facility uses. + #pragma cyclus var {"tooltip": "commodity recipe name", \ + "doc": "recipe name for source facility's commodity", \ + "uitype": "recipe"} + std::string recipe_name; + + /// The capacity is defined in terms of the number of units of the + /// recipe that can be provided each time step. A very large number + /// can be provided to represent infinte capacity. + #pragma cyclus var {"default": 1e299, "tooltip": "source capacity", \ + "doc": "amount of commodity that can be supplied " \ + "at each time step"} + double capacity; + + /// The capacity at the current time step + #pragma cyclus var {'derived_init': 'current_capacity = capacity;'} + double current_capacity; + + // --- +}; + +} // namespace cycamore + +#endif // CYCAMORE_SRC_FOO_H_ diff --git a/src/foo_tests.cc b/src/foo_tests.cc new file mode 100644 index 0000000000..0973e794d0 --- /dev/null +++ b/src/foo_tests.cc @@ -0,0 +1,204 @@ +#include "foo_tests.h" + +#include + +#include + +#include "cyc_limits.h" +#include "resource_helpers.h" +#include "test_context.h" + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +void FooTest::SetUp() { + src_facility = new cycamore::Foo(tc.get()); + trader = tc.trader(); + InitParameters(); + SetUpFoo(); +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +void FooTest::TearDown() { + delete src_facility; +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +void FooTest::InitParameters() { + commod = "commod"; + recipe_name = "recipe"; + capacity = 5; // some magic number.. + + recipe = cyclus::Composition::CreateFromAtom(cyclus::CompMap()); + tc.get()->AddRecipe(recipe_name, recipe); +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +void FooTest::SetUpFoo() { + src_facility->commodity(commod); + src_facility->recipe(recipe_name); + src_facility->Capacity(capacity); +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +TEST_F(FooTest, InitialState) { + EXPECT_EQ(src_facility->Capacity(), capacity); + EXPECT_EQ(src_facility->commodity(), commod); + EXPECT_EQ(src_facility->recipe(), recipe_name); + EXPECT_EQ(src_facility->CurrentCapacity(), capacity); +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +TEST_F(FooTest, Clone) { + cyclus::Context* ctx = tc.get(); + cycamore::Foo* cloned_fac = dynamic_cast + (src_facility->Clone()); + + EXPECT_EQ(src_facility->commodity(), cloned_fac->commodity()); + EXPECT_EQ(src_facility->Capacity(), cloned_fac->Capacity()); + EXPECT_EQ(src_facility->recipe(), cloned_fac->recipe()); + EXPECT_EQ(src_facility->Capacity(), cloned_fac->CurrentCapacity()); + + delete cloned_fac; +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +TEST_F(FooTest, Print) { + EXPECT_NO_THROW(std::string s = src_facility->str()); +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +TEST_F(FooTest, GetOffer) { + using cyclus::Material; + + double qty = capacity - 1; + Material::Ptr mat = cyclus::NewBlankMaterial(qty); + Material::Ptr obs_mat = src_facility->GetOffer(mat); + EXPECT_EQ(obs_mat->quantity(), qty); + EXPECT_EQ(obs_mat->comp(), recipe); + + qty = capacity + 1; + mat = cyclus::NewBlankMaterial(qty); + obs_mat = src_facility->GetOffer(mat); + EXPECT_EQ(obs_mat->quantity(), capacity); + EXPECT_EQ(obs_mat->comp(), recipe); + + qty = capacity; + mat = cyclus::NewBlankMaterial(qty); + obs_mat = src_facility->GetOffer(mat); + EXPECT_EQ(obs_mat->quantity(), capacity); + EXPECT_EQ(obs_mat->comp(), recipe); +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +TEST_F(FooTest, AddBids) { + using cyclus::Bid; + using cyclus::BidPortfolio; + using cyclus::CapacityConstraint; + using cyclus::ExchangeContext; + using cyclus::Material; + + int nreqs = 5; + + boost::shared_ptr< cyclus::ExchangeContext > + ec = GetContext(nreqs, commod); + + std::set::Ptr> ports = + src_facility->GetMatlBids(ec.get()->commod_requests); + + ASSERT_TRUE(ports.size() > 0); + EXPECT_EQ(ports.size(), 1); + + BidPortfolio::Ptr port = *ports.begin(); + EXPECT_EQ(port->bidder(), src_facility); + EXPECT_EQ(port->bids().size(), nreqs); + + const std::set< CapacityConstraint >& constrs = port->constraints(); + ASSERT_TRUE(constrs.size() > 0); + EXPECT_EQ(constrs.size(), 1); + EXPECT_EQ(*constrs.begin(), CapacityConstraint(capacity)); +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +TEST_F(FooTest, Response) { + using cyclus::Bid; + using cyclus::Material; + using cyclus::Request; + using cyclus::Trade; + using test_helpers::get_mat; + + std::vector< cyclus::Trade > trades; + std::vector, + cyclus::Material::Ptr> > responses; + + // Null response + EXPECT_NO_THROW(src_facility->GetMatlTrades(trades, responses)); + EXPECT_EQ(responses.size(), 0); + + double qty = capacity / 3; + Request* request = + Request::Create(get_mat(), trader, commod); + Bid* bid = + Bid::Create(request, get_mat(), src_facility); + + Trade trade(request, bid, qty); + trades.push_back(trade); + + // 1 trade + ASSERT_EQ(src_facility->CurrentCapacity(), capacity); + src_facility->GetMatlTrades(trades, responses); + EXPECT_EQ(responses.size(), 1); + EXPECT_EQ(responses[0].second->quantity(), qty); + EXPECT_EQ(responses[0].second->comp(), recipe); + + // 2 trades, total qty = capacity + ASSERT_DOUBLE_EQ(src_facility->CurrentCapacity(), capacity - qty); + ASSERT_GT(src_facility->CurrentCapacity() - 2 * qty, -1 * cyclus::eps()); + trades.push_back(trade); + responses.clear(); + EXPECT_NO_THROW(src_facility->GetMatlTrades(trades, responses)); + EXPECT_EQ(responses.size(), 2); + ASSERT_TRUE(cyclus::AlmostEq(src_facility->CurrentCapacity(), 0)); + + // too much qty, capn! + EXPECT_THROW(src_facility->GetMatlTrades(trades, responses), + cyclus::ValueError); + + // reset! + src_facility->Tick(); + ASSERT_DOUBLE_EQ(src_facility->CurrentCapacity(), capacity); + + delete request; + delete bid; +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +boost::shared_ptr< cyclus::ExchangeContext > +FooTest::GetContext(int nreqs, std::string commod) { + using cyclus::Material; + using cyclus::Request; + using cyclus::ExchangeContext; + using test_helpers::get_mat; + + double qty = 3; + boost::shared_ptr< ExchangeContext > + ec(new ExchangeContext()); + for (int i = 0; i < nreqs; i++) { + ec->AddRequest(Request::Create(get_mat(), trader, commod)); + } + return ec; +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +cyclus::Agent* FooConstructor(cyclus::Context* ctx) { + return new cycamore::Foo(ctx); +} + +// required to get functionality in cyclus agent unit tests library +#ifndef CYCLUS_AGENT_TESTS_CONNECTED +int ConnectAgentTests(); +static int cyclus_agent_tests_connected = ConnectAgentTests(); +#define CYCLUS_AGENT_TESTS_CONNECTED cyclus_agent_tests_connected +#endif // CYCLUS_AGENT_TESTS_CONNECTED + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +INSTANTIATE_TEST_CASE_P(FooFac, FacilityTests, Values(&FooConstructor)); +INSTANTIATE_TEST_CASE_P(FooFac, AgentTests, Values(&FooConstructor)); diff --git a/src/foo_tests.h b/src/foo_tests.h new file mode 100644 index 0000000000..59888926b7 --- /dev/null +++ b/src/foo_tests.h @@ -0,0 +1,34 @@ +#ifndef CYCAMORE_SRC_FOO_TESTS_H_ +#define CYCAMORE_SRC_FOO_TESTS_H_ +#include "foo.h" + +#include + +#include + +#include "agent_tests.h" +#include "context.h" +#include "exchange_context.h" +#include "facility_tests.h" +#include "material.h" + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +class FooTest : public ::testing::Test { + public: + cyclus::TestContext tc; + TestFacility* trader; + cycamore::Foo* src_facility; + std::string commod, recipe_name; + double capacity; + cyclus::Composition::Ptr recipe; + + virtual void SetUp(); + virtual void TearDown(); + void InitParameters(); + void SetUpFoo(); + + boost::shared_ptr< cyclus::ExchangeContext > + GetContext(int nreqs, std::string commodity); +}; + +#endif // CYCAMORE_SRC_FOO_TESTS_H_ From 55df5eecde6c221b6fce8a3bc5b216e3b37184e2 Mon Sep 17 00:00:00 2001 From: Matthew Gidden Date: Thu, 23 Apr 2015 12:46:05 -0500 Subject: [PATCH 30/80] Revert "Squashing commits from cyclus/cycamore#301. This should fail on CI." This reverts commit 3bb92b3be3c5ccf879bc11c9c50243ab1a206bf0. --- src/CMakeLists.txt | 2 - src/foo.cc | 171 ------------------------------------- src/foo.h | 204 --------------------------------------------- src/foo_tests.cc | 204 --------------------------------------------- src/foo_tests.h | 34 -------- 5 files changed, 615 deletions(-) delete mode 100644 src/foo.cc delete mode 100644 src/foo.h delete mode 100644 src/foo_tests.cc delete mode 100644 src/foo_tests.h diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 0f0ef9eea2..5701534c73 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -10,8 +10,6 @@ USE_CYCLUS("cycamore" "sink") USE_CYCLUS("cycamore" "source") -USE_CYCLUS("cycamore" "foo") - USE_CYCLUS("cycamore" "deploy_inst") USE_CYCLUS("cycamore" "manager_inst") diff --git a/src/foo.cc b/src/foo.cc deleted file mode 100644 index 9ad8ada201..0000000000 --- a/src/foo.cc +++ /dev/null @@ -1,171 +0,0 @@ -#include "foo.h" - -#include -#include - -#include - -namespace cycamore { - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Foo::Foo(cyclus::Context* ctx) - : cyclus::Facility(ctx), - out_commod(""), - recipe_name(""), - capacity(std::numeric_limits::max()) {} - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Foo::~Foo() {} - -#pragma cyclus def clone cycamore::Foo - -#pragma cyclus def schema cycamore::Foo - -#pragma cyclus def annotations cycamore::Foo - -#pragma cyclus def infiletodb cycamore::Foo - -#pragma cyclus def snapshot cycamore::Foo - -#pragma cyclus def snapshotinv cycamore::Foo - -#pragma cyclus def initinv cycamore::Foo - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void Foo::InitFrom(Foo* m) { - #pragma cyclus impl initfromcopy cycamore::Foo - cyclus::toolkit::CommodityProducer::Copy(m); -} - -void Foo::InitFrom(cyclus::QueryableBackend* b) { - #pragma cyclus impl initfromdb cycamore::Foo - - commod_ = cyclus::toolkit::Commodity(out_commod); - cyclus::toolkit::CommodityProducer::Add(commod_); - cyclus::toolkit::CommodityProducer::SetCapacity(commod_, capacity); - cyclus::toolkit::CommodityProducer::SetCost(commod_, capacity); -} - -void Foo::EnterNotify() { - Facility::EnterNotify(); - commod_ = cyclus::toolkit::Commodity(out_commod); - cyclus::toolkit::CommodityProducer::Add(commod_); - cyclus::toolkit::CommodityProducer::SetCapacity(commod_, capacity); - cyclus::toolkit::CommodityProducer::SetCost(commod_, capacity); -} - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -std::string Foo::str() { - std::stringstream ss; - std::string ans; - if (cyclus::toolkit::CommodityProducer:: - Produces(cyclus::toolkit::Commodity(out_commod))) { - ans = "yes"; - } else { - ans = "no"; - } - ss << cyclus::Facility::str() - << " supplies commodity '" - << out_commod << "' with recipe '" - << recipe_name << "' at a capacity of " - << capacity << " kg per time step " - << " commod producer members: " << " produces " - << out_commod << "?: " << ans - << " capacity: " << cyclus::toolkit::CommodityProducer::Capacity(commod_) - << " cost: " << cyclus::toolkit::CommodityProducer::Cost(commod_); - return ss.str(); -} - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void Foo::Tick() { - LOG(cyclus::LEV_INFO3, "SrcFac") << prototype() << " is ticking {"; - LOG(cyclus::LEV_INFO4, "SrcFac") << "will offer " << capacity - << " kg of " - << out_commod << "."; - LOG(cyclus::LEV_INFO3, "SrcFac") << "Stats: " << str(); - LOG(cyclus::LEV_INFO3, "SrcFac") << "}"; - current_capacity = capacity; // reset capacity -} - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void Foo::Tock() { - LOG(cyclus::LEV_INFO3, "SrcFac") << prototype() << " is tocking {"; - LOG(cyclus::LEV_INFO3, "SrcFac") << "}"; -} - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -cyclus::Material::Ptr Foo::GetOffer( - const cyclus::Material::Ptr target) const { - using cyclus::Material; - double qty = std::min(target->quantity(), capacity); - return Material::CreateUntracked(qty, context()->GetRecipe(recipe_name)); -} - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -std::set::Ptr> -Foo::GetMatlBids( - cyclus::CommodMap::type& commod_requests) { - using cyclus::Bid; - using cyclus::BidPortfolio; - using cyclus::CapacityConstraint; - using cyclus::Material; - using cyclus::Request; - - std::set::Ptr> ports; - - if (commod_requests.count(out_commod) > 0) { - BidPortfolio::Ptr port(new BidPortfolio()); - - std::vector*>& requests = - commod_requests[out_commod]; - - std::vector*>::iterator it; - for (it = requests.begin(); it != requests.end(); ++it) { - Request* req = *it; - Material::Ptr offer = GetOffer(req->target()); - port->AddBid(req, offer, this); - } - - CapacityConstraint cc(capacity); - port->AddConstraint(cc); - ports.insert(port); - } - return ports; -} - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void Foo::GetMatlTrades( - const std::vector< cyclus::Trade >& trades, - std::vector, - cyclus::Material::Ptr> >& responses) { - using cyclus::Material; - using cyclus::Trade; - - double provided = 0; - std::vector< cyclus::Trade >::const_iterator it; - for (it = trades.begin(); it != trades.end(); ++it) { - double qty = it->amt; - current_capacity -= qty; - provided += qty; - // @TODO we need a policy on negatives.. - Material::Ptr response = Material::Create(this, qty, - context()->GetRecipe(recipe_name)); - responses.push_back(std::make_pair(*it, response)); - LOG(cyclus::LEV_INFO5, "SrcFac") << prototype() << " just received an order" - << " for " << qty - << " of " << out_commod; - } - if (cyclus::IsNegative(current_capacity)) { - std::stringstream ss; - ss << "is being asked to provide " << provided - << " but its capacity is " << capacity << "."; - throw cyclus::ValueError(Agent::InformErrorMsg(ss.str())); - } -} - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -extern "C" cyclus::Agent* ConstructFoo(cyclus::Context* ctx) { - return new Foo(ctx); -} - -} // namespace cycamore diff --git a/src/foo.h b/src/foo.h deleted file mode 100644 index e35ab83d99..0000000000 --- a/src/foo.h +++ /dev/null @@ -1,204 +0,0 @@ -#ifndef CYCAMORE_SRC_FOO_H_ -#define CYCAMORE_SRC_FOO_H_ - -#include -#include - -#include "cyclus.h" - -namespace cycamore { - -class Context; - -/// @class Foo -/// This cyclus::Facility provides a simple source of some capacity -/// (possibly infinite) of some commodity/Recipe. - -/// The Foo class inherits from the cyclus::Facility class and is -/// dynamically loaded by the Agent class when requested. - -/// @section introduction Introduction -/// The Foo is a facility type in Cyclus capable of providing -/// a finite or infinite.Supply of a particular material to the -/// simulation. A Foo generates material of a certain -/// composition and commodity type, then offers that material on the -/// appropriate market. Shipments of this material are executed when the -/// market issues an order that the offer has been matched with a -/// request. - -/// @section agentparams Agent Parameters -/// Foo behavior is comprehensively defined by the following -/// parameters: -/// - double capacity: The production capacity of the facility (units -/// vary, but typically kg/month). Capacity is infinite if a negative -/// value is provided. -/// - int startDate: The date on which the facility begins to operate -/// (months). -/// - int lifeTime: The length of time that the facility operates -/// (months). - std::string outCommod: the commodity that this facility -/// produces - double inventorysize: the maximum quantity of material to -/// be held in the inventory -/// - double commodprice: the price of the output material PER UNIT -/// - map outComp - -/// @section optionalparams Optional Parameters -/// Foo behavior may also be specified with the following -/// optional parameters which have default values listed here. -/// - double capacityFactor: The ratio of actual production capacity to -/// the rated production capacity. Default is 1 (actual/rated). -/// - double availFactor: The percent of time the facility operates at -/// its capacity factor. Default is 100%. -/// - double capitalCost: The cost of constructing and commissioning -/// this facility. Default is 0 ($). -/// - double opCost: The annual cost of operation and maintenance of -/// this facility. Default is 0 ( $/year). -/// - int constrTime: The number of months it takes to construct and -/// commission this facility. Default is 0 (months). -/// - int decomTime: The number of months it takes to deconstruct and -/// decommission this facility. Default is 0 (months). -/// - Inst* inst: The institution responsible for this facility. -/// - string name: A non-generic name for this facility. - -/// @section detailed Detailed Behavior -/// @subsection finite If Finite Capacity: -/// The Foo starts operation when the simulation reaches the -/// month specified as the startDate. It immediately begins to produce -/// material at the rate defined by its capacity. Each month the -/// Foo adds the amount it has produced to its inventory. It -/// then offers to the appropriate market exactly as much material as it -/// has in its inventory. If an offer is matched with a request, the -/// Foo executes that order by subtracting the quantity from -/// its inventory and sending that amount to the requesting facility. -/// When the simulation time equals the startDate plus the lifeTime, the -/// facility ceases to operate. -/// @subsection infinite If Infinite Capacity: -/// The Foo starts operation when the simulation reaches the -/// month specified as the startDate. Each month the Foo -/// offers an infinite amount of material to the appropriate market. If -/// there is a request for that material, the Foo executes -/// that order by sending that amount to the requesting facility. When -/// the simulation time equals the startDate plus the lifeTime, the -/// facility ceases to operate. - -/// @subsection question Question: -/// What is the best way to allow offers of an infinite amount of -/// material on a market? - -class Foo : public cyclus::Facility, - public cyclus::toolkit::CommodityProducer { - public: - // --- Module Members --- - /// Constructor for the Foo class - /// @param ctx the cyclus context for access to simulation-wide parameters - Foo(cyclus::Context* ctx); - - virtual ~Foo() - - #pragma cyclus decl - - #pragma cyclus note {"doc": "A source facility that provides a " \ - "commodity with a given capacity"} - - /// Print information about this agent - virtual std::string str(); - // --- - - // --- Agent Members --- - virtual void EnterNotify(); - - /// Each facility is prompted to do its beginning-of-time-step - /// stuff at the tick of the timer. - - /// @param time is the time to perform the tick - virtual void Tick(); - - /// Each facility is prompted to its end-of-time-step - /// stuff on the tock of the timer. - - /// @param time is the time to perform the tock - virtual void Tock(); - - /// @brief Responds to each request for this source facility's commodity. - /// If a given request is more than this facility's capacity, it will offer - /// its capacity. - virtual std::set::Ptr> - GetMatlBids(cyclus::CommodMap::type& - commod_requests); - - /// @brief respond to each trade with a material made from this facility's - /// recipe - /// - /// @param trades all trades in which this trader is the supplier - /// @param responses a container to populate with responses to each trade - virtual void GetMatlTrades( - const std::vector< cyclus::Trade >& trades, - std::vector, - cyclus::Material::Ptr> >& responses); - // --- - - // --- Foo Members --- - /// @brief creates a material object to offer to a requester - /// @param target the material target a request desires - cyclus::Material::Ptr GetOffer(const cyclus::Material::Ptr target) const; - - /// sets the output commodity name - /// @param name the commodity name - inline void commodity(std::string name) { out_commod = name; } - - /// @return the output commodity - inline std::string commodity() const { return out_commod; } - - /// sets the capacity of a material generated at any given time step - /// @param capacity the production capacity - inline void Capacity(double cap) { - capacity = cap; - current_capacity = capacity; - } - - /// @return the production capacity at any given time step - inline double Capacity() const { return capacity; } - - /// sets the name of the recipe to be produced - /// @param name the recipe name - inline void recipe(std::string name) { recipe_name = name; } - - /// @return the name of the output recipe - inline std::string recipe() const { return recipe_name; } - - /// @return the current timestep's capacity - inline double CurrentCapacity() const { return current_capacity; } - - private: - cyclus::toolkit::Commodity commod_; - - /// This facility has only one output commodity - #pragma cyclus var {"tooltip": "source output commodity", \ - "doc": "output commodity that the source facility " \ - "supplies", \ - "uitype": "outcommodity"} - std::string out_commod; - - /// Name of the recipe this facility uses. - #pragma cyclus var {"tooltip": "commodity recipe name", \ - "doc": "recipe name for source facility's commodity", \ - "uitype": "recipe"} - std::string recipe_name; - - /// The capacity is defined in terms of the number of units of the - /// recipe that can be provided each time step. A very large number - /// can be provided to represent infinte capacity. - #pragma cyclus var {"default": 1e299, "tooltip": "source capacity", \ - "doc": "amount of commodity that can be supplied " \ - "at each time step"} - double capacity; - - /// The capacity at the current time step - #pragma cyclus var {'derived_init': 'current_capacity = capacity;'} - double current_capacity; - - // --- -}; - -} // namespace cycamore - -#endif // CYCAMORE_SRC_FOO_H_ diff --git a/src/foo_tests.cc b/src/foo_tests.cc deleted file mode 100644 index 0973e794d0..0000000000 --- a/src/foo_tests.cc +++ /dev/null @@ -1,204 +0,0 @@ -#include "foo_tests.h" - -#include - -#include - -#include "cyc_limits.h" -#include "resource_helpers.h" -#include "test_context.h" - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void FooTest::SetUp() { - src_facility = new cycamore::Foo(tc.get()); - trader = tc.trader(); - InitParameters(); - SetUpFoo(); -} - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void FooTest::TearDown() { - delete src_facility; -} - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void FooTest::InitParameters() { - commod = "commod"; - recipe_name = "recipe"; - capacity = 5; // some magic number.. - - recipe = cyclus::Composition::CreateFromAtom(cyclus::CompMap()); - tc.get()->AddRecipe(recipe_name, recipe); -} - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void FooTest::SetUpFoo() { - src_facility->commodity(commod); - src_facility->recipe(recipe_name); - src_facility->Capacity(capacity); -} - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -TEST_F(FooTest, InitialState) { - EXPECT_EQ(src_facility->Capacity(), capacity); - EXPECT_EQ(src_facility->commodity(), commod); - EXPECT_EQ(src_facility->recipe(), recipe_name); - EXPECT_EQ(src_facility->CurrentCapacity(), capacity); -} - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -TEST_F(FooTest, Clone) { - cyclus::Context* ctx = tc.get(); - cycamore::Foo* cloned_fac = dynamic_cast - (src_facility->Clone()); - - EXPECT_EQ(src_facility->commodity(), cloned_fac->commodity()); - EXPECT_EQ(src_facility->Capacity(), cloned_fac->Capacity()); - EXPECT_EQ(src_facility->recipe(), cloned_fac->recipe()); - EXPECT_EQ(src_facility->Capacity(), cloned_fac->CurrentCapacity()); - - delete cloned_fac; -} - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -TEST_F(FooTest, Print) { - EXPECT_NO_THROW(std::string s = src_facility->str()); -} - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -TEST_F(FooTest, GetOffer) { - using cyclus::Material; - - double qty = capacity - 1; - Material::Ptr mat = cyclus::NewBlankMaterial(qty); - Material::Ptr obs_mat = src_facility->GetOffer(mat); - EXPECT_EQ(obs_mat->quantity(), qty); - EXPECT_EQ(obs_mat->comp(), recipe); - - qty = capacity + 1; - mat = cyclus::NewBlankMaterial(qty); - obs_mat = src_facility->GetOffer(mat); - EXPECT_EQ(obs_mat->quantity(), capacity); - EXPECT_EQ(obs_mat->comp(), recipe); - - qty = capacity; - mat = cyclus::NewBlankMaterial(qty); - obs_mat = src_facility->GetOffer(mat); - EXPECT_EQ(obs_mat->quantity(), capacity); - EXPECT_EQ(obs_mat->comp(), recipe); -} - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -TEST_F(FooTest, AddBids) { - using cyclus::Bid; - using cyclus::BidPortfolio; - using cyclus::CapacityConstraint; - using cyclus::ExchangeContext; - using cyclus::Material; - - int nreqs = 5; - - boost::shared_ptr< cyclus::ExchangeContext > - ec = GetContext(nreqs, commod); - - std::set::Ptr> ports = - src_facility->GetMatlBids(ec.get()->commod_requests); - - ASSERT_TRUE(ports.size() > 0); - EXPECT_EQ(ports.size(), 1); - - BidPortfolio::Ptr port = *ports.begin(); - EXPECT_EQ(port->bidder(), src_facility); - EXPECT_EQ(port->bids().size(), nreqs); - - const std::set< CapacityConstraint >& constrs = port->constraints(); - ASSERT_TRUE(constrs.size() > 0); - EXPECT_EQ(constrs.size(), 1); - EXPECT_EQ(*constrs.begin(), CapacityConstraint(capacity)); -} - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -TEST_F(FooTest, Response) { - using cyclus::Bid; - using cyclus::Material; - using cyclus::Request; - using cyclus::Trade; - using test_helpers::get_mat; - - std::vector< cyclus::Trade > trades; - std::vector, - cyclus::Material::Ptr> > responses; - - // Null response - EXPECT_NO_THROW(src_facility->GetMatlTrades(trades, responses)); - EXPECT_EQ(responses.size(), 0); - - double qty = capacity / 3; - Request* request = - Request::Create(get_mat(), trader, commod); - Bid* bid = - Bid::Create(request, get_mat(), src_facility); - - Trade trade(request, bid, qty); - trades.push_back(trade); - - // 1 trade - ASSERT_EQ(src_facility->CurrentCapacity(), capacity); - src_facility->GetMatlTrades(trades, responses); - EXPECT_EQ(responses.size(), 1); - EXPECT_EQ(responses[0].second->quantity(), qty); - EXPECT_EQ(responses[0].second->comp(), recipe); - - // 2 trades, total qty = capacity - ASSERT_DOUBLE_EQ(src_facility->CurrentCapacity(), capacity - qty); - ASSERT_GT(src_facility->CurrentCapacity() - 2 * qty, -1 * cyclus::eps()); - trades.push_back(trade); - responses.clear(); - EXPECT_NO_THROW(src_facility->GetMatlTrades(trades, responses)); - EXPECT_EQ(responses.size(), 2); - ASSERT_TRUE(cyclus::AlmostEq(src_facility->CurrentCapacity(), 0)); - - // too much qty, capn! - EXPECT_THROW(src_facility->GetMatlTrades(trades, responses), - cyclus::ValueError); - - // reset! - src_facility->Tick(); - ASSERT_DOUBLE_EQ(src_facility->CurrentCapacity(), capacity); - - delete request; - delete bid; -} - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -boost::shared_ptr< cyclus::ExchangeContext > -FooTest::GetContext(int nreqs, std::string commod) { - using cyclus::Material; - using cyclus::Request; - using cyclus::ExchangeContext; - using test_helpers::get_mat; - - double qty = 3; - boost::shared_ptr< ExchangeContext > - ec(new ExchangeContext()); - for (int i = 0; i < nreqs; i++) { - ec->AddRequest(Request::Create(get_mat(), trader, commod)); - } - return ec; -} - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -cyclus::Agent* FooConstructor(cyclus::Context* ctx) { - return new cycamore::Foo(ctx); -} - -// required to get functionality in cyclus agent unit tests library -#ifndef CYCLUS_AGENT_TESTS_CONNECTED -int ConnectAgentTests(); -static int cyclus_agent_tests_connected = ConnectAgentTests(); -#define CYCLUS_AGENT_TESTS_CONNECTED cyclus_agent_tests_connected -#endif // CYCLUS_AGENT_TESTS_CONNECTED - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -INSTANTIATE_TEST_CASE_P(FooFac, FacilityTests, Values(&FooConstructor)); -INSTANTIATE_TEST_CASE_P(FooFac, AgentTests, Values(&FooConstructor)); diff --git a/src/foo_tests.h b/src/foo_tests.h deleted file mode 100644 index 59888926b7..0000000000 --- a/src/foo_tests.h +++ /dev/null @@ -1,34 +0,0 @@ -#ifndef CYCAMORE_SRC_FOO_TESTS_H_ -#define CYCAMORE_SRC_FOO_TESTS_H_ -#include "foo.h" - -#include - -#include - -#include "agent_tests.h" -#include "context.h" -#include "exchange_context.h" -#include "facility_tests.h" -#include "material.h" - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -class FooTest : public ::testing::Test { - public: - cyclus::TestContext tc; - TestFacility* trader; - cycamore::Foo* src_facility; - std::string commod, recipe_name; - double capacity; - cyclus::Composition::Ptr recipe; - - virtual void SetUp(); - virtual void TearDown(); - void InitParameters(); - void SetUpFoo(); - - boost::shared_ptr< cyclus::ExchangeContext > - GetContext(int nreqs, std::string commodity); -}; - -#endif // CYCAMORE_SRC_FOO_TESTS_H_ From 67f4a5cf616ec24843599d45934025e07c3e9174 Mon Sep 17 00:00:00 2001 From: Matthew Gidden Date: Thu, 23 Apr 2015 14:18:47 -0500 Subject: [PATCH 31/80] adding commit msg indicator --- .travis-install.sh | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.travis-install.sh b/.travis-install.sh index 1e53559839..1f9e8a8e15 100755 --- a/.travis-install.sh +++ b/.travis-install.sh @@ -1,5 +1,9 @@ #!/bin/bash +# log +msg=`git log --pretty=oneline -1` +echo "Building commit: $msg" + # setup conda recipe wget https://github.com/gidden/ciclus/archive/travis.zip -O ciclus.zip unzip -j ciclus.zip "*/cycamore/*" -d conda-recipe From d7c653699506e3aa4229840db5b97f24bc73d4f4 Mon Sep 17 00:00:00 2001 From: Matthew Gidden Date: Thu, 23 Apr 2015 14:30:44 -0500 Subject: [PATCH 32/80] adding failure with an explicit check --- .travis-install.sh | 2 + src/CMakeLists.txt | 2 + src/foo.cc | 171 +++++++++++++++++++++++++++++++++++++ src/foo.h | 204 +++++++++++++++++++++++++++++++++++++++++++++ src/foo_tests.cc | 204 +++++++++++++++++++++++++++++++++++++++++++++ src/foo_tests.h | 34 ++++++++ 6 files changed, 617 insertions(+) create mode 100644 src/foo.cc create mode 100644 src/foo.h create mode 100644 src/foo_tests.cc create mode 100644 src/foo_tests.h diff --git a/.travis-install.sh b/.travis-install.sh index 1f9e8a8e15..08a02557a1 100755 --- a/.travis-install.sh +++ b/.travis-install.sh @@ -10,6 +10,8 @@ unzip -j ciclus.zip "*/cycamore/*" -d conda-recipe sed -i "s/- cyclus/- cyclus 0.0/g" conda-recipe/meta.yaml # build +"src/CMakeLists.txt:" +cat src/CMakeLists.txt cmd="conda build --no-test conda-recipe" echo "cmd: $cmd" $cmd diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 5701534c73..0f0ef9eea2 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -10,6 +10,8 @@ USE_CYCLUS("cycamore" "sink") USE_CYCLUS("cycamore" "source") +USE_CYCLUS("cycamore" "foo") + USE_CYCLUS("cycamore" "deploy_inst") USE_CYCLUS("cycamore" "manager_inst") diff --git a/src/foo.cc b/src/foo.cc new file mode 100644 index 0000000000..9ad8ada201 --- /dev/null +++ b/src/foo.cc @@ -0,0 +1,171 @@ +#include "foo.h" + +#include +#include + +#include + +namespace cycamore { + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +Foo::Foo(cyclus::Context* ctx) + : cyclus::Facility(ctx), + out_commod(""), + recipe_name(""), + capacity(std::numeric_limits::max()) {} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +Foo::~Foo() {} + +#pragma cyclus def clone cycamore::Foo + +#pragma cyclus def schema cycamore::Foo + +#pragma cyclus def annotations cycamore::Foo + +#pragma cyclus def infiletodb cycamore::Foo + +#pragma cyclus def snapshot cycamore::Foo + +#pragma cyclus def snapshotinv cycamore::Foo + +#pragma cyclus def initinv cycamore::Foo + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +void Foo::InitFrom(Foo* m) { + #pragma cyclus impl initfromcopy cycamore::Foo + cyclus::toolkit::CommodityProducer::Copy(m); +} + +void Foo::InitFrom(cyclus::QueryableBackend* b) { + #pragma cyclus impl initfromdb cycamore::Foo + + commod_ = cyclus::toolkit::Commodity(out_commod); + cyclus::toolkit::CommodityProducer::Add(commod_); + cyclus::toolkit::CommodityProducer::SetCapacity(commod_, capacity); + cyclus::toolkit::CommodityProducer::SetCost(commod_, capacity); +} + +void Foo::EnterNotify() { + Facility::EnterNotify(); + commod_ = cyclus::toolkit::Commodity(out_commod); + cyclus::toolkit::CommodityProducer::Add(commod_); + cyclus::toolkit::CommodityProducer::SetCapacity(commod_, capacity); + cyclus::toolkit::CommodityProducer::SetCost(commod_, capacity); +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +std::string Foo::str() { + std::stringstream ss; + std::string ans; + if (cyclus::toolkit::CommodityProducer:: + Produces(cyclus::toolkit::Commodity(out_commod))) { + ans = "yes"; + } else { + ans = "no"; + } + ss << cyclus::Facility::str() + << " supplies commodity '" + << out_commod << "' with recipe '" + << recipe_name << "' at a capacity of " + << capacity << " kg per time step " + << " commod producer members: " << " produces " + << out_commod << "?: " << ans + << " capacity: " << cyclus::toolkit::CommodityProducer::Capacity(commod_) + << " cost: " << cyclus::toolkit::CommodityProducer::Cost(commod_); + return ss.str(); +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +void Foo::Tick() { + LOG(cyclus::LEV_INFO3, "SrcFac") << prototype() << " is ticking {"; + LOG(cyclus::LEV_INFO4, "SrcFac") << "will offer " << capacity + << " kg of " + << out_commod << "."; + LOG(cyclus::LEV_INFO3, "SrcFac") << "Stats: " << str(); + LOG(cyclus::LEV_INFO3, "SrcFac") << "}"; + current_capacity = capacity; // reset capacity +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +void Foo::Tock() { + LOG(cyclus::LEV_INFO3, "SrcFac") << prototype() << " is tocking {"; + LOG(cyclus::LEV_INFO3, "SrcFac") << "}"; +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +cyclus::Material::Ptr Foo::GetOffer( + const cyclus::Material::Ptr target) const { + using cyclus::Material; + double qty = std::min(target->quantity(), capacity); + return Material::CreateUntracked(qty, context()->GetRecipe(recipe_name)); +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +std::set::Ptr> +Foo::GetMatlBids( + cyclus::CommodMap::type& commod_requests) { + using cyclus::Bid; + using cyclus::BidPortfolio; + using cyclus::CapacityConstraint; + using cyclus::Material; + using cyclus::Request; + + std::set::Ptr> ports; + + if (commod_requests.count(out_commod) > 0) { + BidPortfolio::Ptr port(new BidPortfolio()); + + std::vector*>& requests = + commod_requests[out_commod]; + + std::vector*>::iterator it; + for (it = requests.begin(); it != requests.end(); ++it) { + Request* req = *it; + Material::Ptr offer = GetOffer(req->target()); + port->AddBid(req, offer, this); + } + + CapacityConstraint cc(capacity); + port->AddConstraint(cc); + ports.insert(port); + } + return ports; +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +void Foo::GetMatlTrades( + const std::vector< cyclus::Trade >& trades, + std::vector, + cyclus::Material::Ptr> >& responses) { + using cyclus::Material; + using cyclus::Trade; + + double provided = 0; + std::vector< cyclus::Trade >::const_iterator it; + for (it = trades.begin(); it != trades.end(); ++it) { + double qty = it->amt; + current_capacity -= qty; + provided += qty; + // @TODO we need a policy on negatives.. + Material::Ptr response = Material::Create(this, qty, + context()->GetRecipe(recipe_name)); + responses.push_back(std::make_pair(*it, response)); + LOG(cyclus::LEV_INFO5, "SrcFac") << prototype() << " just received an order" + << " for " << qty + << " of " << out_commod; + } + if (cyclus::IsNegative(current_capacity)) { + std::stringstream ss; + ss << "is being asked to provide " << provided + << " but its capacity is " << capacity << "."; + throw cyclus::ValueError(Agent::InformErrorMsg(ss.str())); + } +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +extern "C" cyclus::Agent* ConstructFoo(cyclus::Context* ctx) { + return new Foo(ctx); +} + +} // namespace cycamore diff --git a/src/foo.h b/src/foo.h new file mode 100644 index 0000000000..e35ab83d99 --- /dev/null +++ b/src/foo.h @@ -0,0 +1,204 @@ +#ifndef CYCAMORE_SRC_FOO_H_ +#define CYCAMORE_SRC_FOO_H_ + +#include +#include + +#include "cyclus.h" + +namespace cycamore { + +class Context; + +/// @class Foo +/// This cyclus::Facility provides a simple source of some capacity +/// (possibly infinite) of some commodity/Recipe. + +/// The Foo class inherits from the cyclus::Facility class and is +/// dynamically loaded by the Agent class when requested. + +/// @section introduction Introduction +/// The Foo is a facility type in Cyclus capable of providing +/// a finite or infinite.Supply of a particular material to the +/// simulation. A Foo generates material of a certain +/// composition and commodity type, then offers that material on the +/// appropriate market. Shipments of this material are executed when the +/// market issues an order that the offer has been matched with a +/// request. + +/// @section agentparams Agent Parameters +/// Foo behavior is comprehensively defined by the following +/// parameters: +/// - double capacity: The production capacity of the facility (units +/// vary, but typically kg/month). Capacity is infinite if a negative +/// value is provided. +/// - int startDate: The date on which the facility begins to operate +/// (months). +/// - int lifeTime: The length of time that the facility operates +/// (months). - std::string outCommod: the commodity that this facility +/// produces - double inventorysize: the maximum quantity of material to +/// be held in the inventory +/// - double commodprice: the price of the output material PER UNIT +/// - map outComp + +/// @section optionalparams Optional Parameters +/// Foo behavior may also be specified with the following +/// optional parameters which have default values listed here. +/// - double capacityFactor: The ratio of actual production capacity to +/// the rated production capacity. Default is 1 (actual/rated). +/// - double availFactor: The percent of time the facility operates at +/// its capacity factor. Default is 100%. +/// - double capitalCost: The cost of constructing and commissioning +/// this facility. Default is 0 ($). +/// - double opCost: The annual cost of operation and maintenance of +/// this facility. Default is 0 ( $/year). +/// - int constrTime: The number of months it takes to construct and +/// commission this facility. Default is 0 (months). +/// - int decomTime: The number of months it takes to deconstruct and +/// decommission this facility. Default is 0 (months). +/// - Inst* inst: The institution responsible for this facility. +/// - string name: A non-generic name for this facility. + +/// @section detailed Detailed Behavior +/// @subsection finite If Finite Capacity: +/// The Foo starts operation when the simulation reaches the +/// month specified as the startDate. It immediately begins to produce +/// material at the rate defined by its capacity. Each month the +/// Foo adds the amount it has produced to its inventory. It +/// then offers to the appropriate market exactly as much material as it +/// has in its inventory. If an offer is matched with a request, the +/// Foo executes that order by subtracting the quantity from +/// its inventory and sending that amount to the requesting facility. +/// When the simulation time equals the startDate plus the lifeTime, the +/// facility ceases to operate. +/// @subsection infinite If Infinite Capacity: +/// The Foo starts operation when the simulation reaches the +/// month specified as the startDate. Each month the Foo +/// offers an infinite amount of material to the appropriate market. If +/// there is a request for that material, the Foo executes +/// that order by sending that amount to the requesting facility. When +/// the simulation time equals the startDate plus the lifeTime, the +/// facility ceases to operate. + +/// @subsection question Question: +/// What is the best way to allow offers of an infinite amount of +/// material on a market? + +class Foo : public cyclus::Facility, + public cyclus::toolkit::CommodityProducer { + public: + // --- Module Members --- + /// Constructor for the Foo class + /// @param ctx the cyclus context for access to simulation-wide parameters + Foo(cyclus::Context* ctx); + + virtual ~Foo() + + #pragma cyclus decl + + #pragma cyclus note {"doc": "A source facility that provides a " \ + "commodity with a given capacity"} + + /// Print information about this agent + virtual std::string str(); + // --- + + // --- Agent Members --- + virtual void EnterNotify(); + + /// Each facility is prompted to do its beginning-of-time-step + /// stuff at the tick of the timer. + + /// @param time is the time to perform the tick + virtual void Tick(); + + /// Each facility is prompted to its end-of-time-step + /// stuff on the tock of the timer. + + /// @param time is the time to perform the tock + virtual void Tock(); + + /// @brief Responds to each request for this source facility's commodity. + /// If a given request is more than this facility's capacity, it will offer + /// its capacity. + virtual std::set::Ptr> + GetMatlBids(cyclus::CommodMap::type& + commod_requests); + + /// @brief respond to each trade with a material made from this facility's + /// recipe + /// + /// @param trades all trades in which this trader is the supplier + /// @param responses a container to populate with responses to each trade + virtual void GetMatlTrades( + const std::vector< cyclus::Trade >& trades, + std::vector, + cyclus::Material::Ptr> >& responses); + // --- + + // --- Foo Members --- + /// @brief creates a material object to offer to a requester + /// @param target the material target a request desires + cyclus::Material::Ptr GetOffer(const cyclus::Material::Ptr target) const; + + /// sets the output commodity name + /// @param name the commodity name + inline void commodity(std::string name) { out_commod = name; } + + /// @return the output commodity + inline std::string commodity() const { return out_commod; } + + /// sets the capacity of a material generated at any given time step + /// @param capacity the production capacity + inline void Capacity(double cap) { + capacity = cap; + current_capacity = capacity; + } + + /// @return the production capacity at any given time step + inline double Capacity() const { return capacity; } + + /// sets the name of the recipe to be produced + /// @param name the recipe name + inline void recipe(std::string name) { recipe_name = name; } + + /// @return the name of the output recipe + inline std::string recipe() const { return recipe_name; } + + /// @return the current timestep's capacity + inline double CurrentCapacity() const { return current_capacity; } + + private: + cyclus::toolkit::Commodity commod_; + + /// This facility has only one output commodity + #pragma cyclus var {"tooltip": "source output commodity", \ + "doc": "output commodity that the source facility " \ + "supplies", \ + "uitype": "outcommodity"} + std::string out_commod; + + /// Name of the recipe this facility uses. + #pragma cyclus var {"tooltip": "commodity recipe name", \ + "doc": "recipe name for source facility's commodity", \ + "uitype": "recipe"} + std::string recipe_name; + + /// The capacity is defined in terms of the number of units of the + /// recipe that can be provided each time step. A very large number + /// can be provided to represent infinte capacity. + #pragma cyclus var {"default": 1e299, "tooltip": "source capacity", \ + "doc": "amount of commodity that can be supplied " \ + "at each time step"} + double capacity; + + /// The capacity at the current time step + #pragma cyclus var {'derived_init': 'current_capacity = capacity;'} + double current_capacity; + + // --- +}; + +} // namespace cycamore + +#endif // CYCAMORE_SRC_FOO_H_ diff --git a/src/foo_tests.cc b/src/foo_tests.cc new file mode 100644 index 0000000000..0973e794d0 --- /dev/null +++ b/src/foo_tests.cc @@ -0,0 +1,204 @@ +#include "foo_tests.h" + +#include + +#include + +#include "cyc_limits.h" +#include "resource_helpers.h" +#include "test_context.h" + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +void FooTest::SetUp() { + src_facility = new cycamore::Foo(tc.get()); + trader = tc.trader(); + InitParameters(); + SetUpFoo(); +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +void FooTest::TearDown() { + delete src_facility; +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +void FooTest::InitParameters() { + commod = "commod"; + recipe_name = "recipe"; + capacity = 5; // some magic number.. + + recipe = cyclus::Composition::CreateFromAtom(cyclus::CompMap()); + tc.get()->AddRecipe(recipe_name, recipe); +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +void FooTest::SetUpFoo() { + src_facility->commodity(commod); + src_facility->recipe(recipe_name); + src_facility->Capacity(capacity); +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +TEST_F(FooTest, InitialState) { + EXPECT_EQ(src_facility->Capacity(), capacity); + EXPECT_EQ(src_facility->commodity(), commod); + EXPECT_EQ(src_facility->recipe(), recipe_name); + EXPECT_EQ(src_facility->CurrentCapacity(), capacity); +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +TEST_F(FooTest, Clone) { + cyclus::Context* ctx = tc.get(); + cycamore::Foo* cloned_fac = dynamic_cast + (src_facility->Clone()); + + EXPECT_EQ(src_facility->commodity(), cloned_fac->commodity()); + EXPECT_EQ(src_facility->Capacity(), cloned_fac->Capacity()); + EXPECT_EQ(src_facility->recipe(), cloned_fac->recipe()); + EXPECT_EQ(src_facility->Capacity(), cloned_fac->CurrentCapacity()); + + delete cloned_fac; +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +TEST_F(FooTest, Print) { + EXPECT_NO_THROW(std::string s = src_facility->str()); +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +TEST_F(FooTest, GetOffer) { + using cyclus::Material; + + double qty = capacity - 1; + Material::Ptr mat = cyclus::NewBlankMaterial(qty); + Material::Ptr obs_mat = src_facility->GetOffer(mat); + EXPECT_EQ(obs_mat->quantity(), qty); + EXPECT_EQ(obs_mat->comp(), recipe); + + qty = capacity + 1; + mat = cyclus::NewBlankMaterial(qty); + obs_mat = src_facility->GetOffer(mat); + EXPECT_EQ(obs_mat->quantity(), capacity); + EXPECT_EQ(obs_mat->comp(), recipe); + + qty = capacity; + mat = cyclus::NewBlankMaterial(qty); + obs_mat = src_facility->GetOffer(mat); + EXPECT_EQ(obs_mat->quantity(), capacity); + EXPECT_EQ(obs_mat->comp(), recipe); +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +TEST_F(FooTest, AddBids) { + using cyclus::Bid; + using cyclus::BidPortfolio; + using cyclus::CapacityConstraint; + using cyclus::ExchangeContext; + using cyclus::Material; + + int nreqs = 5; + + boost::shared_ptr< cyclus::ExchangeContext > + ec = GetContext(nreqs, commod); + + std::set::Ptr> ports = + src_facility->GetMatlBids(ec.get()->commod_requests); + + ASSERT_TRUE(ports.size() > 0); + EXPECT_EQ(ports.size(), 1); + + BidPortfolio::Ptr port = *ports.begin(); + EXPECT_EQ(port->bidder(), src_facility); + EXPECT_EQ(port->bids().size(), nreqs); + + const std::set< CapacityConstraint >& constrs = port->constraints(); + ASSERT_TRUE(constrs.size() > 0); + EXPECT_EQ(constrs.size(), 1); + EXPECT_EQ(*constrs.begin(), CapacityConstraint(capacity)); +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +TEST_F(FooTest, Response) { + using cyclus::Bid; + using cyclus::Material; + using cyclus::Request; + using cyclus::Trade; + using test_helpers::get_mat; + + std::vector< cyclus::Trade > trades; + std::vector, + cyclus::Material::Ptr> > responses; + + // Null response + EXPECT_NO_THROW(src_facility->GetMatlTrades(trades, responses)); + EXPECT_EQ(responses.size(), 0); + + double qty = capacity / 3; + Request* request = + Request::Create(get_mat(), trader, commod); + Bid* bid = + Bid::Create(request, get_mat(), src_facility); + + Trade trade(request, bid, qty); + trades.push_back(trade); + + // 1 trade + ASSERT_EQ(src_facility->CurrentCapacity(), capacity); + src_facility->GetMatlTrades(trades, responses); + EXPECT_EQ(responses.size(), 1); + EXPECT_EQ(responses[0].second->quantity(), qty); + EXPECT_EQ(responses[0].second->comp(), recipe); + + // 2 trades, total qty = capacity + ASSERT_DOUBLE_EQ(src_facility->CurrentCapacity(), capacity - qty); + ASSERT_GT(src_facility->CurrentCapacity() - 2 * qty, -1 * cyclus::eps()); + trades.push_back(trade); + responses.clear(); + EXPECT_NO_THROW(src_facility->GetMatlTrades(trades, responses)); + EXPECT_EQ(responses.size(), 2); + ASSERT_TRUE(cyclus::AlmostEq(src_facility->CurrentCapacity(), 0)); + + // too much qty, capn! + EXPECT_THROW(src_facility->GetMatlTrades(trades, responses), + cyclus::ValueError); + + // reset! + src_facility->Tick(); + ASSERT_DOUBLE_EQ(src_facility->CurrentCapacity(), capacity); + + delete request; + delete bid; +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +boost::shared_ptr< cyclus::ExchangeContext > +FooTest::GetContext(int nreqs, std::string commod) { + using cyclus::Material; + using cyclus::Request; + using cyclus::ExchangeContext; + using test_helpers::get_mat; + + double qty = 3; + boost::shared_ptr< ExchangeContext > + ec(new ExchangeContext()); + for (int i = 0; i < nreqs; i++) { + ec->AddRequest(Request::Create(get_mat(), trader, commod)); + } + return ec; +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +cyclus::Agent* FooConstructor(cyclus::Context* ctx) { + return new cycamore::Foo(ctx); +} + +// required to get functionality in cyclus agent unit tests library +#ifndef CYCLUS_AGENT_TESTS_CONNECTED +int ConnectAgentTests(); +static int cyclus_agent_tests_connected = ConnectAgentTests(); +#define CYCLUS_AGENT_TESTS_CONNECTED cyclus_agent_tests_connected +#endif // CYCLUS_AGENT_TESTS_CONNECTED + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +INSTANTIATE_TEST_CASE_P(FooFac, FacilityTests, Values(&FooConstructor)); +INSTANTIATE_TEST_CASE_P(FooFac, AgentTests, Values(&FooConstructor)); diff --git a/src/foo_tests.h b/src/foo_tests.h new file mode 100644 index 0000000000..59888926b7 --- /dev/null +++ b/src/foo_tests.h @@ -0,0 +1,34 @@ +#ifndef CYCAMORE_SRC_FOO_TESTS_H_ +#define CYCAMORE_SRC_FOO_TESTS_H_ +#include "foo.h" + +#include + +#include + +#include "agent_tests.h" +#include "context.h" +#include "exchange_context.h" +#include "facility_tests.h" +#include "material.h" + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +class FooTest : public ::testing::Test { + public: + cyclus::TestContext tc; + TestFacility* trader; + cycamore::Foo* src_facility; + std::string commod, recipe_name; + double capacity; + cyclus::Composition::Ptr recipe; + + virtual void SetUp(); + virtual void TearDown(); + void InitParameters(); + void SetUpFoo(); + + boost::shared_ptr< cyclus::ExchangeContext > + GetContext(int nreqs, std::string commodity); +}; + +#endif // CYCAMORE_SRC_FOO_TESTS_H_ From 44a88042f3eeb9c10bef3409caa3313ac4b21b89 Mon Sep 17 00:00:00 2001 From: Matthew Gidden Date: Thu, 23 Apr 2015 14:53:53 -0500 Subject: [PATCH 33/80] Revert "adding failure with an explicit check" This reverts commit d7c653699506e3aa4229840db5b97f24bc73d4f4. --- .travis-install.sh | 2 - src/CMakeLists.txt | 2 - src/foo.cc | 171 ------------------------------------- src/foo.h | 204 --------------------------------------------- src/foo_tests.cc | 204 --------------------------------------------- src/foo_tests.h | 34 -------- 6 files changed, 617 deletions(-) delete mode 100644 src/foo.cc delete mode 100644 src/foo.h delete mode 100644 src/foo_tests.cc delete mode 100644 src/foo_tests.h diff --git a/.travis-install.sh b/.travis-install.sh index 08a02557a1..1f9e8a8e15 100755 --- a/.travis-install.sh +++ b/.travis-install.sh @@ -10,8 +10,6 @@ unzip -j ciclus.zip "*/cycamore/*" -d conda-recipe sed -i "s/- cyclus/- cyclus 0.0/g" conda-recipe/meta.yaml # build -"src/CMakeLists.txt:" -cat src/CMakeLists.txt cmd="conda build --no-test conda-recipe" echo "cmd: $cmd" $cmd diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 0f0ef9eea2..5701534c73 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -10,8 +10,6 @@ USE_CYCLUS("cycamore" "sink") USE_CYCLUS("cycamore" "source") -USE_CYCLUS("cycamore" "foo") - USE_CYCLUS("cycamore" "deploy_inst") USE_CYCLUS("cycamore" "manager_inst") diff --git a/src/foo.cc b/src/foo.cc deleted file mode 100644 index 9ad8ada201..0000000000 --- a/src/foo.cc +++ /dev/null @@ -1,171 +0,0 @@ -#include "foo.h" - -#include -#include - -#include - -namespace cycamore { - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Foo::Foo(cyclus::Context* ctx) - : cyclus::Facility(ctx), - out_commod(""), - recipe_name(""), - capacity(std::numeric_limits::max()) {} - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Foo::~Foo() {} - -#pragma cyclus def clone cycamore::Foo - -#pragma cyclus def schema cycamore::Foo - -#pragma cyclus def annotations cycamore::Foo - -#pragma cyclus def infiletodb cycamore::Foo - -#pragma cyclus def snapshot cycamore::Foo - -#pragma cyclus def snapshotinv cycamore::Foo - -#pragma cyclus def initinv cycamore::Foo - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void Foo::InitFrom(Foo* m) { - #pragma cyclus impl initfromcopy cycamore::Foo - cyclus::toolkit::CommodityProducer::Copy(m); -} - -void Foo::InitFrom(cyclus::QueryableBackend* b) { - #pragma cyclus impl initfromdb cycamore::Foo - - commod_ = cyclus::toolkit::Commodity(out_commod); - cyclus::toolkit::CommodityProducer::Add(commod_); - cyclus::toolkit::CommodityProducer::SetCapacity(commod_, capacity); - cyclus::toolkit::CommodityProducer::SetCost(commod_, capacity); -} - -void Foo::EnterNotify() { - Facility::EnterNotify(); - commod_ = cyclus::toolkit::Commodity(out_commod); - cyclus::toolkit::CommodityProducer::Add(commod_); - cyclus::toolkit::CommodityProducer::SetCapacity(commod_, capacity); - cyclus::toolkit::CommodityProducer::SetCost(commod_, capacity); -} - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -std::string Foo::str() { - std::stringstream ss; - std::string ans; - if (cyclus::toolkit::CommodityProducer:: - Produces(cyclus::toolkit::Commodity(out_commod))) { - ans = "yes"; - } else { - ans = "no"; - } - ss << cyclus::Facility::str() - << " supplies commodity '" - << out_commod << "' with recipe '" - << recipe_name << "' at a capacity of " - << capacity << " kg per time step " - << " commod producer members: " << " produces " - << out_commod << "?: " << ans - << " capacity: " << cyclus::toolkit::CommodityProducer::Capacity(commod_) - << " cost: " << cyclus::toolkit::CommodityProducer::Cost(commod_); - return ss.str(); -} - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void Foo::Tick() { - LOG(cyclus::LEV_INFO3, "SrcFac") << prototype() << " is ticking {"; - LOG(cyclus::LEV_INFO4, "SrcFac") << "will offer " << capacity - << " kg of " - << out_commod << "."; - LOG(cyclus::LEV_INFO3, "SrcFac") << "Stats: " << str(); - LOG(cyclus::LEV_INFO3, "SrcFac") << "}"; - current_capacity = capacity; // reset capacity -} - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void Foo::Tock() { - LOG(cyclus::LEV_INFO3, "SrcFac") << prototype() << " is tocking {"; - LOG(cyclus::LEV_INFO3, "SrcFac") << "}"; -} - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -cyclus::Material::Ptr Foo::GetOffer( - const cyclus::Material::Ptr target) const { - using cyclus::Material; - double qty = std::min(target->quantity(), capacity); - return Material::CreateUntracked(qty, context()->GetRecipe(recipe_name)); -} - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -std::set::Ptr> -Foo::GetMatlBids( - cyclus::CommodMap::type& commod_requests) { - using cyclus::Bid; - using cyclus::BidPortfolio; - using cyclus::CapacityConstraint; - using cyclus::Material; - using cyclus::Request; - - std::set::Ptr> ports; - - if (commod_requests.count(out_commod) > 0) { - BidPortfolio::Ptr port(new BidPortfolio()); - - std::vector*>& requests = - commod_requests[out_commod]; - - std::vector*>::iterator it; - for (it = requests.begin(); it != requests.end(); ++it) { - Request* req = *it; - Material::Ptr offer = GetOffer(req->target()); - port->AddBid(req, offer, this); - } - - CapacityConstraint cc(capacity); - port->AddConstraint(cc); - ports.insert(port); - } - return ports; -} - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void Foo::GetMatlTrades( - const std::vector< cyclus::Trade >& trades, - std::vector, - cyclus::Material::Ptr> >& responses) { - using cyclus::Material; - using cyclus::Trade; - - double provided = 0; - std::vector< cyclus::Trade >::const_iterator it; - for (it = trades.begin(); it != trades.end(); ++it) { - double qty = it->amt; - current_capacity -= qty; - provided += qty; - // @TODO we need a policy on negatives.. - Material::Ptr response = Material::Create(this, qty, - context()->GetRecipe(recipe_name)); - responses.push_back(std::make_pair(*it, response)); - LOG(cyclus::LEV_INFO5, "SrcFac") << prototype() << " just received an order" - << " for " << qty - << " of " << out_commod; - } - if (cyclus::IsNegative(current_capacity)) { - std::stringstream ss; - ss << "is being asked to provide " << provided - << " but its capacity is " << capacity << "."; - throw cyclus::ValueError(Agent::InformErrorMsg(ss.str())); - } -} - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -extern "C" cyclus::Agent* ConstructFoo(cyclus::Context* ctx) { - return new Foo(ctx); -} - -} // namespace cycamore diff --git a/src/foo.h b/src/foo.h deleted file mode 100644 index e35ab83d99..0000000000 --- a/src/foo.h +++ /dev/null @@ -1,204 +0,0 @@ -#ifndef CYCAMORE_SRC_FOO_H_ -#define CYCAMORE_SRC_FOO_H_ - -#include -#include - -#include "cyclus.h" - -namespace cycamore { - -class Context; - -/// @class Foo -/// This cyclus::Facility provides a simple source of some capacity -/// (possibly infinite) of some commodity/Recipe. - -/// The Foo class inherits from the cyclus::Facility class and is -/// dynamically loaded by the Agent class when requested. - -/// @section introduction Introduction -/// The Foo is a facility type in Cyclus capable of providing -/// a finite or infinite.Supply of a particular material to the -/// simulation. A Foo generates material of a certain -/// composition and commodity type, then offers that material on the -/// appropriate market. Shipments of this material are executed when the -/// market issues an order that the offer has been matched with a -/// request. - -/// @section agentparams Agent Parameters -/// Foo behavior is comprehensively defined by the following -/// parameters: -/// - double capacity: The production capacity of the facility (units -/// vary, but typically kg/month). Capacity is infinite if a negative -/// value is provided. -/// - int startDate: The date on which the facility begins to operate -/// (months). -/// - int lifeTime: The length of time that the facility operates -/// (months). - std::string outCommod: the commodity that this facility -/// produces - double inventorysize: the maximum quantity of material to -/// be held in the inventory -/// - double commodprice: the price of the output material PER UNIT -/// - map outComp - -/// @section optionalparams Optional Parameters -/// Foo behavior may also be specified with the following -/// optional parameters which have default values listed here. -/// - double capacityFactor: The ratio of actual production capacity to -/// the rated production capacity. Default is 1 (actual/rated). -/// - double availFactor: The percent of time the facility operates at -/// its capacity factor. Default is 100%. -/// - double capitalCost: The cost of constructing and commissioning -/// this facility. Default is 0 ($). -/// - double opCost: The annual cost of operation and maintenance of -/// this facility. Default is 0 ( $/year). -/// - int constrTime: The number of months it takes to construct and -/// commission this facility. Default is 0 (months). -/// - int decomTime: The number of months it takes to deconstruct and -/// decommission this facility. Default is 0 (months). -/// - Inst* inst: The institution responsible for this facility. -/// - string name: A non-generic name for this facility. - -/// @section detailed Detailed Behavior -/// @subsection finite If Finite Capacity: -/// The Foo starts operation when the simulation reaches the -/// month specified as the startDate. It immediately begins to produce -/// material at the rate defined by its capacity. Each month the -/// Foo adds the amount it has produced to its inventory. It -/// then offers to the appropriate market exactly as much material as it -/// has in its inventory. If an offer is matched with a request, the -/// Foo executes that order by subtracting the quantity from -/// its inventory and sending that amount to the requesting facility. -/// When the simulation time equals the startDate plus the lifeTime, the -/// facility ceases to operate. -/// @subsection infinite If Infinite Capacity: -/// The Foo starts operation when the simulation reaches the -/// month specified as the startDate. Each month the Foo -/// offers an infinite amount of material to the appropriate market. If -/// there is a request for that material, the Foo executes -/// that order by sending that amount to the requesting facility. When -/// the simulation time equals the startDate plus the lifeTime, the -/// facility ceases to operate. - -/// @subsection question Question: -/// What is the best way to allow offers of an infinite amount of -/// material on a market? - -class Foo : public cyclus::Facility, - public cyclus::toolkit::CommodityProducer { - public: - // --- Module Members --- - /// Constructor for the Foo class - /// @param ctx the cyclus context for access to simulation-wide parameters - Foo(cyclus::Context* ctx); - - virtual ~Foo() - - #pragma cyclus decl - - #pragma cyclus note {"doc": "A source facility that provides a " \ - "commodity with a given capacity"} - - /// Print information about this agent - virtual std::string str(); - // --- - - // --- Agent Members --- - virtual void EnterNotify(); - - /// Each facility is prompted to do its beginning-of-time-step - /// stuff at the tick of the timer. - - /// @param time is the time to perform the tick - virtual void Tick(); - - /// Each facility is prompted to its end-of-time-step - /// stuff on the tock of the timer. - - /// @param time is the time to perform the tock - virtual void Tock(); - - /// @brief Responds to each request for this source facility's commodity. - /// If a given request is more than this facility's capacity, it will offer - /// its capacity. - virtual std::set::Ptr> - GetMatlBids(cyclus::CommodMap::type& - commod_requests); - - /// @brief respond to each trade with a material made from this facility's - /// recipe - /// - /// @param trades all trades in which this trader is the supplier - /// @param responses a container to populate with responses to each trade - virtual void GetMatlTrades( - const std::vector< cyclus::Trade >& trades, - std::vector, - cyclus::Material::Ptr> >& responses); - // --- - - // --- Foo Members --- - /// @brief creates a material object to offer to a requester - /// @param target the material target a request desires - cyclus::Material::Ptr GetOffer(const cyclus::Material::Ptr target) const; - - /// sets the output commodity name - /// @param name the commodity name - inline void commodity(std::string name) { out_commod = name; } - - /// @return the output commodity - inline std::string commodity() const { return out_commod; } - - /// sets the capacity of a material generated at any given time step - /// @param capacity the production capacity - inline void Capacity(double cap) { - capacity = cap; - current_capacity = capacity; - } - - /// @return the production capacity at any given time step - inline double Capacity() const { return capacity; } - - /// sets the name of the recipe to be produced - /// @param name the recipe name - inline void recipe(std::string name) { recipe_name = name; } - - /// @return the name of the output recipe - inline std::string recipe() const { return recipe_name; } - - /// @return the current timestep's capacity - inline double CurrentCapacity() const { return current_capacity; } - - private: - cyclus::toolkit::Commodity commod_; - - /// This facility has only one output commodity - #pragma cyclus var {"tooltip": "source output commodity", \ - "doc": "output commodity that the source facility " \ - "supplies", \ - "uitype": "outcommodity"} - std::string out_commod; - - /// Name of the recipe this facility uses. - #pragma cyclus var {"tooltip": "commodity recipe name", \ - "doc": "recipe name for source facility's commodity", \ - "uitype": "recipe"} - std::string recipe_name; - - /// The capacity is defined in terms of the number of units of the - /// recipe that can be provided each time step. A very large number - /// can be provided to represent infinte capacity. - #pragma cyclus var {"default": 1e299, "tooltip": "source capacity", \ - "doc": "amount of commodity that can be supplied " \ - "at each time step"} - double capacity; - - /// The capacity at the current time step - #pragma cyclus var {'derived_init': 'current_capacity = capacity;'} - double current_capacity; - - // --- -}; - -} // namespace cycamore - -#endif // CYCAMORE_SRC_FOO_H_ diff --git a/src/foo_tests.cc b/src/foo_tests.cc deleted file mode 100644 index 0973e794d0..0000000000 --- a/src/foo_tests.cc +++ /dev/null @@ -1,204 +0,0 @@ -#include "foo_tests.h" - -#include - -#include - -#include "cyc_limits.h" -#include "resource_helpers.h" -#include "test_context.h" - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void FooTest::SetUp() { - src_facility = new cycamore::Foo(tc.get()); - trader = tc.trader(); - InitParameters(); - SetUpFoo(); -} - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void FooTest::TearDown() { - delete src_facility; -} - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void FooTest::InitParameters() { - commod = "commod"; - recipe_name = "recipe"; - capacity = 5; // some magic number.. - - recipe = cyclus::Composition::CreateFromAtom(cyclus::CompMap()); - tc.get()->AddRecipe(recipe_name, recipe); -} - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void FooTest::SetUpFoo() { - src_facility->commodity(commod); - src_facility->recipe(recipe_name); - src_facility->Capacity(capacity); -} - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -TEST_F(FooTest, InitialState) { - EXPECT_EQ(src_facility->Capacity(), capacity); - EXPECT_EQ(src_facility->commodity(), commod); - EXPECT_EQ(src_facility->recipe(), recipe_name); - EXPECT_EQ(src_facility->CurrentCapacity(), capacity); -} - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -TEST_F(FooTest, Clone) { - cyclus::Context* ctx = tc.get(); - cycamore::Foo* cloned_fac = dynamic_cast - (src_facility->Clone()); - - EXPECT_EQ(src_facility->commodity(), cloned_fac->commodity()); - EXPECT_EQ(src_facility->Capacity(), cloned_fac->Capacity()); - EXPECT_EQ(src_facility->recipe(), cloned_fac->recipe()); - EXPECT_EQ(src_facility->Capacity(), cloned_fac->CurrentCapacity()); - - delete cloned_fac; -} - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -TEST_F(FooTest, Print) { - EXPECT_NO_THROW(std::string s = src_facility->str()); -} - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -TEST_F(FooTest, GetOffer) { - using cyclus::Material; - - double qty = capacity - 1; - Material::Ptr mat = cyclus::NewBlankMaterial(qty); - Material::Ptr obs_mat = src_facility->GetOffer(mat); - EXPECT_EQ(obs_mat->quantity(), qty); - EXPECT_EQ(obs_mat->comp(), recipe); - - qty = capacity + 1; - mat = cyclus::NewBlankMaterial(qty); - obs_mat = src_facility->GetOffer(mat); - EXPECT_EQ(obs_mat->quantity(), capacity); - EXPECT_EQ(obs_mat->comp(), recipe); - - qty = capacity; - mat = cyclus::NewBlankMaterial(qty); - obs_mat = src_facility->GetOffer(mat); - EXPECT_EQ(obs_mat->quantity(), capacity); - EXPECT_EQ(obs_mat->comp(), recipe); -} - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -TEST_F(FooTest, AddBids) { - using cyclus::Bid; - using cyclus::BidPortfolio; - using cyclus::CapacityConstraint; - using cyclus::ExchangeContext; - using cyclus::Material; - - int nreqs = 5; - - boost::shared_ptr< cyclus::ExchangeContext > - ec = GetContext(nreqs, commod); - - std::set::Ptr> ports = - src_facility->GetMatlBids(ec.get()->commod_requests); - - ASSERT_TRUE(ports.size() > 0); - EXPECT_EQ(ports.size(), 1); - - BidPortfolio::Ptr port = *ports.begin(); - EXPECT_EQ(port->bidder(), src_facility); - EXPECT_EQ(port->bids().size(), nreqs); - - const std::set< CapacityConstraint >& constrs = port->constraints(); - ASSERT_TRUE(constrs.size() > 0); - EXPECT_EQ(constrs.size(), 1); - EXPECT_EQ(*constrs.begin(), CapacityConstraint(capacity)); -} - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -TEST_F(FooTest, Response) { - using cyclus::Bid; - using cyclus::Material; - using cyclus::Request; - using cyclus::Trade; - using test_helpers::get_mat; - - std::vector< cyclus::Trade > trades; - std::vector, - cyclus::Material::Ptr> > responses; - - // Null response - EXPECT_NO_THROW(src_facility->GetMatlTrades(trades, responses)); - EXPECT_EQ(responses.size(), 0); - - double qty = capacity / 3; - Request* request = - Request::Create(get_mat(), trader, commod); - Bid* bid = - Bid::Create(request, get_mat(), src_facility); - - Trade trade(request, bid, qty); - trades.push_back(trade); - - // 1 trade - ASSERT_EQ(src_facility->CurrentCapacity(), capacity); - src_facility->GetMatlTrades(trades, responses); - EXPECT_EQ(responses.size(), 1); - EXPECT_EQ(responses[0].second->quantity(), qty); - EXPECT_EQ(responses[0].second->comp(), recipe); - - // 2 trades, total qty = capacity - ASSERT_DOUBLE_EQ(src_facility->CurrentCapacity(), capacity - qty); - ASSERT_GT(src_facility->CurrentCapacity() - 2 * qty, -1 * cyclus::eps()); - trades.push_back(trade); - responses.clear(); - EXPECT_NO_THROW(src_facility->GetMatlTrades(trades, responses)); - EXPECT_EQ(responses.size(), 2); - ASSERT_TRUE(cyclus::AlmostEq(src_facility->CurrentCapacity(), 0)); - - // too much qty, capn! - EXPECT_THROW(src_facility->GetMatlTrades(trades, responses), - cyclus::ValueError); - - // reset! - src_facility->Tick(); - ASSERT_DOUBLE_EQ(src_facility->CurrentCapacity(), capacity); - - delete request; - delete bid; -} - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -boost::shared_ptr< cyclus::ExchangeContext > -FooTest::GetContext(int nreqs, std::string commod) { - using cyclus::Material; - using cyclus::Request; - using cyclus::ExchangeContext; - using test_helpers::get_mat; - - double qty = 3; - boost::shared_ptr< ExchangeContext > - ec(new ExchangeContext()); - for (int i = 0; i < nreqs; i++) { - ec->AddRequest(Request::Create(get_mat(), trader, commod)); - } - return ec; -} - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -cyclus::Agent* FooConstructor(cyclus::Context* ctx) { - return new cycamore::Foo(ctx); -} - -// required to get functionality in cyclus agent unit tests library -#ifndef CYCLUS_AGENT_TESTS_CONNECTED -int ConnectAgentTests(); -static int cyclus_agent_tests_connected = ConnectAgentTests(); -#define CYCLUS_AGENT_TESTS_CONNECTED cyclus_agent_tests_connected -#endif // CYCLUS_AGENT_TESTS_CONNECTED - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -INSTANTIATE_TEST_CASE_P(FooFac, FacilityTests, Values(&FooConstructor)); -INSTANTIATE_TEST_CASE_P(FooFac, AgentTests, Values(&FooConstructor)); diff --git a/src/foo_tests.h b/src/foo_tests.h deleted file mode 100644 index 59888926b7..0000000000 --- a/src/foo_tests.h +++ /dev/null @@ -1,34 +0,0 @@ -#ifndef CYCAMORE_SRC_FOO_TESTS_H_ -#define CYCAMORE_SRC_FOO_TESTS_H_ -#include "foo.h" - -#include - -#include - -#include "agent_tests.h" -#include "context.h" -#include "exchange_context.h" -#include "facility_tests.h" -#include "material.h" - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -class FooTest : public ::testing::Test { - public: - cyclus::TestContext tc; - TestFacility* trader; - cycamore::Foo* src_facility; - std::string commod, recipe_name; - double capacity; - cyclus::Composition::Ptr recipe; - - virtual void SetUp(); - virtual void TearDown(); - void InitParameters(); - void SetUpFoo(); - - boost::shared_ptr< cyclus::ExchangeContext > - GetContext(int nreqs, std::string commodity); -}; - -#endif // CYCAMORE_SRC_FOO_TESTS_H_ From 8e904cdf8ddedbb16a18f6aa6487df6e33734ee7 Mon Sep 17 00:00:00 2001 From: Matthew Gidden Date: Thu, 23 Apr 2015 14:55:17 -0500 Subject: [PATCH 34/80] this should fail unit tests --- src/source_tests.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/source_tests.cc b/src/source_tests.cc index eea1d9c38d..556623a82f 100644 --- a/src/source_tests.cc +++ b/src/source_tests.cc @@ -107,7 +107,7 @@ TEST_F(SourceTest, Response) { // 1 trade src_facility->GetMatlTrades(trades, responses); EXPECT_EQ(responses.size(), 1); - EXPECT_EQ(responses[0].second->quantity(), qty); + EXPECT_EQ(responses[0].second->quantity(), qty + 1); EXPECT_EQ(responses[0].second->comp(), recipe); // 2 trades, total qty = capacity From 713a9d409c54583e14f75df472d8e50216d9d22f Mon Sep 17 00:00:00 2001 From: Matthew Gidden Date: Thu, 23 Apr 2015 15:04:56 -0500 Subject: [PATCH 35/80] Revert "this should fail unit tests" This reverts commit 8e904cdf8ddedbb16a18f6aa6487df6e33734ee7. --- src/source_tests.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/source_tests.cc b/src/source_tests.cc index 556623a82f..eea1d9c38d 100644 --- a/src/source_tests.cc +++ b/src/source_tests.cc @@ -107,7 +107,7 @@ TEST_F(SourceTest, Response) { // 1 trade src_facility->GetMatlTrades(trades, responses); EXPECT_EQ(responses.size(), 1); - EXPECT_EQ(responses[0].second->quantity(), qty + 1); + EXPECT_EQ(responses[0].second->quantity(), qty); EXPECT_EQ(responses[0].second->comp(), recipe); // 2 trades, total qty = capacity From 1d3457a29e9f423c3b524b5d495897c7350cf458 Mon Sep 17 00:00:00 2001 From: Matthew Gidden Date: Thu, 23 Apr 2015 15:32:58 -0500 Subject: [PATCH 36/80] Addressing @scopatz's comments --- .travis-install.sh | 10 ++++------ .travis.yml | 2 -- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/.travis-install.sh b/.travis-install.sh index 1f9e8a8e15..c6a2e10c90 100755 --- a/.travis-install.sh +++ b/.travis-install.sh @@ -1,5 +1,7 @@ #!/bin/bash +set -x + # log msg=`git log --pretty=oneline -1` echo "Building commit: $msg" @@ -10,9 +12,7 @@ unzip -j ciclus.zip "*/cycamore/*" -d conda-recipe sed -i "s/- cyclus/- cyclus 0.0/g" conda-recipe/meta.yaml # build -cmd="conda build --no-test conda-recipe" -echo "cmd: $cmd" -$cmd +conda build --no-test conda-recipe status=$? echo "status: $status" if [[ $status != 0 ]]; then @@ -20,9 +20,7 @@ if [[ $status != 0 ]]; then fi # install -cmd="conda install --use-local cycamore=0.0" -echo "cmd: $cmd" -$cmd +conda install --use-local cycamore=0.0 status=$? echo "status: $status" if [[ $status != 0 ]]; then diff --git a/.travis.yml b/.travis.yml index 5153f20149..54cdd1f8ad 100644 --- a/.travis.yml +++ b/.travis.yml @@ -39,8 +39,6 @@ install: script: - export PATH="$HOME/miniconda/bin:$PATH" - export LD_LIBRARY_PATH="$HOME/miniconda/lib:$LD_LIBRARY_PATH" - #- ls -l $HOME/miniconda/lib - #- ls -l $HOME/miniconda/envs/_build/lib - cycamore_unit_tests - conda install numpy pytables - nosetests -w tests From 2b9d07d7f18dc9bb1060233a016256007982fc1a Mon Sep 17 00:00:00 2001 From: Matthew Gidden Date: Thu, 23 Apr 2015 15:38:05 -0500 Subject: [PATCH 37/80] set -e --- .travis-install.sh | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/.travis-install.sh b/.travis-install.sh index c6a2e10c90..f4cf6adae1 100755 --- a/.travis-install.sh +++ b/.travis-install.sh @@ -1,6 +1,7 @@ #!/bin/bash -set -x +set -x # print cmds +set -e # exit as soon as an error occurs # log msg=`git log --pretty=oneline -1` @@ -13,16 +14,6 @@ sed -i "s/- cyclus/- cyclus 0.0/g" conda-recipe/meta.yaml # build conda build --no-test conda-recipe -status=$? -echo "status: $status" -if [[ $status != 0 ]]; then - exit $status -fi # install conda install --use-local cycamore=0.0 -status=$? -echo "status: $status" -if [[ $status != 0 ]]; then - exit $status -fi From 91bdb3ae84d6c0cb06cd17ad698cbf65b64a9a68 Mon Sep 17 00:00:00 2001 From: Matthew Gidden Date: Thu, 23 Apr 2015 15:04:32 -0500 Subject: [PATCH 38/80] removed testing-specific repo and branch info --- .travis.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 54cdd1f8ad..6a126fed6a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -27,9 +27,8 @@ install: - conda info -a # install cyclus - - git clone https://github.com/gidden/cyclus ../cyclus + - git clone https://github.com/cyclus/cyclus ../cyclus - cd ../cyclus - - git checkout origin/travis - ./.travis-install.sh - cd ../cycamore From 3158b7c935e51fa3696e3af49a4fadb92f810144 Mon Sep 17 00:00:00 2001 From: Matthew Gidden Date: Thu, 23 Apr 2015 15:35:05 -0500 Subject: [PATCH 39/80] updating ciclus pull --- .travis-install.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis-install.sh b/.travis-install.sh index f4cf6adae1..0ec08d2ea3 100755 --- a/.travis-install.sh +++ b/.travis-install.sh @@ -8,7 +8,7 @@ msg=`git log --pretty=oneline -1` echo "Building commit: $msg" # setup conda recipe -wget https://github.com/gidden/ciclus/archive/travis.zip -O ciclus.zip +wget https://github.com/cyclus/ciclus/archive/master.zip -O ciclus.zip unzip -j ciclus.zip "*/cycamore/*" -d conda-recipe sed -i "s/- cyclus/- cyclus 0.0/g" conda-recipe/meta.yaml From ab36e381de17cb7b8a9bb5c5c6692d84a732d199 Mon Sep 17 00:00:00 2001 From: Matthew Gidden Date: Tue, 21 Apr 2015 10:32:28 -0500 Subject: [PATCH 40/80] adding travis.yml --- .travis.yml | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000000..3becb17748 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,49 @@ +language: python +python: + # We don't actually use the Travis Python, but this keeps it organized. + - "2.7" + - "3.4" + +before_install: + - sudo apt-get update -qq + +install: + # You may want to periodically update this, although the conda update + # conda line below will keep everything up-to-date. We do this + # conditionally because it saves us some downloading if the version is + # the same. + - if [[ "$TRAVIS_PYTHON_VERSION" == "2.7" ]]; then + wget http://repo.continuum.io/miniconda/Miniconda-latest-Linux-x86_64.sh -O miniconda.sh; + else + wget http://repo.continuum.io/miniconda/Miniconda3-latest-Linux-x86_64.sh -O miniconda.sh; + fi + - bash miniconda.sh -b -p $HOME/miniconda + - export PATH="$HOME/miniconda/bin:$PATH" + - hash -r + - conda config --set always_yes yes --set changeps1 no + - conda config --add channels pyne + - conda config --add channels cyclus + - conda config --add channels cycamore + - conda update -q conda + - conda install conda-build jinja2 setuptools binstar patchelf nose + # Useful for debugging any issues with conda + - conda info -a + + # download CI repo + - wget https://github.com/cyclus/ciclus/archive/master.zip -O ciclus.zip + - unzip -j ciclus.zip "*/cycamore/*" -d conda-recipe + + # Replace dep1 dep2 ... with your dependencies + #- conda create -q -n test-environment python=$TRAVIS_PYTHON_VERSION dep1 dep2 ... + #- source activate test-environment + - conda build --no-test conda-recipe + - conda install cycamore --use-local + +script: + - cycamore_unit_tests + - nosetests -w tests + #- cd tests + #- nosetests + #- ./travis-run-tests.sh + + From 40d4eb90a5d72e6fe9d56aa8dd127ef72cbd88ad Mon Sep 17 00:00:00 2001 From: Matthew Gidden Date: Tue, 21 Apr 2015 13:39:20 -0500 Subject: [PATCH 41/80] rm cycamore as binstar user --- .travis.yml | 3 --- 1 file changed, 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 3becb17748..12755d392b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,10 +3,8 @@ python: # We don't actually use the Travis Python, but this keeps it organized. - "2.7" - "3.4" - before_install: - sudo apt-get update -qq - install: # You may want to periodically update this, although the conda update # conda line below will keep everything up-to-date. We do this @@ -23,7 +21,6 @@ install: - conda config --set always_yes yes --set changeps1 no - conda config --add channels pyne - conda config --add channels cyclus - - conda config --add channels cycamore - conda update -q conda - conda install conda-build jinja2 setuptools binstar patchelf nose # Useful for debugging any issues with conda From 6d7cead8c0709ddde74f5f0484f9be18d6367834 Mon Sep 17 00:00:00 2001 From: Matthew Gidden Date: Tue, 21 Apr 2015 16:51:47 -0500 Subject: [PATCH 42/80] updating path and tables install --- .travis.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 12755d392b..f8e2e5d435 100644 --- a/.travis.yml +++ b/.travis.yml @@ -22,7 +22,7 @@ install: - conda config --add channels pyne - conda config --add channels cyclus - conda update -q conda - - conda install conda-build jinja2 setuptools binstar patchelf nose + - conda install conda-build setuptools binstar patchelf nose # Useful for debugging any issues with conda - conda info -a @@ -37,6 +37,8 @@ install: - conda install cycamore --use-local script: + - export PATH="$HOME/miniconda/bin:$PATH" + - conda install tables - cycamore_unit_tests - nosetests -w tests #- cd tests From e98ddb668eac212aebe002389d62df66199e2d1a Mon Sep 17 00:00:00 2001 From: Matthew Gidden Date: Tue, 21 Apr 2015 16:52:55 -0500 Subject: [PATCH 43/80] numpy install --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index f8e2e5d435..061440d20b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -38,7 +38,7 @@ install: script: - export PATH="$HOME/miniconda/bin:$PATH" - - conda install tables + - conda install numpy tables - cycamore_unit_tests - nosetests -w tests #- cd tests From b368f7414437de87fe4c0b176ebaa167b9990204 Mon Sep 17 00:00:00 2001 From: Matthew Gidden Date: Wed, 22 Apr 2015 10:56:36 -0500 Subject: [PATCH 44/80] updating from cyclus yml --- .travis.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.travis.yml b/.travis.yml index 061440d20b..dc2c452196 100644 --- a/.travis.yml +++ b/.travis.yml @@ -38,6 +38,11 @@ install: script: - export PATH="$HOME/miniconda/bin:$PATH" + - export LD_LIBRARY_PATH="$HOME/miniconda/lib:$HOME/miniconda/envs/_build/lib:$LD_LIBRARY_PATH" + - ls -l $HOME/miniconda/lib + - ls -l $HOME/miniconda/envs/_build/lib + - ln -s $HOME/miniconda/lib/libhdf5.so.9 $HOME/miniconda/lib/libhdf5.so.8 + - ln -s $HOME/miniconda/lib/libhdf5_hl.so.9 $HOME/miniconda/lib/libhdf5_hl.so.8 - conda install numpy tables - cycamore_unit_tests - nosetests -w tests From de669a0896d92e7d2aaa92b9c4c05a0501557d94 Mon Sep 17 00:00:00 2001 From: Matthew Gidden Date: Wed, 22 Apr 2015 17:48:36 -0500 Subject: [PATCH 45/80] matching cyclus --- .travis.yml | 34 ++++++++++++++++------------------ 1 file changed, 16 insertions(+), 18 deletions(-) diff --git a/.travis.yml b/.travis.yml index dc2c452196..0bdcac5064 100644 --- a/.travis.yml +++ b/.travis.yml @@ -22,32 +22,30 @@ install: - conda config --add channels pyne - conda config --add channels cyclus - conda update -q conda - - conda install conda-build setuptools binstar patchelf nose + - conda install conda-build jinja2 setuptools binstar patchelf nose # Useful for debugging any issues with conda - conda info -a # download CI repo - wget https://github.com/cyclus/ciclus/archive/master.zip -O ciclus.zip - - unzip -j ciclus.zip "*/cycamore/*" -d conda-recipe - - # Replace dep1 dep2 ... with your dependencies - #- conda create -q -n test-environment python=$TRAVIS_PYTHON_VERSION dep1 dep2 ... - #- source activate test-environment - - conda build --no-test conda-recipe - - conda install cycamore --use-local + - unzip -j ciclus.zip + + # build cyclus + - mv ciclus/cyclus conda-recipe-cyclus + - conda build --no-test conda-recipe-cyclus + - conda install --use-local cyclus=0.0 + + # build cycamore + - mv ciclus/cycamore conda-recipe-cycamore + - conda build --no-test conda-recipe-cycamore + - conda install --use-local cycamore=0.0 script: - export PATH="$HOME/miniconda/bin:$PATH" - - export LD_LIBRARY_PATH="$HOME/miniconda/lib:$HOME/miniconda/envs/_build/lib:$LD_LIBRARY_PATH" - - ls -l $HOME/miniconda/lib - - ls -l $HOME/miniconda/envs/_build/lib - - ln -s $HOME/miniconda/lib/libhdf5.so.9 $HOME/miniconda/lib/libhdf5.so.8 - - ln -s $HOME/miniconda/lib/libhdf5_hl.so.9 $HOME/miniconda/lib/libhdf5_hl.so.8 - - conda install numpy tables + - export LD_LIBRARY_PATH="$HOME/miniconda/lib:$LD_LIBRARY_PATH" + #- ls -l $HOME/miniconda/lib + #- ls -l $HOME/miniconda/envs/_build/lib - cycamore_unit_tests + - conda install numpy tables - nosetests -w tests - #- cd tests - #- nosetests - #- ./travis-run-tests.sh - From 66c27450a61e0445edb5b65c93dc72a083d26481 Mon Sep 17 00:00:00 2001 From: Matthew Gidden Date: Wed, 22 Apr 2015 17:50:17 -0500 Subject: [PATCH 46/80] grabbing correct ciclus --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 0bdcac5064..1d51093559 100644 --- a/.travis.yml +++ b/.travis.yml @@ -27,7 +27,7 @@ install: - conda info -a # download CI repo - - wget https://github.com/cyclus/ciclus/archive/master.zip -O ciclus.zip + - wget https://github.com/gidden/ciclus/archive/travis.zip -O ciclus.zip - unzip -j ciclus.zip # build cyclus From 8bf8e9164e66e583fb8a0bd737cb35aefdfd2ac6 Mon Sep 17 00:00:00 2001 From: Matthew Gidden Date: Wed, 22 Apr 2015 18:13:53 -0500 Subject: [PATCH 47/80] mirroring cyclus unzip --- .travis.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 1d51093559..d6eb10b32b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -28,14 +28,15 @@ install: # download CI repo - wget https://github.com/gidden/ciclus/archive/travis.zip -O ciclus.zip - - unzip -j ciclus.zip # build cyclus + - unzip -j ciclus.zip "*/cyclus/*" -d conda-recipe-cyclus - mv ciclus/cyclus conda-recipe-cyclus - conda build --no-test conda-recipe-cyclus - conda install --use-local cyclus=0.0 # build cycamore + - unzip -j ciclus.zip "*/cycamore/*" -d conda-recipe-cycamore - mv ciclus/cycamore conda-recipe-cycamore - conda build --no-test conda-recipe-cycamore - conda install --use-local cycamore=0.0 From 1816731e95996d49006299503b1a9b53273a6fc8 Mon Sep 17 00:00:00 2001 From: Matthew Gidden Date: Wed, 22 Apr 2015 18:23:41 -0500 Subject: [PATCH 48/80] rm mvs --- .travis.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index d6eb10b32b..09c1b2a1bf 100644 --- a/.travis.yml +++ b/.travis.yml @@ -31,13 +31,11 @@ install: # build cyclus - unzip -j ciclus.zip "*/cyclus/*" -d conda-recipe-cyclus - - mv ciclus/cyclus conda-recipe-cyclus - conda build --no-test conda-recipe-cyclus - conda install --use-local cyclus=0.0 # build cycamore - unzip -j ciclus.zip "*/cycamore/*" -d conda-recipe-cycamore - - mv ciclus/cycamore conda-recipe-cycamore - conda build --no-test conda-recipe-cycamore - conda install --use-local cycamore=0.0 From 0c703195fc9a8dbf8618671617ef44c4f76ab157 Mon Sep 17 00:00:00 2001 From: Matthew Gidden Date: Wed, 22 Apr 2015 18:34:34 -0500 Subject: [PATCH 49/80] maybe conda-recipe name matters --- .travis.yml | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index 09c1b2a1bf..9e414d829c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -30,13 +30,14 @@ install: - wget https://github.com/gidden/ciclus/archive/travis.zip -O ciclus.zip # build cyclus - - unzip -j ciclus.zip "*/cyclus/*" -d conda-recipe-cyclus - - conda build --no-test conda-recipe-cyclus + - unzip -j ciclus.zip "*/cyclus/*" -d conda-recipe + - conda build --no-test conda-recipe - conda install --use-local cyclus=0.0 + - mv conda-recipe conda-recipe-cyclus # build cycamore - - unzip -j ciclus.zip "*/cycamore/*" -d conda-recipe-cycamore - - conda build --no-test conda-recipe-cycamore + - unzip -j ciclus.zip "*/cycamore/*" -d conda-recipe + - conda build --no-test conda-recipe - conda install --use-local cycamore=0.0 script: From eaadc31959e0b3183147de002f31eed39c15b47d Mon Sep 17 00:00:00 2001 From: Matthew Gidden Date: Thu, 23 Apr 2015 08:55:28 -0500 Subject: [PATCH 50/80] trying now with sedding the right cyclus --- .travis.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 9e414d829c..08589b0985 100644 --- a/.travis.yml +++ b/.travis.yml @@ -33,12 +33,14 @@ install: - unzip -j ciclus.zip "*/cyclus/*" -d conda-recipe - conda build --no-test conda-recipe - conda install --use-local cyclus=0.0 - - mv conda-recipe conda-recipe-cyclus + - mv conda-recipe cyclus-recipe # build cycamore - unzip -j ciclus.zip "*/cycamore/*" -d conda-recipe + - sed -i "s/- cyclus/- cyclus=0.0/g" conda-recipe/meta.yaml - conda build --no-test conda-recipe - conda install --use-local cycamore=0.0 + - mv conda-recipe cycamore-recipe script: - export PATH="$HOME/miniconda/bin:$PATH" From 16f31aa5aa5e58d3fada8a4c4c7125a89ad8d719 Mon Sep 17 00:00:00 2001 From: Matthew Gidden Date: Thu, 23 Apr 2015 09:02:51 -0500 Subject: [PATCH 51/80] trying some cyclus foo --- .travis.yml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/.travis.yml b/.travis.yml index 08589b0985..d2ca4ae79a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -30,10 +30,17 @@ install: - wget https://github.com/gidden/ciclus/archive/travis.zip -O ciclus.zip # build cyclus + - pwd=$PWD + - echo "pwd: $pwd" + - cd $HOME + - git clone git@github.com:gidden/cyclus + - cd cyclus + - git checkout origin/travis - unzip -j ciclus.zip "*/cyclus/*" -d conda-recipe - conda build --no-test conda-recipe - conda install --use-local cyclus=0.0 - mv conda-recipe cyclus-recipe + - cd $pwd # build cycamore - unzip -j ciclus.zip "*/cycamore/*" -d conda-recipe From 2e4f2edc336cb9aa26dd68592d1863a7cb4deeae Mon Sep 17 00:00:00 2001 From: Matthew Gidden Date: Thu, 23 Apr 2015 09:08:50 -0500 Subject: [PATCH 52/80] travis doesn't like colons --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index d2ca4ae79a..b703ceb84a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -31,7 +31,7 @@ install: # build cyclus - pwd=$PWD - - echo "pwd: $pwd" + - echo "pwd $pwd" - cd $HOME - git clone git@github.com:gidden/cyclus - cd cyclus From 629f2b71889a43c5737d4f75326d7229ad579e80 Mon Sep 17 00:00:00 2001 From: Matthew Gidden Date: Thu, 23 Apr 2015 09:15:08 -0500 Subject: [PATCH 53/80] https for clone --- .travis.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index b703ceb84a..876463161d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -32,8 +32,8 @@ install: # build cyclus - pwd=$PWD - echo "pwd $pwd" - - cd $HOME - - git clone git@github.com:gidden/cyclus + - cd .. + - git clone https://github.com/gidden/cyclus - cd cyclus - git checkout origin/travis - unzip -j ciclus.zip "*/cyclus/*" -d conda-recipe From 80abe1a35e16184746ec65749ec01dc06127c94e Mon Sep 17 00:00:00 2001 From: Matthew Gidden Date: Thu, 23 Apr 2015 09:23:52 -0500 Subject: [PATCH 54/80] need to rewget --- .travis.yml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 876463161d..a31791ff27 100644 --- a/.travis.yml +++ b/.travis.yml @@ -26,9 +26,6 @@ install: # Useful for debugging any issues with conda - conda info -a - # download CI repo - - wget https://github.com/gidden/ciclus/archive/travis.zip -O ciclus.zip - # build cyclus - pwd=$PWD - echo "pwd $pwd" @@ -36,6 +33,7 @@ install: - git clone https://github.com/gidden/cyclus - cd cyclus - git checkout origin/travis + - wget https://github.com/gidden/ciclus/archive/travis.zip -O ciclus.zip - unzip -j ciclus.zip "*/cyclus/*" -d conda-recipe - conda build --no-test conda-recipe - conda install --use-local cyclus=0.0 @@ -43,6 +41,7 @@ install: - cd $pwd # build cycamore + - wget https://github.com/gidden/ciclus/archive/travis.zip -O ciclus.zip - unzip -j ciclus.zip "*/cycamore/*" -d conda-recipe - sed -i "s/- cyclus/- cyclus=0.0/g" conda-recipe/meta.yaml - conda build --no-test conda-recipe From a4335a564bdcf81a82134f2058f16a4c4114c71a Mon Sep 17 00:00:00 2001 From: Matthew Gidden Date: Thu, 23 Apr 2015 10:00:58 -0500 Subject: [PATCH 55/80] meta didn't like = ' --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index a31791ff27..f3b5eb5e8b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -43,7 +43,7 @@ install: # build cycamore - wget https://github.com/gidden/ciclus/archive/travis.zip -O ciclus.zip - unzip -j ciclus.zip "*/cycamore/*" -d conda-recipe - - sed -i "s/- cyclus/- cyclus=0.0/g" conda-recipe/meta.yaml + - sed -i "s/- cyclus/- cyclus 0.0/g" conda-recipe/meta.yaml - conda build --no-test conda-recipe - conda install --use-local cycamore=0.0 - mv conda-recipe cycamore-recipe From 1a52935f772abccd4a76ed289cb6f4daddd7a458 Mon Sep 17 00:00:00 2001 From: Matthew Gidden Date: Thu, 23 Apr 2015 10:20:45 -0500 Subject: [PATCH 56/80] updating for travis-install.sh --- .travis-install.sh | 5 +++++ .travis.yml | 26 +++++++------------------- 2 files changed, 12 insertions(+), 19 deletions(-) create mode 100755 .travis-install.sh diff --git a/.travis-install.sh b/.travis-install.sh new file mode 100755 index 0000000000..0ab998f721 --- /dev/null +++ b/.travis-install.sh @@ -0,0 +1,5 @@ +wget https://github.com/gidden/ciclus/archive/travis.zip -O ciclus.zip +unzip -j ciclus.zip "*/cycamore/*" -d conda-recipe +sed -i "s/- cyclus/- cyclus 0.0/g" conda-recipe/meta.yaml +conda build --no-test conda-recipe +conda install --use-local cycamore=0.0 \ No newline at end of file diff --git a/.travis.yml b/.travis.yml index f3b5eb5e8b..6eecf5b8a2 100644 --- a/.travis.yml +++ b/.travis.yml @@ -26,27 +26,15 @@ install: # Useful for debugging any issues with conda - conda info -a - # build cyclus - - pwd=$PWD - - echo "pwd $pwd" - - cd .. - - git clone https://github.com/gidden/cyclus - - cd cyclus + # install cyclus + - git clone https://github.com/gidden/cyclus ../cyclus + - cd ../cyclus - git checkout origin/travis - - wget https://github.com/gidden/ciclus/archive/travis.zip -O ciclus.zip - - unzip -j ciclus.zip "*/cyclus/*" -d conda-recipe - - conda build --no-test conda-recipe - - conda install --use-local cyclus=0.0 - - mv conda-recipe cyclus-recipe - - cd $pwd + - ./.travis-install.sh + - cd ../cycamore - # build cycamore - - wget https://github.com/gidden/ciclus/archive/travis.zip -O ciclus.zip - - unzip -j ciclus.zip "*/cycamore/*" -d conda-recipe - - sed -i "s/- cyclus/- cyclus 0.0/g" conda-recipe/meta.yaml - - conda build --no-test conda-recipe - - conda install --use-local cycamore=0.0 - - mv conda-recipe cycamore-recipe + # install cycamore + - ./.travis-install.sh script: - export PATH="$HOME/miniconda/bin:$PATH" From bf85c705e9bc5dccff3f270df846cbb1b092feb0 Mon Sep 17 00:00:00 2001 From: Matthew Gidden Date: Thu, 23 Apr 2015 10:25:51 -0500 Subject: [PATCH 57/80] matching find hdf5.cmakes with cyclus --- cmake/FindHDF5.cmake | 382 ++++++++++++++++++++++--------------------- 1 file changed, 192 insertions(+), 190 deletions(-) diff --git a/cmake/FindHDF5.cmake b/cmake/FindHDF5.cmake index 1722a7ea41..5b7cadd022 100644 --- a/cmake/FindHDF5.cmake +++ b/cmake/FindHDF5.cmake @@ -26,7 +26,7 @@ # In addition to finding the includes and libraries required to compile an HDF5 # client application, this module also makes an effort to find tools that come # with the HDF5 distribution that may be useful for regression testing. -# +# # This module will define the following variables: # HDF5_INCLUDE_DIRS - Location of the hdf5 includes # HDF5_INCLUDE_DIR - Location of the hdf5 includes (deprecated) @@ -60,268 +60,270 @@ include(SelectLibraryConfigurations) include(FindPackageHandleStandardArgs) # List of the valid HDF5 components -set(HDF5_VALID_COMPONENTS +set( HDF5_VALID_COMPONENTS C CXX - ) +) # try to find the HDF5 wrapper compilers -find_program(HDF5_C_COMPILER_EXECUTABLE +find_program( HDF5_C_COMPILER_EXECUTABLE NAMES h5cc h5pcc HINTS ENV HDF5_ROOT PATH_SUFFIXES bin Bin - DOC "HDF5 Wrapper compiler. Used only to detect HDF5 compile flags.") -mark_as_advanced(HDF5_C_COMPILER_EXECUTABLE) + DOC "HDF5 Wrapper compiler. Used only to detect HDF5 compile flags." ) +mark_as_advanced( HDF5_C_COMPILER_EXECUTABLE ) -find_program(HDF5_CXX_COMPILER_EXECUTABLE +find_program( HDF5_CXX_COMPILER_EXECUTABLE NAMES h5c++ h5pc++ HINTS ENV HDF5_ROOT PATH_SUFFIXES bin Bin - DOC "HDF5 C++ Wrapper compiler. Used only to detect HDF5 compile flags.") -mark_as_advanced(HDF5_CXX_COMPILER_EXECUTABLE) + DOC "HDF5 C++ Wrapper compiler. Used only to detect HDF5 compile flags." ) +mark_as_advanced( HDF5_CXX_COMPILER_EXECUTABLE ) -find_program(HDF5_DIFF_EXECUTABLE +find_program( HDF5_DIFF_EXECUTABLE NAMES h5diff HINTS ENV HDF5_ROOT - PATH_SUFFIXES bin Bin - DOC "HDF5 file differencing tool.") -mark_as_advanced(HDF5_DIFF_EXECUTABLE) + PATH_SUFFIXES bin Bin + DOC "HDF5 file differencing tool." ) +mark_as_advanced( HDF5_DIFF_EXECUTABLE ) # Invoke the HDF5 wrapper compiler. The compiler return value is stored to the # return_value argument, the text output is stored to the output variable. -macro(_HDF5_invoke_compiler language output return_value) - if(HDF5_${language}_COMPILER_EXECUTABLE) - exec_program(${HDF5_${language}_COMPILER_EXECUTABLE} +macro( _HDF5_invoke_compiler language output return_value ) + if( HDF5_${language}_COMPILER_EXECUTABLE ) + exec_program( ${HDF5_${language}_COMPILER_EXECUTABLE} ARGS -show OUTPUT_VARIABLE ${output} RETURN_VALUE ${return_value} - ) - if(${${return_value}} EQUAL 0) + ) + if( ${${return_value}} EQUAL 0 ) # do nothing else() - message(STATUS - "Unable to determine HDF5 ${language} flags from HDF5 wrapper.") + message( STATUS + "Unable to determine HDF5 ${language} flags from HDF5 wrapper." ) endif() endif() endmacro() # Parse a compile line for definitions, includes, library paths, and libraries. -macro(_HDF5_parse_compile_line - compile_line_var - include_paths - definitions - library_paths - libraries) +macro( _HDF5_parse_compile_line + compile_line_var + include_paths + definitions + library_paths + libraries ) # Match the include paths - string(REGEX MATCHALL "-I([^\" ]+)" include_path_flags + string( REGEX MATCHALL "-I([^\" ]+)" include_path_flags "${${compile_line_var}}" - ) - foreach(IPATH ${include_path_flags}) - string(REGEX REPLACE "^-I" "" IPATH ${IPATH}) - string(REGEX REPLACE "//" "/" IPATH ${IPATH}) - list(APPEND ${include_paths} ${IPATH}) + ) + foreach( IPATH ${include_path_flags} ) + string( REGEX REPLACE "^-I" "" IPATH ${IPATH} ) + string( REGEX REPLACE "//" "/" IPATH ${IPATH} ) + list( APPEND ${include_paths} ${IPATH} ) endforeach() # Match the definitions - string(REGEX MATCHALL "-D[^ ]*" definition_flags "${${compile_line_var}}") - foreach(DEF ${definition_flags}) - list(APPEND ${definitions} ${DEF}) + string( REGEX MATCHALL "-D[^ ]*" definition_flags "${${compile_line_var}}" ) + foreach( DEF ${definition_flags} ) + list( APPEND ${definitions} ${DEF} ) endforeach() # Match the library paths - string(REGEX MATCHALL "-L([^\" ]+|\"[^\"]+\")" library_path_flags + string( REGEX MATCHALL "-L([^\" ]+|\"[^\"]+\")" library_path_flags "${${compile_line_var}}" - ) - - foreach(LPATH ${library_path_flags}) - string(REGEX REPLACE "^-L" "" LPATH ${LPATH}) - string(REGEX REPLACE "//" "/" LPATH ${LPATH}) - list(APPEND ${library_paths} ${LPATH}) + ) + + foreach( LPATH ${library_path_flags} ) + string( REGEX REPLACE "^-L" "" LPATH ${LPATH} ) + string( REGEX REPLACE "//" "/" LPATH ${LPATH} ) + list( APPEND ${library_paths} ${LPATH} ) endforeach() # now search for the library names specified in the compile line (match -l...) # match only -l's preceded by a space or comma # this is to exclude directory names like xxx-linux/ - string(REGEX MATCHALL "[, ]-l([^\", ]+)" library_name_flags - "${${compile_line_var}}") + string( REGEX MATCHALL "[, ]-l([^\", ]+)" library_name_flags + "${${compile_line_var}}" ) # strip the -l from all of the library flags and add to the search list - foreach(LIB ${library_name_flags}) - string(REGEX REPLACE "^[, ]-l" "" LIB ${LIB}) - list(APPEND ${libraries} ${LIB}) + foreach( LIB ${library_name_flags} ) + string( REGEX REPLACE "^[, ]-l" "" LIB ${LIB} ) + list( APPEND ${libraries} ${LIB} ) endforeach() endmacro() -if(HDF5_INCLUDE_DIRS AND HDF5_LIBRARIES) +if( HDF5_INCLUDE_DIRS AND HDF5_LIBRARIES ) # Do nothing: we already have HDF5_INCLUDE_PATH and HDF5_LIBRARIES in the # cache, it would be a shame to override them else() - _HDF5_invoke_compiler(C HDF5_C_COMPILE_LINE HDF5_C_RETURN_VALUE) - _HDF5_invoke_compiler(CXX HDF5_CXX_COMPILE_LINE HDF5_CXX_RETURN_VALUE) + _HDF5_invoke_compiler( C HDF5_C_COMPILE_LINE HDF5_C_RETURN_VALUE ) + _HDF5_invoke_compiler( CXX HDF5_CXX_COMPILE_LINE HDF5_CXX_RETURN_VALUE ) - if(NOT HDF5_FIND_COMPONENTS) - set(HDF5_LANGUAGE_BINDINGS "C") + if( NOT HDF5_FIND_COMPONENTS ) + set( HDF5_LANGUAGE_BINDINGS "C" ) else() # add the extra specified components, ensuring that they are valid. - foreach(component ${HDF5_FIND_COMPONENTS}) - list(FIND HDF5_VALID_COMPONENTS ${component} component_location) - if(${component_location} EQUAL -1) - message(FATAL_ERROR - "\"${component}\" is not a valid HDF5 component.") + foreach( component ${HDF5_FIND_COMPONENTS} ) + list( FIND HDF5_VALID_COMPONENTS ${component} component_location ) + if( ${component_location} EQUAL -1 ) + message( FATAL_ERROR + "\"${component}\" is not a valid HDF5 component." ) else() - list(APPEND HDF5_LANGUAGE_BINDINGS ${component}) + list( APPEND HDF5_LANGUAGE_BINDINGS ${component} ) endif() endforeach() endif() - + # seed the initial lists of libraries to find with items we know we need - set(HDF5_C_LIBRARY_NAMES_INIT hdf5_hl hdf5) - set(HDF5_CXX_LIBRARY_NAMES_INIT hdf5_cpp ${HDF5_C_LIBRARY_NAMES_INIT}) - - foreach(LANGUAGE ${HDF5_LANGUAGE_BINDINGS}) - if(HDF5_${LANGUAGE}_COMPILE_LINE) - _HDF5_parse_compile_line(HDF5_${LANGUAGE}_COMPILE_LINE - HDF5_${LANGUAGE}_INCLUDE_FLAGS - HDF5_${LANGUAGE}_DEFINITIONS - HDF5_${LANGUAGE}_LIBRARY_DIRS - HDF5_${LANGUAGE}_LIBRARY_NAMES + set( HDF5_C_LIBRARY_NAMES_INIT hdf5_hl hdf5 ) + set( HDF5_CXX_LIBRARY_NAMES_INIT hdf5_cpp ${HDF5_C_LIBRARY_NAMES_INIT} ) + + foreach( LANGUAGE ${HDF5_LANGUAGE_BINDINGS} ) + if( HDF5_${LANGUAGE}_COMPILE_LINE ) + _HDF5_parse_compile_line( HDF5_${LANGUAGE}_COMPILE_LINE + HDF5_${LANGUAGE}_INCLUDE_FLAGS + HDF5_${LANGUAGE}_DEFINITIONS + HDF5_${LANGUAGE}_LIBRARY_DIRS + HDF5_${LANGUAGE}_LIBRARY_NAMES ) + + # take a guess that the includes may be in the 'include' sibling directory + # of a library directory. + foreach( dir ${HDF5_${LANGUAGE}_LIBRARY_DIRS} ) + list( APPEND HDF5_${LANGUAGE}_INCLUDE_FLAGS ${dir}/../include ) + endforeach() + endif() - # take a guess that the includes may be in the 'include' sibling directory - # of a library directory. - foreach(dir ${HDF5_${LANGUAGE}_LIBRARY_DIRS}) - list(APPEND HDF5_${LANGUAGE}_INCLUDE_FLAGS ${dir}/../include) - endforeach() - endif() - - # set the definitions for the language bindings. - list(APPEND HDF5_DEFINITIONS ${HDF5_${LANGUAGE}_DEFINITIONS}) - - # find the HDF5 include directories - find_path(HDF5_${LANGUAGE}_INCLUDE_DIR hdf5.h - HINTS - ${HDF5_${LANGUAGE}_INCLUDE_FLAGS} - ENV - HDF5_ROOT - PATHS - $ENV{HOME}/.local/include - PATH_SUFFIXES - include - Include + # set the definitions for the language bindings. + list( APPEND HDF5_DEFINITIONS ${HDF5_${LANGUAGE}_DEFINITIONS} ) + + # find the HDF5 include directories + find_path( HDF5_${LANGUAGE}_INCLUDE_DIR hdf5.h + HINTS + ${HDF5_${LANGUAGE}_INCLUDE_FLAGS} + ENV + HDF5_ROOT + PATHS + $ENV{HOME}/.local/include + PATH_SUFFIXES + include + Include ) - mark_as_advanced(HDF5_${LANGUAGE}_INCLUDE_DIR) - list(APPEND HDF5_INCLUDE_DIRS ${HDF5_${LANGUAGE}_INCLUDE_DIR}) - - set(HDF5_${LANGUAGE}_LIBRARY_NAMES - ${HDF5_${LANGUAGE}_LIBRARY_NAMES_INIT} - ${HDF5_${LANGUAGE}_LIBRARY_NAMES}) - - # find the HDF5 libraries - foreach(LIB ${HDF5_${LANGUAGE}_LIBRARY_NAMES}) - if(UNIX AND HDF5_USE_STATIC_LIBRARIES) - # According to bug 1643 on the CMake bug tracker, this is the - # preferred method for searching for a static library. - # See http://www.cmake.org/Bug/view.php?id=1643. We search - # first for the full static library name, but fall back to a - # generic search on the name if the static search fails. - set(THIS_LIBRARY_SEARCH_DEBUG lib${LIB}d.a ${LIB}d) - set(THIS_LIBRARY_SEARCH_RELEASE lib${LIB}.a ${LIB}) - else() - set(THIS_LIBRARY_SEARCH_DEBUG ${LIB}d) - set(THIS_LIBRARY_SEARCH_RELEASE ${LIB}) - endif() - find_library(HDF5_${LIB}_LIBRARY_DEBUG - NAMES ${THIS_LIBRARY_SEARCH_DEBUG} - HINTS ${HDF5_${LANGUAGE}_LIBRARY_DIRS} - ENV HDF5_ROOT - PATH_SUFFIXES lib Lib) - find_library(HDF5_${LIB}_LIBRARY_RELEASE - NAMES ${THIS_LIBRARY_SEARCH_RELEASE} - HINTS ${HDF5_${LANGUAGE}_LIBRARY_DIRS} - ENV HDF5_ROOT - PATH_SUFFIXES lib Lib) - select_library_configurations(HDF5_${LIB}) - # even though we adjusted the individual library names in - # select_library_configurations, we still need to distinguish - # between debug and release variants because HDF5_LIBRARIES will - # need to specify different lists for debug and optimized builds. - # We can't just use the HDF5_${LIB}_LIBRARY variable (which was set - # up by the selection macro above) because it may specify debug and - # optimized variants for a particular library, but a list of - # libraries is allowed to specify debug and optimized only once. - list(APPEND HDF5_${LANGUAGE}_LIBRARIES_DEBUG - ${HDF5_${LIB}_LIBRARY_DEBUG}) - list(APPEND HDF5_${LANGUAGE}_LIBRARIES_RELEASE - ${HDF5_${LIB}_LIBRARY_RELEASE}) + mark_as_advanced( HDF5_${LANGUAGE}_INCLUDE_DIR ) + list( APPEND HDF5_INCLUDE_DIRS ${HDF5_${LANGUAGE}_INCLUDE_DIR} ) + + set( HDF5_${LANGUAGE}_LIBRARY_NAMES + ${HDF5_${LANGUAGE}_LIBRARY_NAMES_INIT} + ${HDF5_${LANGUAGE}_LIBRARY_NAMES} ) + + # find the HDF5 libraries + foreach( LIB ${HDF5_${LANGUAGE}_LIBRARY_NAMES} ) + if( UNIX AND HDF5_USE_STATIC_LIBRARIES ) + # According to bug 1643 on the CMake bug tracker, this is the + # preferred method for searching for a static library. + # See http://www.cmake.org/Bug/view.php?id=1643. We search + # first for the full static library name, but fall back to a + # generic search on the name if the static search fails. + set( THIS_LIBRARY_SEARCH_DEBUG lib${LIB}d.a ${LIB}d ) + set( THIS_LIBRARY_SEARCH_RELEASE lib${LIB}.a ${LIB} ) + else() + set( THIS_LIBRARY_SEARCH_DEBUG ${LIB}d ) + set( THIS_LIBRARY_SEARCH_RELEASE ${LIB} ) + endif() + find_library( HDF5_${LIB}_LIBRARY_DEBUG + NAMES ${THIS_LIBRARY_SEARCH_DEBUG} + HINTS ${HDF5_${LANGUAGE}_LIBRARY_DIRS} + ENV HDF5_ROOT + PATH_SUFFIXES lib Lib ) + find_library( HDF5_${LIB}_LIBRARY_RELEASE + NAMES ${THIS_LIBRARY_SEARCH_RELEASE} + HINTS ${HDF5_${LANGUAGE}_LIBRARY_DIRS} + ENV HDF5_ROOT + PATH_SUFFIXES lib Lib ) + select_library_configurations( HDF5_${LIB} ) + # even though we adjusted the individual library names in + # select_library_configurations, we still need to distinguish + # between debug and release variants because HDF5_LIBRARIES will + # need to specify different lists for debug and optimized builds. + # We can't just use the HDF5_${LIB}_LIBRARY variable (which was set + # up by the selection macro above) because it may specify debug and + # optimized variants for a particular library, but a list of + # libraries is allowed to specify debug and optimized only once. + list( APPEND HDF5_${LANGUAGE}_LIBRARIES_DEBUG + ${HDF5_${LIB}_LIBRARY_DEBUG} ) + list( APPEND HDF5_${LANGUAGE}_LIBRARIES_RELEASE + ${HDF5_${LIB}_LIBRARY_RELEASE} ) + endforeach() + list( APPEND HDF5_LIBRARY_DIRS ${HDF5_${LANGUAGE}_LIBRARY_DIRS} ) + + # Append the libraries for this language binding to the list of all + # required libraries. + list( APPEND HDF5_LIBRARIES_DEBUG + ${HDF5_${LANGUAGE}_LIBRARIES_DEBUG} ) + list( APPEND HDF5_LIBRARIES_RELEASE + ${HDF5_${LANGUAGE}_LIBRARIES_RELEASE} ) endforeach() - list(APPEND HDF5_LIBRARY_DIRS ${HDF5_${LANGUAGE}_LIBRARY_DIRS}) - - # Append the libraries for this language binding to the list of all - # required libraries. - list(APPEND HDF5_LIBRARIES_DEBUG - ${HDF5_${LANGUAGE}_LIBRARIES_DEBUG}) - list(APPEND HDF5_LIBRARIES_RELEASE - ${HDF5_${LANGUAGE}_LIBRARIES_RELEASE}) -endforeach() -# We may have picked up some duplicates in various lists during the above -# process for the language bindings (both the C and C++ bindings depend on -# libz for example). Remove the duplicates. -if(HDF5_INCLUDE_DIRS) - list(REMOVE_DUPLICATES HDF5_INCLUDE_DIRS) -endif() -if(HDF5_LIBRARIES_DEBUG) - list(REMOVE_DUPLICATES HDF5_LIBRARIES_DEBUG) -endif() -if(HDF5_LIBRARIES_RELEASE) - list(REMOVE_DUPLICATES HDF5_LIBRARIES_RELEASE) -endif() -if(HDF5_LIBRARY_DIRS) - list(REMOVE_DUPLICATES HDF5_LIBRARY_DIRS) -endif() + # We may have picked up some duplicates in various lists during the above + # process for the language bindings (both the C and C++ bindings depend on + # libz for example). Remove the duplicates. + if( HDF5_INCLUDE_DIRS ) + list( REMOVE_DUPLICATES HDF5_INCLUDE_DIRS ) + endif() + if( HDF5_LIBRARIES_DEBUG ) + list( REMOVE_DUPLICATES HDF5_LIBRARIES_DEBUG ) + endif() + if( HDF5_LIBRARIES_RELEASE ) + list( REMOVE_DUPLICATES HDF5_LIBRARIES_RELEASE ) + endif() + if( HDF5_LIBRARY_DIRS ) + list( REMOVE_DUPLICATES HDF5_LIBRARY_DIRS ) + endif() -# Construct the complete list of HDF5 libraries with debug and optimized -# variants when the generator supports them. -if(CMAKE_CONFIGURATION_TYPES OR CMAKE_BUILD_TYPE) - set(HDF5_LIBRARIES - debug ${HDF5_LIBRARIES_DEBUG} - optimized ${HDF5_LIBRARIES_RELEASE}) -else() - set(HDF5_LIBRARIES ${HDF5_LIBRARIES_RELEASE}) -endif() + # Construct the complete list of HDF5 libraries with debug and optimized + # variants when the generator supports them. + if( CMAKE_CONFIGURATION_TYPES OR CMAKE_BUILD_TYPE ) + set( HDF5_LIBRARIES + debug ${HDF5_LIBRARIES_DEBUG} + optimized ${HDF5_LIBRARIES_RELEASE} ) + else() + set( HDF5_LIBRARIES ${HDF5_LIBRARIES_RELEASE} ) + endif() -# If the HDF5 include directory was found, open H5pubconf.h to determine if -# HDF5 was compiled with parallel IO support -set(HDF5_IS_PARALLEL FALSE) -foreach(_dir HDF5_INCLUDE_DIRS) - if(EXISTS "${_dir}/H5pubconf.h") - file(STRINGS "${_dir}/H5pubconf.h" - HDF5_HAVE_PARALLEL_DEFINE - REGEX "HAVE_PARALLEL 1") - if(HDF5_HAVE_PARALLEL_DEFINE) - set(HDF5_IS_PARALLEL TRUE) + # If the HDF5 include directory was found, open H5pubconf.h to determine if + # HDF5 was compiled with parallel IO support + set( HDF5_IS_PARALLEL FALSE ) + foreach( _dir HDF5_INCLUDE_DIRS ) + if( EXISTS "${_dir}/H5pubconf.h" ) + file( STRINGS "${_dir}/H5pubconf.h" + HDF5_HAVE_PARALLEL_DEFINE + REGEX "HAVE_PARALLEL 1" ) + if( HDF5_HAVE_PARALLEL_DEFINE ) + set( HDF5_IS_PARALLEL TRUE ) + endif() endif() - endif() -endforeach() -set(HDF5_IS_PARALLEL ${HDF5_IS_PARALLEL} CACHE BOOL - "HDF5 library compiled with parallel IO support") -mark_as_advanced(HDF5_IS_PARALLEL) + endforeach() + set( HDF5_IS_PARALLEL ${HDF5_IS_PARALLEL} CACHE BOOL + "HDF5 library compiled with parallel IO support" ) + mark_as_advanced( HDF5_IS_PARALLEL ) endif() -find_package_handle_standard_args(HDF5 DEFAULT_MSG - HDF5_LIBRARIES +find_package_handle_standard_args( HDF5 DEFAULT_MSG + HDF5_LIBRARIES HDF5_INCLUDE_DIRS - ) +) -mark_as_advanced( - HDF5_INCLUDE_DIRS - HDF5_LIBRARIES +mark_as_advanced( + HDF5_INCLUDE_DIRS + HDF5_LIBRARIES HDF5_DEFINTIONS HDF5_LIBRARY_DIRS HDF5_C_COMPILER_EXECUTABLE - HDF5_CXX_COMPILER_EXECUTABLE) + HDF5_CXX_COMPILER_EXECUTABLE ) # For backwards compatibility we set HDF5_INCLUDE_DIR to the value of # HDF5_INCLUDE_DIRS -set(HDF5_INCLUDE_DIR "${HDF5_INCLUDE_DIRS}") +set( HDF5_INCLUDE_DIR "${HDF5_INCLUDE_DIRS}" ) + + From c8f8511e03225ad7a5f57ad339cba3767f1ca34a Mon Sep 17 00:00:00 2001 From: Matthew Gidden Date: Thu, 23 Apr 2015 10:27:41 -0500 Subject: [PATCH 58/80] tables->pytables --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 6eecf5b8a2..5153f20149 100644 --- a/.travis.yml +++ b/.travis.yml @@ -42,6 +42,6 @@ script: #- ls -l $HOME/miniconda/lib #- ls -l $HOME/miniconda/envs/_build/lib - cycamore_unit_tests - - conda install numpy tables + - conda install numpy pytables - nosetests -w tests From 863ed175d38c45bf01468b1ab176c9d434539f2c Mon Sep 17 00:00:00 2001 From: Robert Carlsen Date: Tue, 17 Feb 2015 12:50:14 -0600 Subject: [PATCH 59/80] Squashing commits from cyclus/cycamore#301. This should fail on CI. --- src/CMakeLists.txt | 2 + src/foo.cc | 171 +++++++++++++++++++++++++++++++++++++ src/foo.h | 204 +++++++++++++++++++++++++++++++++++++++++++++ src/foo_tests.cc | 204 +++++++++++++++++++++++++++++++++++++++++++++ src/foo_tests.h | 34 ++++++++ 5 files changed, 615 insertions(+) create mode 100644 src/foo.cc create mode 100644 src/foo.h create mode 100644 src/foo_tests.cc create mode 100644 src/foo_tests.h diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 6a29fcff22..29e907624e 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -12,6 +12,8 @@ USE_CYCLUS("cycamore" "sink") USE_CYCLUS("cycamore" "source") +USE_CYCLUS("cycamore" "foo") + USE_CYCLUS("cycamore" "deploy_inst") USE_CYCLUS("cycamore" "manager_inst") diff --git a/src/foo.cc b/src/foo.cc new file mode 100644 index 0000000000..9ad8ada201 --- /dev/null +++ b/src/foo.cc @@ -0,0 +1,171 @@ +#include "foo.h" + +#include +#include + +#include + +namespace cycamore { + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +Foo::Foo(cyclus::Context* ctx) + : cyclus::Facility(ctx), + out_commod(""), + recipe_name(""), + capacity(std::numeric_limits::max()) {} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +Foo::~Foo() {} + +#pragma cyclus def clone cycamore::Foo + +#pragma cyclus def schema cycamore::Foo + +#pragma cyclus def annotations cycamore::Foo + +#pragma cyclus def infiletodb cycamore::Foo + +#pragma cyclus def snapshot cycamore::Foo + +#pragma cyclus def snapshotinv cycamore::Foo + +#pragma cyclus def initinv cycamore::Foo + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +void Foo::InitFrom(Foo* m) { + #pragma cyclus impl initfromcopy cycamore::Foo + cyclus::toolkit::CommodityProducer::Copy(m); +} + +void Foo::InitFrom(cyclus::QueryableBackend* b) { + #pragma cyclus impl initfromdb cycamore::Foo + + commod_ = cyclus::toolkit::Commodity(out_commod); + cyclus::toolkit::CommodityProducer::Add(commod_); + cyclus::toolkit::CommodityProducer::SetCapacity(commod_, capacity); + cyclus::toolkit::CommodityProducer::SetCost(commod_, capacity); +} + +void Foo::EnterNotify() { + Facility::EnterNotify(); + commod_ = cyclus::toolkit::Commodity(out_commod); + cyclus::toolkit::CommodityProducer::Add(commod_); + cyclus::toolkit::CommodityProducer::SetCapacity(commod_, capacity); + cyclus::toolkit::CommodityProducer::SetCost(commod_, capacity); +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +std::string Foo::str() { + std::stringstream ss; + std::string ans; + if (cyclus::toolkit::CommodityProducer:: + Produces(cyclus::toolkit::Commodity(out_commod))) { + ans = "yes"; + } else { + ans = "no"; + } + ss << cyclus::Facility::str() + << " supplies commodity '" + << out_commod << "' with recipe '" + << recipe_name << "' at a capacity of " + << capacity << " kg per time step " + << " commod producer members: " << " produces " + << out_commod << "?: " << ans + << " capacity: " << cyclus::toolkit::CommodityProducer::Capacity(commod_) + << " cost: " << cyclus::toolkit::CommodityProducer::Cost(commod_); + return ss.str(); +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +void Foo::Tick() { + LOG(cyclus::LEV_INFO3, "SrcFac") << prototype() << " is ticking {"; + LOG(cyclus::LEV_INFO4, "SrcFac") << "will offer " << capacity + << " kg of " + << out_commod << "."; + LOG(cyclus::LEV_INFO3, "SrcFac") << "Stats: " << str(); + LOG(cyclus::LEV_INFO3, "SrcFac") << "}"; + current_capacity = capacity; // reset capacity +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +void Foo::Tock() { + LOG(cyclus::LEV_INFO3, "SrcFac") << prototype() << " is tocking {"; + LOG(cyclus::LEV_INFO3, "SrcFac") << "}"; +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +cyclus::Material::Ptr Foo::GetOffer( + const cyclus::Material::Ptr target) const { + using cyclus::Material; + double qty = std::min(target->quantity(), capacity); + return Material::CreateUntracked(qty, context()->GetRecipe(recipe_name)); +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +std::set::Ptr> +Foo::GetMatlBids( + cyclus::CommodMap::type& commod_requests) { + using cyclus::Bid; + using cyclus::BidPortfolio; + using cyclus::CapacityConstraint; + using cyclus::Material; + using cyclus::Request; + + std::set::Ptr> ports; + + if (commod_requests.count(out_commod) > 0) { + BidPortfolio::Ptr port(new BidPortfolio()); + + std::vector*>& requests = + commod_requests[out_commod]; + + std::vector*>::iterator it; + for (it = requests.begin(); it != requests.end(); ++it) { + Request* req = *it; + Material::Ptr offer = GetOffer(req->target()); + port->AddBid(req, offer, this); + } + + CapacityConstraint cc(capacity); + port->AddConstraint(cc); + ports.insert(port); + } + return ports; +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +void Foo::GetMatlTrades( + const std::vector< cyclus::Trade >& trades, + std::vector, + cyclus::Material::Ptr> >& responses) { + using cyclus::Material; + using cyclus::Trade; + + double provided = 0; + std::vector< cyclus::Trade >::const_iterator it; + for (it = trades.begin(); it != trades.end(); ++it) { + double qty = it->amt; + current_capacity -= qty; + provided += qty; + // @TODO we need a policy on negatives.. + Material::Ptr response = Material::Create(this, qty, + context()->GetRecipe(recipe_name)); + responses.push_back(std::make_pair(*it, response)); + LOG(cyclus::LEV_INFO5, "SrcFac") << prototype() << " just received an order" + << " for " << qty + << " of " << out_commod; + } + if (cyclus::IsNegative(current_capacity)) { + std::stringstream ss; + ss << "is being asked to provide " << provided + << " but its capacity is " << capacity << "."; + throw cyclus::ValueError(Agent::InformErrorMsg(ss.str())); + } +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +extern "C" cyclus::Agent* ConstructFoo(cyclus::Context* ctx) { + return new Foo(ctx); +} + +} // namespace cycamore diff --git a/src/foo.h b/src/foo.h new file mode 100644 index 0000000000..e35ab83d99 --- /dev/null +++ b/src/foo.h @@ -0,0 +1,204 @@ +#ifndef CYCAMORE_SRC_FOO_H_ +#define CYCAMORE_SRC_FOO_H_ + +#include +#include + +#include "cyclus.h" + +namespace cycamore { + +class Context; + +/// @class Foo +/// This cyclus::Facility provides a simple source of some capacity +/// (possibly infinite) of some commodity/Recipe. + +/// The Foo class inherits from the cyclus::Facility class and is +/// dynamically loaded by the Agent class when requested. + +/// @section introduction Introduction +/// The Foo is a facility type in Cyclus capable of providing +/// a finite or infinite.Supply of a particular material to the +/// simulation. A Foo generates material of a certain +/// composition and commodity type, then offers that material on the +/// appropriate market. Shipments of this material are executed when the +/// market issues an order that the offer has been matched with a +/// request. + +/// @section agentparams Agent Parameters +/// Foo behavior is comprehensively defined by the following +/// parameters: +/// - double capacity: The production capacity of the facility (units +/// vary, but typically kg/month). Capacity is infinite if a negative +/// value is provided. +/// - int startDate: The date on which the facility begins to operate +/// (months). +/// - int lifeTime: The length of time that the facility operates +/// (months). - std::string outCommod: the commodity that this facility +/// produces - double inventorysize: the maximum quantity of material to +/// be held in the inventory +/// - double commodprice: the price of the output material PER UNIT +/// - map outComp + +/// @section optionalparams Optional Parameters +/// Foo behavior may also be specified with the following +/// optional parameters which have default values listed here. +/// - double capacityFactor: The ratio of actual production capacity to +/// the rated production capacity. Default is 1 (actual/rated). +/// - double availFactor: The percent of time the facility operates at +/// its capacity factor. Default is 100%. +/// - double capitalCost: The cost of constructing and commissioning +/// this facility. Default is 0 ($). +/// - double opCost: The annual cost of operation and maintenance of +/// this facility. Default is 0 ( $/year). +/// - int constrTime: The number of months it takes to construct and +/// commission this facility. Default is 0 (months). +/// - int decomTime: The number of months it takes to deconstruct and +/// decommission this facility. Default is 0 (months). +/// - Inst* inst: The institution responsible for this facility. +/// - string name: A non-generic name for this facility. + +/// @section detailed Detailed Behavior +/// @subsection finite If Finite Capacity: +/// The Foo starts operation when the simulation reaches the +/// month specified as the startDate. It immediately begins to produce +/// material at the rate defined by its capacity. Each month the +/// Foo adds the amount it has produced to its inventory. It +/// then offers to the appropriate market exactly as much material as it +/// has in its inventory. If an offer is matched with a request, the +/// Foo executes that order by subtracting the quantity from +/// its inventory and sending that amount to the requesting facility. +/// When the simulation time equals the startDate plus the lifeTime, the +/// facility ceases to operate. +/// @subsection infinite If Infinite Capacity: +/// The Foo starts operation when the simulation reaches the +/// month specified as the startDate. Each month the Foo +/// offers an infinite amount of material to the appropriate market. If +/// there is a request for that material, the Foo executes +/// that order by sending that amount to the requesting facility. When +/// the simulation time equals the startDate plus the lifeTime, the +/// facility ceases to operate. + +/// @subsection question Question: +/// What is the best way to allow offers of an infinite amount of +/// material on a market? + +class Foo : public cyclus::Facility, + public cyclus::toolkit::CommodityProducer { + public: + // --- Module Members --- + /// Constructor for the Foo class + /// @param ctx the cyclus context for access to simulation-wide parameters + Foo(cyclus::Context* ctx); + + virtual ~Foo() + + #pragma cyclus decl + + #pragma cyclus note {"doc": "A source facility that provides a " \ + "commodity with a given capacity"} + + /// Print information about this agent + virtual std::string str(); + // --- + + // --- Agent Members --- + virtual void EnterNotify(); + + /// Each facility is prompted to do its beginning-of-time-step + /// stuff at the tick of the timer. + + /// @param time is the time to perform the tick + virtual void Tick(); + + /// Each facility is prompted to its end-of-time-step + /// stuff on the tock of the timer. + + /// @param time is the time to perform the tock + virtual void Tock(); + + /// @brief Responds to each request for this source facility's commodity. + /// If a given request is more than this facility's capacity, it will offer + /// its capacity. + virtual std::set::Ptr> + GetMatlBids(cyclus::CommodMap::type& + commod_requests); + + /// @brief respond to each trade with a material made from this facility's + /// recipe + /// + /// @param trades all trades in which this trader is the supplier + /// @param responses a container to populate with responses to each trade + virtual void GetMatlTrades( + const std::vector< cyclus::Trade >& trades, + std::vector, + cyclus::Material::Ptr> >& responses); + // --- + + // --- Foo Members --- + /// @brief creates a material object to offer to a requester + /// @param target the material target a request desires + cyclus::Material::Ptr GetOffer(const cyclus::Material::Ptr target) const; + + /// sets the output commodity name + /// @param name the commodity name + inline void commodity(std::string name) { out_commod = name; } + + /// @return the output commodity + inline std::string commodity() const { return out_commod; } + + /// sets the capacity of a material generated at any given time step + /// @param capacity the production capacity + inline void Capacity(double cap) { + capacity = cap; + current_capacity = capacity; + } + + /// @return the production capacity at any given time step + inline double Capacity() const { return capacity; } + + /// sets the name of the recipe to be produced + /// @param name the recipe name + inline void recipe(std::string name) { recipe_name = name; } + + /// @return the name of the output recipe + inline std::string recipe() const { return recipe_name; } + + /// @return the current timestep's capacity + inline double CurrentCapacity() const { return current_capacity; } + + private: + cyclus::toolkit::Commodity commod_; + + /// This facility has only one output commodity + #pragma cyclus var {"tooltip": "source output commodity", \ + "doc": "output commodity that the source facility " \ + "supplies", \ + "uitype": "outcommodity"} + std::string out_commod; + + /// Name of the recipe this facility uses. + #pragma cyclus var {"tooltip": "commodity recipe name", \ + "doc": "recipe name for source facility's commodity", \ + "uitype": "recipe"} + std::string recipe_name; + + /// The capacity is defined in terms of the number of units of the + /// recipe that can be provided each time step. A very large number + /// can be provided to represent infinte capacity. + #pragma cyclus var {"default": 1e299, "tooltip": "source capacity", \ + "doc": "amount of commodity that can be supplied " \ + "at each time step"} + double capacity; + + /// The capacity at the current time step + #pragma cyclus var {'derived_init': 'current_capacity = capacity;'} + double current_capacity; + + // --- +}; + +} // namespace cycamore + +#endif // CYCAMORE_SRC_FOO_H_ diff --git a/src/foo_tests.cc b/src/foo_tests.cc new file mode 100644 index 0000000000..0973e794d0 --- /dev/null +++ b/src/foo_tests.cc @@ -0,0 +1,204 @@ +#include "foo_tests.h" + +#include + +#include + +#include "cyc_limits.h" +#include "resource_helpers.h" +#include "test_context.h" + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +void FooTest::SetUp() { + src_facility = new cycamore::Foo(tc.get()); + trader = tc.trader(); + InitParameters(); + SetUpFoo(); +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +void FooTest::TearDown() { + delete src_facility; +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +void FooTest::InitParameters() { + commod = "commod"; + recipe_name = "recipe"; + capacity = 5; // some magic number.. + + recipe = cyclus::Composition::CreateFromAtom(cyclus::CompMap()); + tc.get()->AddRecipe(recipe_name, recipe); +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +void FooTest::SetUpFoo() { + src_facility->commodity(commod); + src_facility->recipe(recipe_name); + src_facility->Capacity(capacity); +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +TEST_F(FooTest, InitialState) { + EXPECT_EQ(src_facility->Capacity(), capacity); + EXPECT_EQ(src_facility->commodity(), commod); + EXPECT_EQ(src_facility->recipe(), recipe_name); + EXPECT_EQ(src_facility->CurrentCapacity(), capacity); +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +TEST_F(FooTest, Clone) { + cyclus::Context* ctx = tc.get(); + cycamore::Foo* cloned_fac = dynamic_cast + (src_facility->Clone()); + + EXPECT_EQ(src_facility->commodity(), cloned_fac->commodity()); + EXPECT_EQ(src_facility->Capacity(), cloned_fac->Capacity()); + EXPECT_EQ(src_facility->recipe(), cloned_fac->recipe()); + EXPECT_EQ(src_facility->Capacity(), cloned_fac->CurrentCapacity()); + + delete cloned_fac; +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +TEST_F(FooTest, Print) { + EXPECT_NO_THROW(std::string s = src_facility->str()); +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +TEST_F(FooTest, GetOffer) { + using cyclus::Material; + + double qty = capacity - 1; + Material::Ptr mat = cyclus::NewBlankMaterial(qty); + Material::Ptr obs_mat = src_facility->GetOffer(mat); + EXPECT_EQ(obs_mat->quantity(), qty); + EXPECT_EQ(obs_mat->comp(), recipe); + + qty = capacity + 1; + mat = cyclus::NewBlankMaterial(qty); + obs_mat = src_facility->GetOffer(mat); + EXPECT_EQ(obs_mat->quantity(), capacity); + EXPECT_EQ(obs_mat->comp(), recipe); + + qty = capacity; + mat = cyclus::NewBlankMaterial(qty); + obs_mat = src_facility->GetOffer(mat); + EXPECT_EQ(obs_mat->quantity(), capacity); + EXPECT_EQ(obs_mat->comp(), recipe); +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +TEST_F(FooTest, AddBids) { + using cyclus::Bid; + using cyclus::BidPortfolio; + using cyclus::CapacityConstraint; + using cyclus::ExchangeContext; + using cyclus::Material; + + int nreqs = 5; + + boost::shared_ptr< cyclus::ExchangeContext > + ec = GetContext(nreqs, commod); + + std::set::Ptr> ports = + src_facility->GetMatlBids(ec.get()->commod_requests); + + ASSERT_TRUE(ports.size() > 0); + EXPECT_EQ(ports.size(), 1); + + BidPortfolio::Ptr port = *ports.begin(); + EXPECT_EQ(port->bidder(), src_facility); + EXPECT_EQ(port->bids().size(), nreqs); + + const std::set< CapacityConstraint >& constrs = port->constraints(); + ASSERT_TRUE(constrs.size() > 0); + EXPECT_EQ(constrs.size(), 1); + EXPECT_EQ(*constrs.begin(), CapacityConstraint(capacity)); +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +TEST_F(FooTest, Response) { + using cyclus::Bid; + using cyclus::Material; + using cyclus::Request; + using cyclus::Trade; + using test_helpers::get_mat; + + std::vector< cyclus::Trade > trades; + std::vector, + cyclus::Material::Ptr> > responses; + + // Null response + EXPECT_NO_THROW(src_facility->GetMatlTrades(trades, responses)); + EXPECT_EQ(responses.size(), 0); + + double qty = capacity / 3; + Request* request = + Request::Create(get_mat(), trader, commod); + Bid* bid = + Bid::Create(request, get_mat(), src_facility); + + Trade trade(request, bid, qty); + trades.push_back(trade); + + // 1 trade + ASSERT_EQ(src_facility->CurrentCapacity(), capacity); + src_facility->GetMatlTrades(trades, responses); + EXPECT_EQ(responses.size(), 1); + EXPECT_EQ(responses[0].second->quantity(), qty); + EXPECT_EQ(responses[0].second->comp(), recipe); + + // 2 trades, total qty = capacity + ASSERT_DOUBLE_EQ(src_facility->CurrentCapacity(), capacity - qty); + ASSERT_GT(src_facility->CurrentCapacity() - 2 * qty, -1 * cyclus::eps()); + trades.push_back(trade); + responses.clear(); + EXPECT_NO_THROW(src_facility->GetMatlTrades(trades, responses)); + EXPECT_EQ(responses.size(), 2); + ASSERT_TRUE(cyclus::AlmostEq(src_facility->CurrentCapacity(), 0)); + + // too much qty, capn! + EXPECT_THROW(src_facility->GetMatlTrades(trades, responses), + cyclus::ValueError); + + // reset! + src_facility->Tick(); + ASSERT_DOUBLE_EQ(src_facility->CurrentCapacity(), capacity); + + delete request; + delete bid; +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +boost::shared_ptr< cyclus::ExchangeContext > +FooTest::GetContext(int nreqs, std::string commod) { + using cyclus::Material; + using cyclus::Request; + using cyclus::ExchangeContext; + using test_helpers::get_mat; + + double qty = 3; + boost::shared_ptr< ExchangeContext > + ec(new ExchangeContext()); + for (int i = 0; i < nreqs; i++) { + ec->AddRequest(Request::Create(get_mat(), trader, commod)); + } + return ec; +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +cyclus::Agent* FooConstructor(cyclus::Context* ctx) { + return new cycamore::Foo(ctx); +} + +// required to get functionality in cyclus agent unit tests library +#ifndef CYCLUS_AGENT_TESTS_CONNECTED +int ConnectAgentTests(); +static int cyclus_agent_tests_connected = ConnectAgentTests(); +#define CYCLUS_AGENT_TESTS_CONNECTED cyclus_agent_tests_connected +#endif // CYCLUS_AGENT_TESTS_CONNECTED + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +INSTANTIATE_TEST_CASE_P(FooFac, FacilityTests, Values(&FooConstructor)); +INSTANTIATE_TEST_CASE_P(FooFac, AgentTests, Values(&FooConstructor)); diff --git a/src/foo_tests.h b/src/foo_tests.h new file mode 100644 index 0000000000..59888926b7 --- /dev/null +++ b/src/foo_tests.h @@ -0,0 +1,34 @@ +#ifndef CYCAMORE_SRC_FOO_TESTS_H_ +#define CYCAMORE_SRC_FOO_TESTS_H_ +#include "foo.h" + +#include + +#include + +#include "agent_tests.h" +#include "context.h" +#include "exchange_context.h" +#include "facility_tests.h" +#include "material.h" + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +class FooTest : public ::testing::Test { + public: + cyclus::TestContext tc; + TestFacility* trader; + cycamore::Foo* src_facility; + std::string commod, recipe_name; + double capacity; + cyclus::Composition::Ptr recipe; + + virtual void SetUp(); + virtual void TearDown(); + void InitParameters(); + void SetUpFoo(); + + boost::shared_ptr< cyclus::ExchangeContext > + GetContext(int nreqs, std::string commodity); +}; + +#endif // CYCAMORE_SRC_FOO_TESTS_H_ From 163b667017150772b37d51dbc4107d942be1259c Mon Sep 17 00:00:00 2001 From: Matthew Gidden Date: Thu, 23 Apr 2015 10:56:49 -0500 Subject: [PATCH 60/80] adding same hdf5 messages as cyclus --- CMakeLists.txt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 4985e62e56..f2d1f2b451 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -104,6 +104,10 @@ IF(NOT CYCLUS_DOC_ONLY) FIND_PACKAGE(HDF5 REQUIRED) ADD_DEFINITIONS(${HDF5_DEFINITIONS}) set(LIBS ${LIBS} ${HDF5_LIBRARIES}) + MESSAGE("-- HDF5 Root: ${HDF5_ROOT}") + MESSAGE("-- HDF5 Include directory: ${HDF5_INCLUDE_DIR}") + MESSAGE("-- HDF5 Library directories: ${HDF5_LIBRARY_DIRS}") + MESSAGE("-- HDF5 Libraries: ${HDF5_LIBRARIES}") # find coin and link to it FIND_PACKAGE(COIN REQUIRED) From 0135e3778d39de7ccbeab1717428643062b40860 Mon Sep 17 00:00:00 2001 From: Matthew Gidden Date: Thu, 23 Apr 2015 11:07:56 -0500 Subject: [PATCH 61/80] matching cyclus findhdf --- cmake/FindHDF5.cmake | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/cmake/FindHDF5.cmake b/cmake/FindHDF5.cmake index 5b7cadd022..c7f7d73bee 100644 --- a/cmake/FindHDF5.cmake +++ b/cmake/FindHDF5.cmake @@ -20,8 +20,9 @@ # HDF5_USE_STATIC_LIBRARIES variable is set before the call to find_package. # # To provide the module with a hint about where to find your HDF5 installation, -# you can set the environment variable HDF5_ROOT. The Find module will then -# look in this path when searching for HDF5 executables, paths, and libraries. +# you can set the CMAKE variable -OR- environment variable HDF5_ROOT. The Find +# module will then look in this path when searching for HDF5 executables, paths, +# and libraries. # # In addition to finding the includes and libraries required to compile an HDF5 # client application, this module also makes an effort to find tools that come @@ -68,21 +69,21 @@ set( HDF5_VALID_COMPONENTS # try to find the HDF5 wrapper compilers find_program( HDF5_C_COMPILER_EXECUTABLE NAMES h5cc h5pcc - HINTS ENV HDF5_ROOT + HINTS "${HDF5_ROOT}" ENV HDF5_ROOT PATH_SUFFIXES bin Bin DOC "HDF5 Wrapper compiler. Used only to detect HDF5 compile flags." ) mark_as_advanced( HDF5_C_COMPILER_EXECUTABLE ) find_program( HDF5_CXX_COMPILER_EXECUTABLE NAMES h5c++ h5pc++ - HINTS ENV HDF5_ROOT + HINTS "${HDF5_ROOT}" ENV HDF5_ROOT PATH_SUFFIXES bin Bin DOC "HDF5 C++ Wrapper compiler. Used only to detect HDF5 compile flags." ) mark_as_advanced( HDF5_CXX_COMPILER_EXECUTABLE ) find_program( HDF5_DIFF_EXECUTABLE NAMES h5diff - HINTS ENV HDF5_ROOT + HINTS "${HDF5_ROOT}" ENV HDF5_ROOT PATH_SUFFIXES bin Bin DOC "HDF5 file differencing tool." ) mark_as_advanced( HDF5_DIFF_EXECUTABLE ) @@ -200,6 +201,7 @@ else() # find the HDF5 include directories find_path( HDF5_${LANGUAGE}_INCLUDE_DIR hdf5.h HINTS + "${HDF5_ROOT}" ${HDF5_${LANGUAGE}_INCLUDE_FLAGS} ENV HDF5_ROOT @@ -232,12 +234,12 @@ else() endif() find_library( HDF5_${LIB}_LIBRARY_DEBUG NAMES ${THIS_LIBRARY_SEARCH_DEBUG} - HINTS ${HDF5_${LANGUAGE}_LIBRARY_DIRS} + HINTS "${HDF5_ROOT}" ${HDF5_${LANGUAGE}_LIBRARY_DIRS} ENV HDF5_ROOT PATH_SUFFIXES lib Lib ) find_library( HDF5_${LIB}_LIBRARY_RELEASE NAMES ${THIS_LIBRARY_SEARCH_RELEASE} - HINTS ${HDF5_${LANGUAGE}_LIBRARY_DIRS} + HINTS "${HDF5_ROOT}" ${HDF5_${LANGUAGE}_LIBRARY_DIRS} ENV HDF5_ROOT PATH_SUFFIXES lib Lib ) select_library_configurations( HDF5_${LIB} ) From efc22ae7bd3ea5c6452c5d0ad66419a5c309f30c Mon Sep 17 00:00:00 2001 From: Matthew Gidden Date: Thu, 23 Apr 2015 11:19:12 -0500 Subject: [PATCH 62/80] early exit on failure --- .travis-install.sh | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/.travis-install.sh b/.travis-install.sh index 0ab998f721..46059223a9 100755 --- a/.travis-install.sh +++ b/.travis-install.sh @@ -2,4 +2,11 @@ wget https://github.com/gidden/ciclus/archive/travis.zip -O ciclus.zip unzip -j ciclus.zip "*/cycamore/*" -d conda-recipe sed -i "s/- cyclus/- cyclus 0.0/g" conda-recipe/meta.yaml conda build --no-test conda-recipe -conda install --use-local cycamore=0.0 \ No newline at end of file + +if [[ $? != 0 ]]; then + exit $? + +conda install --use-local cycamore=0.0 + +if [[ $? != 0 ]]; then + exit $? From 7d8fce0f30ecb9a6dfc75f7cb633a40a90526cf5 Mon Sep 17 00:00:00 2001 From: Matthew Gidden Date: Thu, 23 Apr 2015 11:19:37 -0500 Subject: [PATCH 63/80] Revert "Squashing commits from cyclus/cycamore#301. This should fail on CI." This reverts commit 4f25661c7fe06f815000ea851fa0a9d127678335. --- src/CMakeLists.txt | 2 - src/foo.cc | 171 ------------------------------------- src/foo.h | 204 --------------------------------------------- src/foo_tests.cc | 204 --------------------------------------------- src/foo_tests.h | 34 -------- 5 files changed, 615 deletions(-) delete mode 100644 src/foo.cc delete mode 100644 src/foo.h delete mode 100644 src/foo_tests.cc delete mode 100644 src/foo_tests.h diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 29e907624e..6a29fcff22 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -12,8 +12,6 @@ USE_CYCLUS("cycamore" "sink") USE_CYCLUS("cycamore" "source") -USE_CYCLUS("cycamore" "foo") - USE_CYCLUS("cycamore" "deploy_inst") USE_CYCLUS("cycamore" "manager_inst") diff --git a/src/foo.cc b/src/foo.cc deleted file mode 100644 index 9ad8ada201..0000000000 --- a/src/foo.cc +++ /dev/null @@ -1,171 +0,0 @@ -#include "foo.h" - -#include -#include - -#include - -namespace cycamore { - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Foo::Foo(cyclus::Context* ctx) - : cyclus::Facility(ctx), - out_commod(""), - recipe_name(""), - capacity(std::numeric_limits::max()) {} - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Foo::~Foo() {} - -#pragma cyclus def clone cycamore::Foo - -#pragma cyclus def schema cycamore::Foo - -#pragma cyclus def annotations cycamore::Foo - -#pragma cyclus def infiletodb cycamore::Foo - -#pragma cyclus def snapshot cycamore::Foo - -#pragma cyclus def snapshotinv cycamore::Foo - -#pragma cyclus def initinv cycamore::Foo - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void Foo::InitFrom(Foo* m) { - #pragma cyclus impl initfromcopy cycamore::Foo - cyclus::toolkit::CommodityProducer::Copy(m); -} - -void Foo::InitFrom(cyclus::QueryableBackend* b) { - #pragma cyclus impl initfromdb cycamore::Foo - - commod_ = cyclus::toolkit::Commodity(out_commod); - cyclus::toolkit::CommodityProducer::Add(commod_); - cyclus::toolkit::CommodityProducer::SetCapacity(commod_, capacity); - cyclus::toolkit::CommodityProducer::SetCost(commod_, capacity); -} - -void Foo::EnterNotify() { - Facility::EnterNotify(); - commod_ = cyclus::toolkit::Commodity(out_commod); - cyclus::toolkit::CommodityProducer::Add(commod_); - cyclus::toolkit::CommodityProducer::SetCapacity(commod_, capacity); - cyclus::toolkit::CommodityProducer::SetCost(commod_, capacity); -} - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -std::string Foo::str() { - std::stringstream ss; - std::string ans; - if (cyclus::toolkit::CommodityProducer:: - Produces(cyclus::toolkit::Commodity(out_commod))) { - ans = "yes"; - } else { - ans = "no"; - } - ss << cyclus::Facility::str() - << " supplies commodity '" - << out_commod << "' with recipe '" - << recipe_name << "' at a capacity of " - << capacity << " kg per time step " - << " commod producer members: " << " produces " - << out_commod << "?: " << ans - << " capacity: " << cyclus::toolkit::CommodityProducer::Capacity(commod_) - << " cost: " << cyclus::toolkit::CommodityProducer::Cost(commod_); - return ss.str(); -} - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void Foo::Tick() { - LOG(cyclus::LEV_INFO3, "SrcFac") << prototype() << " is ticking {"; - LOG(cyclus::LEV_INFO4, "SrcFac") << "will offer " << capacity - << " kg of " - << out_commod << "."; - LOG(cyclus::LEV_INFO3, "SrcFac") << "Stats: " << str(); - LOG(cyclus::LEV_INFO3, "SrcFac") << "}"; - current_capacity = capacity; // reset capacity -} - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void Foo::Tock() { - LOG(cyclus::LEV_INFO3, "SrcFac") << prototype() << " is tocking {"; - LOG(cyclus::LEV_INFO3, "SrcFac") << "}"; -} - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -cyclus::Material::Ptr Foo::GetOffer( - const cyclus::Material::Ptr target) const { - using cyclus::Material; - double qty = std::min(target->quantity(), capacity); - return Material::CreateUntracked(qty, context()->GetRecipe(recipe_name)); -} - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -std::set::Ptr> -Foo::GetMatlBids( - cyclus::CommodMap::type& commod_requests) { - using cyclus::Bid; - using cyclus::BidPortfolio; - using cyclus::CapacityConstraint; - using cyclus::Material; - using cyclus::Request; - - std::set::Ptr> ports; - - if (commod_requests.count(out_commod) > 0) { - BidPortfolio::Ptr port(new BidPortfolio()); - - std::vector*>& requests = - commod_requests[out_commod]; - - std::vector*>::iterator it; - for (it = requests.begin(); it != requests.end(); ++it) { - Request* req = *it; - Material::Ptr offer = GetOffer(req->target()); - port->AddBid(req, offer, this); - } - - CapacityConstraint cc(capacity); - port->AddConstraint(cc); - ports.insert(port); - } - return ports; -} - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void Foo::GetMatlTrades( - const std::vector< cyclus::Trade >& trades, - std::vector, - cyclus::Material::Ptr> >& responses) { - using cyclus::Material; - using cyclus::Trade; - - double provided = 0; - std::vector< cyclus::Trade >::const_iterator it; - for (it = trades.begin(); it != trades.end(); ++it) { - double qty = it->amt; - current_capacity -= qty; - provided += qty; - // @TODO we need a policy on negatives.. - Material::Ptr response = Material::Create(this, qty, - context()->GetRecipe(recipe_name)); - responses.push_back(std::make_pair(*it, response)); - LOG(cyclus::LEV_INFO5, "SrcFac") << prototype() << " just received an order" - << " for " << qty - << " of " << out_commod; - } - if (cyclus::IsNegative(current_capacity)) { - std::stringstream ss; - ss << "is being asked to provide " << provided - << " but its capacity is " << capacity << "."; - throw cyclus::ValueError(Agent::InformErrorMsg(ss.str())); - } -} - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -extern "C" cyclus::Agent* ConstructFoo(cyclus::Context* ctx) { - return new Foo(ctx); -} - -} // namespace cycamore diff --git a/src/foo.h b/src/foo.h deleted file mode 100644 index e35ab83d99..0000000000 --- a/src/foo.h +++ /dev/null @@ -1,204 +0,0 @@ -#ifndef CYCAMORE_SRC_FOO_H_ -#define CYCAMORE_SRC_FOO_H_ - -#include -#include - -#include "cyclus.h" - -namespace cycamore { - -class Context; - -/// @class Foo -/// This cyclus::Facility provides a simple source of some capacity -/// (possibly infinite) of some commodity/Recipe. - -/// The Foo class inherits from the cyclus::Facility class and is -/// dynamically loaded by the Agent class when requested. - -/// @section introduction Introduction -/// The Foo is a facility type in Cyclus capable of providing -/// a finite or infinite.Supply of a particular material to the -/// simulation. A Foo generates material of a certain -/// composition and commodity type, then offers that material on the -/// appropriate market. Shipments of this material are executed when the -/// market issues an order that the offer has been matched with a -/// request. - -/// @section agentparams Agent Parameters -/// Foo behavior is comprehensively defined by the following -/// parameters: -/// - double capacity: The production capacity of the facility (units -/// vary, but typically kg/month). Capacity is infinite if a negative -/// value is provided. -/// - int startDate: The date on which the facility begins to operate -/// (months). -/// - int lifeTime: The length of time that the facility operates -/// (months). - std::string outCommod: the commodity that this facility -/// produces - double inventorysize: the maximum quantity of material to -/// be held in the inventory -/// - double commodprice: the price of the output material PER UNIT -/// - map outComp - -/// @section optionalparams Optional Parameters -/// Foo behavior may also be specified with the following -/// optional parameters which have default values listed here. -/// - double capacityFactor: The ratio of actual production capacity to -/// the rated production capacity. Default is 1 (actual/rated). -/// - double availFactor: The percent of time the facility operates at -/// its capacity factor. Default is 100%. -/// - double capitalCost: The cost of constructing and commissioning -/// this facility. Default is 0 ($). -/// - double opCost: The annual cost of operation and maintenance of -/// this facility. Default is 0 ( $/year). -/// - int constrTime: The number of months it takes to construct and -/// commission this facility. Default is 0 (months). -/// - int decomTime: The number of months it takes to deconstruct and -/// decommission this facility. Default is 0 (months). -/// - Inst* inst: The institution responsible for this facility. -/// - string name: A non-generic name for this facility. - -/// @section detailed Detailed Behavior -/// @subsection finite If Finite Capacity: -/// The Foo starts operation when the simulation reaches the -/// month specified as the startDate. It immediately begins to produce -/// material at the rate defined by its capacity. Each month the -/// Foo adds the amount it has produced to its inventory. It -/// then offers to the appropriate market exactly as much material as it -/// has in its inventory. If an offer is matched with a request, the -/// Foo executes that order by subtracting the quantity from -/// its inventory and sending that amount to the requesting facility. -/// When the simulation time equals the startDate plus the lifeTime, the -/// facility ceases to operate. -/// @subsection infinite If Infinite Capacity: -/// The Foo starts operation when the simulation reaches the -/// month specified as the startDate. Each month the Foo -/// offers an infinite amount of material to the appropriate market. If -/// there is a request for that material, the Foo executes -/// that order by sending that amount to the requesting facility. When -/// the simulation time equals the startDate plus the lifeTime, the -/// facility ceases to operate. - -/// @subsection question Question: -/// What is the best way to allow offers of an infinite amount of -/// material on a market? - -class Foo : public cyclus::Facility, - public cyclus::toolkit::CommodityProducer { - public: - // --- Module Members --- - /// Constructor for the Foo class - /// @param ctx the cyclus context for access to simulation-wide parameters - Foo(cyclus::Context* ctx); - - virtual ~Foo() - - #pragma cyclus decl - - #pragma cyclus note {"doc": "A source facility that provides a " \ - "commodity with a given capacity"} - - /// Print information about this agent - virtual std::string str(); - // --- - - // --- Agent Members --- - virtual void EnterNotify(); - - /// Each facility is prompted to do its beginning-of-time-step - /// stuff at the tick of the timer. - - /// @param time is the time to perform the tick - virtual void Tick(); - - /// Each facility is prompted to its end-of-time-step - /// stuff on the tock of the timer. - - /// @param time is the time to perform the tock - virtual void Tock(); - - /// @brief Responds to each request for this source facility's commodity. - /// If a given request is more than this facility's capacity, it will offer - /// its capacity. - virtual std::set::Ptr> - GetMatlBids(cyclus::CommodMap::type& - commod_requests); - - /// @brief respond to each trade with a material made from this facility's - /// recipe - /// - /// @param trades all trades in which this trader is the supplier - /// @param responses a container to populate with responses to each trade - virtual void GetMatlTrades( - const std::vector< cyclus::Trade >& trades, - std::vector, - cyclus::Material::Ptr> >& responses); - // --- - - // --- Foo Members --- - /// @brief creates a material object to offer to a requester - /// @param target the material target a request desires - cyclus::Material::Ptr GetOffer(const cyclus::Material::Ptr target) const; - - /// sets the output commodity name - /// @param name the commodity name - inline void commodity(std::string name) { out_commod = name; } - - /// @return the output commodity - inline std::string commodity() const { return out_commod; } - - /// sets the capacity of a material generated at any given time step - /// @param capacity the production capacity - inline void Capacity(double cap) { - capacity = cap; - current_capacity = capacity; - } - - /// @return the production capacity at any given time step - inline double Capacity() const { return capacity; } - - /// sets the name of the recipe to be produced - /// @param name the recipe name - inline void recipe(std::string name) { recipe_name = name; } - - /// @return the name of the output recipe - inline std::string recipe() const { return recipe_name; } - - /// @return the current timestep's capacity - inline double CurrentCapacity() const { return current_capacity; } - - private: - cyclus::toolkit::Commodity commod_; - - /// This facility has only one output commodity - #pragma cyclus var {"tooltip": "source output commodity", \ - "doc": "output commodity that the source facility " \ - "supplies", \ - "uitype": "outcommodity"} - std::string out_commod; - - /// Name of the recipe this facility uses. - #pragma cyclus var {"tooltip": "commodity recipe name", \ - "doc": "recipe name for source facility's commodity", \ - "uitype": "recipe"} - std::string recipe_name; - - /// The capacity is defined in terms of the number of units of the - /// recipe that can be provided each time step. A very large number - /// can be provided to represent infinte capacity. - #pragma cyclus var {"default": 1e299, "tooltip": "source capacity", \ - "doc": "amount of commodity that can be supplied " \ - "at each time step"} - double capacity; - - /// The capacity at the current time step - #pragma cyclus var {'derived_init': 'current_capacity = capacity;'} - double current_capacity; - - // --- -}; - -} // namespace cycamore - -#endif // CYCAMORE_SRC_FOO_H_ diff --git a/src/foo_tests.cc b/src/foo_tests.cc deleted file mode 100644 index 0973e794d0..0000000000 --- a/src/foo_tests.cc +++ /dev/null @@ -1,204 +0,0 @@ -#include "foo_tests.h" - -#include - -#include - -#include "cyc_limits.h" -#include "resource_helpers.h" -#include "test_context.h" - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void FooTest::SetUp() { - src_facility = new cycamore::Foo(tc.get()); - trader = tc.trader(); - InitParameters(); - SetUpFoo(); -} - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void FooTest::TearDown() { - delete src_facility; -} - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void FooTest::InitParameters() { - commod = "commod"; - recipe_name = "recipe"; - capacity = 5; // some magic number.. - - recipe = cyclus::Composition::CreateFromAtom(cyclus::CompMap()); - tc.get()->AddRecipe(recipe_name, recipe); -} - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void FooTest::SetUpFoo() { - src_facility->commodity(commod); - src_facility->recipe(recipe_name); - src_facility->Capacity(capacity); -} - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -TEST_F(FooTest, InitialState) { - EXPECT_EQ(src_facility->Capacity(), capacity); - EXPECT_EQ(src_facility->commodity(), commod); - EXPECT_EQ(src_facility->recipe(), recipe_name); - EXPECT_EQ(src_facility->CurrentCapacity(), capacity); -} - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -TEST_F(FooTest, Clone) { - cyclus::Context* ctx = tc.get(); - cycamore::Foo* cloned_fac = dynamic_cast - (src_facility->Clone()); - - EXPECT_EQ(src_facility->commodity(), cloned_fac->commodity()); - EXPECT_EQ(src_facility->Capacity(), cloned_fac->Capacity()); - EXPECT_EQ(src_facility->recipe(), cloned_fac->recipe()); - EXPECT_EQ(src_facility->Capacity(), cloned_fac->CurrentCapacity()); - - delete cloned_fac; -} - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -TEST_F(FooTest, Print) { - EXPECT_NO_THROW(std::string s = src_facility->str()); -} - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -TEST_F(FooTest, GetOffer) { - using cyclus::Material; - - double qty = capacity - 1; - Material::Ptr mat = cyclus::NewBlankMaterial(qty); - Material::Ptr obs_mat = src_facility->GetOffer(mat); - EXPECT_EQ(obs_mat->quantity(), qty); - EXPECT_EQ(obs_mat->comp(), recipe); - - qty = capacity + 1; - mat = cyclus::NewBlankMaterial(qty); - obs_mat = src_facility->GetOffer(mat); - EXPECT_EQ(obs_mat->quantity(), capacity); - EXPECT_EQ(obs_mat->comp(), recipe); - - qty = capacity; - mat = cyclus::NewBlankMaterial(qty); - obs_mat = src_facility->GetOffer(mat); - EXPECT_EQ(obs_mat->quantity(), capacity); - EXPECT_EQ(obs_mat->comp(), recipe); -} - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -TEST_F(FooTest, AddBids) { - using cyclus::Bid; - using cyclus::BidPortfolio; - using cyclus::CapacityConstraint; - using cyclus::ExchangeContext; - using cyclus::Material; - - int nreqs = 5; - - boost::shared_ptr< cyclus::ExchangeContext > - ec = GetContext(nreqs, commod); - - std::set::Ptr> ports = - src_facility->GetMatlBids(ec.get()->commod_requests); - - ASSERT_TRUE(ports.size() > 0); - EXPECT_EQ(ports.size(), 1); - - BidPortfolio::Ptr port = *ports.begin(); - EXPECT_EQ(port->bidder(), src_facility); - EXPECT_EQ(port->bids().size(), nreqs); - - const std::set< CapacityConstraint >& constrs = port->constraints(); - ASSERT_TRUE(constrs.size() > 0); - EXPECT_EQ(constrs.size(), 1); - EXPECT_EQ(*constrs.begin(), CapacityConstraint(capacity)); -} - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -TEST_F(FooTest, Response) { - using cyclus::Bid; - using cyclus::Material; - using cyclus::Request; - using cyclus::Trade; - using test_helpers::get_mat; - - std::vector< cyclus::Trade > trades; - std::vector, - cyclus::Material::Ptr> > responses; - - // Null response - EXPECT_NO_THROW(src_facility->GetMatlTrades(trades, responses)); - EXPECT_EQ(responses.size(), 0); - - double qty = capacity / 3; - Request* request = - Request::Create(get_mat(), trader, commod); - Bid* bid = - Bid::Create(request, get_mat(), src_facility); - - Trade trade(request, bid, qty); - trades.push_back(trade); - - // 1 trade - ASSERT_EQ(src_facility->CurrentCapacity(), capacity); - src_facility->GetMatlTrades(trades, responses); - EXPECT_EQ(responses.size(), 1); - EXPECT_EQ(responses[0].second->quantity(), qty); - EXPECT_EQ(responses[0].second->comp(), recipe); - - // 2 trades, total qty = capacity - ASSERT_DOUBLE_EQ(src_facility->CurrentCapacity(), capacity - qty); - ASSERT_GT(src_facility->CurrentCapacity() - 2 * qty, -1 * cyclus::eps()); - trades.push_back(trade); - responses.clear(); - EXPECT_NO_THROW(src_facility->GetMatlTrades(trades, responses)); - EXPECT_EQ(responses.size(), 2); - ASSERT_TRUE(cyclus::AlmostEq(src_facility->CurrentCapacity(), 0)); - - // too much qty, capn! - EXPECT_THROW(src_facility->GetMatlTrades(trades, responses), - cyclus::ValueError); - - // reset! - src_facility->Tick(); - ASSERT_DOUBLE_EQ(src_facility->CurrentCapacity(), capacity); - - delete request; - delete bid; -} - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -boost::shared_ptr< cyclus::ExchangeContext > -FooTest::GetContext(int nreqs, std::string commod) { - using cyclus::Material; - using cyclus::Request; - using cyclus::ExchangeContext; - using test_helpers::get_mat; - - double qty = 3; - boost::shared_ptr< ExchangeContext > - ec(new ExchangeContext()); - for (int i = 0; i < nreqs; i++) { - ec->AddRequest(Request::Create(get_mat(), trader, commod)); - } - return ec; -} - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -cyclus::Agent* FooConstructor(cyclus::Context* ctx) { - return new cycamore::Foo(ctx); -} - -// required to get functionality in cyclus agent unit tests library -#ifndef CYCLUS_AGENT_TESTS_CONNECTED -int ConnectAgentTests(); -static int cyclus_agent_tests_connected = ConnectAgentTests(); -#define CYCLUS_AGENT_TESTS_CONNECTED cyclus_agent_tests_connected -#endif // CYCLUS_AGENT_TESTS_CONNECTED - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -INSTANTIATE_TEST_CASE_P(FooFac, FacilityTests, Values(&FooConstructor)); -INSTANTIATE_TEST_CASE_P(FooFac, AgentTests, Values(&FooConstructor)); diff --git a/src/foo_tests.h b/src/foo_tests.h deleted file mode 100644 index 59888926b7..0000000000 --- a/src/foo_tests.h +++ /dev/null @@ -1,34 +0,0 @@ -#ifndef CYCAMORE_SRC_FOO_TESTS_H_ -#define CYCAMORE_SRC_FOO_TESTS_H_ -#include "foo.h" - -#include - -#include - -#include "agent_tests.h" -#include "context.h" -#include "exchange_context.h" -#include "facility_tests.h" -#include "material.h" - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -class FooTest : public ::testing::Test { - public: - cyclus::TestContext tc; - TestFacility* trader; - cycamore::Foo* src_facility; - std::string commod, recipe_name; - double capacity; - cyclus::Composition::Ptr recipe; - - virtual void SetUp(); - virtual void TearDown(); - void InitParameters(); - void SetUpFoo(); - - boost::shared_ptr< cyclus::ExchangeContext > - GetContext(int nreqs, std::string commodity); -}; - -#endif // CYCAMORE_SRC_FOO_TESTS_H_ From 5d23df9c078a76f1c8974ba83119930cea73ecaa Mon Sep 17 00:00:00 2001 From: Matthew Gidden Date: Thu, 23 Apr 2015 11:38:35 -0500 Subject: [PATCH 64/80] explicit status var --- .travis-install.sh | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/.travis-install.sh b/.travis-install.sh index 46059223a9..40e99c99c5 100755 --- a/.travis-install.sh +++ b/.travis-install.sh @@ -3,10 +3,12 @@ unzip -j ciclus.zip "*/cycamore/*" -d conda-recipe sed -i "s/- cyclus/- cyclus 0.0/g" conda-recipe/meta.yaml conda build --no-test conda-recipe -if [[ $? != 0 ]]; then - exit $? +status=$? +if [[ $status != 0 ]]; then + exit $status conda install --use-local cycamore=0.0 -if [[ $? != 0 ]]; then - exit $? +status=$? +if [[ $status != 0 ]]; then + exit $status From b6331f85393a7b28a07426748dc2d2286b917acd Mon Sep 17 00:00:00 2001 From: Matthew Gidden Date: Thu, 23 Apr 2015 12:09:19 -0500 Subject: [PATCH 65/80] fixed syntax errors added logging --- .travis-install.sh | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/.travis-install.sh b/.travis-install.sh index 40e99c99c5..1e53559839 100755 --- a/.travis-install.sh +++ b/.travis-install.sh @@ -1,14 +1,26 @@ +#!/bin/bash + +# setup conda recipe wget https://github.com/gidden/ciclus/archive/travis.zip -O ciclus.zip unzip -j ciclus.zip "*/cycamore/*" -d conda-recipe sed -i "s/- cyclus/- cyclus 0.0/g" conda-recipe/meta.yaml -conda build --no-test conda-recipe +# build +cmd="conda build --no-test conda-recipe" +echo "cmd: $cmd" +$cmd status=$? +echo "status: $status" if [[ $status != 0 ]]; then exit $status +fi -conda install --use-local cycamore=0.0 - +# install +cmd="conda install --use-local cycamore=0.0" +echo "cmd: $cmd" +$cmd status=$? +echo "status: $status" if [[ $status != 0 ]]; then exit $status +fi From bb75eeb82f380107adfe9e8d3321e1dff7c84ce4 Mon Sep 17 00:00:00 2001 From: Matthew Gidden Date: Thu, 23 Apr 2015 12:45:13 -0500 Subject: [PATCH 66/80] should fail --- src/reactor_tests.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/reactor_tests.cc b/src/reactor_tests.cc index 8c743e5cf4..7ba33e8cc0 100644 --- a/src/reactor_tests.cc +++ b/src/reactor_tests.cc @@ -131,7 +131,7 @@ TEST(ReactorTests, RefuelTimes) { QueryResult qr = sim.db().Query("Transactions", NULL); int cyclet = 4; - int refuelt = 3; + int refuelt = 2; int n_assem_want = simdur/(cyclet+refuelt)+1; // +1 for initial core EXPECT_EQ(n_assem_want, qr.rows.size()); } From e28cc54ba3c2a387509f5b8961129e6591f35829 Mon Sep 17 00:00:00 2001 From: Matthew Gidden Date: Thu, 23 Apr 2015 12:45:21 -0500 Subject: [PATCH 67/80] Revert "should fail" This reverts commit 42fea0add138d2d30b182dae84f9468b85594aa7. --- src/reactor_tests.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/reactor_tests.cc b/src/reactor_tests.cc index 7ba33e8cc0..8c743e5cf4 100644 --- a/src/reactor_tests.cc +++ b/src/reactor_tests.cc @@ -131,7 +131,7 @@ TEST(ReactorTests, RefuelTimes) { QueryResult qr = sim.db().Query("Transactions", NULL); int cyclet = 4; - int refuelt = 2; + int refuelt = 3; int n_assem_want = simdur/(cyclet+refuelt)+1; // +1 for initial core EXPECT_EQ(n_assem_want, qr.rows.size()); } From daf399a8ed521c9d1f031bcb1264ed085567ec62 Mon Sep 17 00:00:00 2001 From: Robert Carlsen Date: Tue, 17 Feb 2015 12:50:14 -0600 Subject: [PATCH 68/80] Squashing commits from cyclus/cycamore#301. This should fail on CI. --- src/CMakeLists.txt | 2 + src/foo.cc | 171 +++++++++++++++++++++++++++++++++++++ src/foo.h | 204 +++++++++++++++++++++++++++++++++++++++++++++ src/foo_tests.cc | 204 +++++++++++++++++++++++++++++++++++++++++++++ src/foo_tests.h | 34 ++++++++ 5 files changed, 615 insertions(+) create mode 100644 src/foo.cc create mode 100644 src/foo.h create mode 100644 src/foo_tests.cc create mode 100644 src/foo_tests.h diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 6a29fcff22..29e907624e 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -12,6 +12,8 @@ USE_CYCLUS("cycamore" "sink") USE_CYCLUS("cycamore" "source") +USE_CYCLUS("cycamore" "foo") + USE_CYCLUS("cycamore" "deploy_inst") USE_CYCLUS("cycamore" "manager_inst") diff --git a/src/foo.cc b/src/foo.cc new file mode 100644 index 0000000000..9ad8ada201 --- /dev/null +++ b/src/foo.cc @@ -0,0 +1,171 @@ +#include "foo.h" + +#include +#include + +#include + +namespace cycamore { + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +Foo::Foo(cyclus::Context* ctx) + : cyclus::Facility(ctx), + out_commod(""), + recipe_name(""), + capacity(std::numeric_limits::max()) {} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +Foo::~Foo() {} + +#pragma cyclus def clone cycamore::Foo + +#pragma cyclus def schema cycamore::Foo + +#pragma cyclus def annotations cycamore::Foo + +#pragma cyclus def infiletodb cycamore::Foo + +#pragma cyclus def snapshot cycamore::Foo + +#pragma cyclus def snapshotinv cycamore::Foo + +#pragma cyclus def initinv cycamore::Foo + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +void Foo::InitFrom(Foo* m) { + #pragma cyclus impl initfromcopy cycamore::Foo + cyclus::toolkit::CommodityProducer::Copy(m); +} + +void Foo::InitFrom(cyclus::QueryableBackend* b) { + #pragma cyclus impl initfromdb cycamore::Foo + + commod_ = cyclus::toolkit::Commodity(out_commod); + cyclus::toolkit::CommodityProducer::Add(commod_); + cyclus::toolkit::CommodityProducer::SetCapacity(commod_, capacity); + cyclus::toolkit::CommodityProducer::SetCost(commod_, capacity); +} + +void Foo::EnterNotify() { + Facility::EnterNotify(); + commod_ = cyclus::toolkit::Commodity(out_commod); + cyclus::toolkit::CommodityProducer::Add(commod_); + cyclus::toolkit::CommodityProducer::SetCapacity(commod_, capacity); + cyclus::toolkit::CommodityProducer::SetCost(commod_, capacity); +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +std::string Foo::str() { + std::stringstream ss; + std::string ans; + if (cyclus::toolkit::CommodityProducer:: + Produces(cyclus::toolkit::Commodity(out_commod))) { + ans = "yes"; + } else { + ans = "no"; + } + ss << cyclus::Facility::str() + << " supplies commodity '" + << out_commod << "' with recipe '" + << recipe_name << "' at a capacity of " + << capacity << " kg per time step " + << " commod producer members: " << " produces " + << out_commod << "?: " << ans + << " capacity: " << cyclus::toolkit::CommodityProducer::Capacity(commod_) + << " cost: " << cyclus::toolkit::CommodityProducer::Cost(commod_); + return ss.str(); +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +void Foo::Tick() { + LOG(cyclus::LEV_INFO3, "SrcFac") << prototype() << " is ticking {"; + LOG(cyclus::LEV_INFO4, "SrcFac") << "will offer " << capacity + << " kg of " + << out_commod << "."; + LOG(cyclus::LEV_INFO3, "SrcFac") << "Stats: " << str(); + LOG(cyclus::LEV_INFO3, "SrcFac") << "}"; + current_capacity = capacity; // reset capacity +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +void Foo::Tock() { + LOG(cyclus::LEV_INFO3, "SrcFac") << prototype() << " is tocking {"; + LOG(cyclus::LEV_INFO3, "SrcFac") << "}"; +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +cyclus::Material::Ptr Foo::GetOffer( + const cyclus::Material::Ptr target) const { + using cyclus::Material; + double qty = std::min(target->quantity(), capacity); + return Material::CreateUntracked(qty, context()->GetRecipe(recipe_name)); +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +std::set::Ptr> +Foo::GetMatlBids( + cyclus::CommodMap::type& commod_requests) { + using cyclus::Bid; + using cyclus::BidPortfolio; + using cyclus::CapacityConstraint; + using cyclus::Material; + using cyclus::Request; + + std::set::Ptr> ports; + + if (commod_requests.count(out_commod) > 0) { + BidPortfolio::Ptr port(new BidPortfolio()); + + std::vector*>& requests = + commod_requests[out_commod]; + + std::vector*>::iterator it; + for (it = requests.begin(); it != requests.end(); ++it) { + Request* req = *it; + Material::Ptr offer = GetOffer(req->target()); + port->AddBid(req, offer, this); + } + + CapacityConstraint cc(capacity); + port->AddConstraint(cc); + ports.insert(port); + } + return ports; +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +void Foo::GetMatlTrades( + const std::vector< cyclus::Trade >& trades, + std::vector, + cyclus::Material::Ptr> >& responses) { + using cyclus::Material; + using cyclus::Trade; + + double provided = 0; + std::vector< cyclus::Trade >::const_iterator it; + for (it = trades.begin(); it != trades.end(); ++it) { + double qty = it->amt; + current_capacity -= qty; + provided += qty; + // @TODO we need a policy on negatives.. + Material::Ptr response = Material::Create(this, qty, + context()->GetRecipe(recipe_name)); + responses.push_back(std::make_pair(*it, response)); + LOG(cyclus::LEV_INFO5, "SrcFac") << prototype() << " just received an order" + << " for " << qty + << " of " << out_commod; + } + if (cyclus::IsNegative(current_capacity)) { + std::stringstream ss; + ss << "is being asked to provide " << provided + << " but its capacity is " << capacity << "."; + throw cyclus::ValueError(Agent::InformErrorMsg(ss.str())); + } +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +extern "C" cyclus::Agent* ConstructFoo(cyclus::Context* ctx) { + return new Foo(ctx); +} + +} // namespace cycamore diff --git a/src/foo.h b/src/foo.h new file mode 100644 index 0000000000..e35ab83d99 --- /dev/null +++ b/src/foo.h @@ -0,0 +1,204 @@ +#ifndef CYCAMORE_SRC_FOO_H_ +#define CYCAMORE_SRC_FOO_H_ + +#include +#include + +#include "cyclus.h" + +namespace cycamore { + +class Context; + +/// @class Foo +/// This cyclus::Facility provides a simple source of some capacity +/// (possibly infinite) of some commodity/Recipe. + +/// The Foo class inherits from the cyclus::Facility class and is +/// dynamically loaded by the Agent class when requested. + +/// @section introduction Introduction +/// The Foo is a facility type in Cyclus capable of providing +/// a finite or infinite.Supply of a particular material to the +/// simulation. A Foo generates material of a certain +/// composition and commodity type, then offers that material on the +/// appropriate market. Shipments of this material are executed when the +/// market issues an order that the offer has been matched with a +/// request. + +/// @section agentparams Agent Parameters +/// Foo behavior is comprehensively defined by the following +/// parameters: +/// - double capacity: The production capacity of the facility (units +/// vary, but typically kg/month). Capacity is infinite if a negative +/// value is provided. +/// - int startDate: The date on which the facility begins to operate +/// (months). +/// - int lifeTime: The length of time that the facility operates +/// (months). - std::string outCommod: the commodity that this facility +/// produces - double inventorysize: the maximum quantity of material to +/// be held in the inventory +/// - double commodprice: the price of the output material PER UNIT +/// - map outComp + +/// @section optionalparams Optional Parameters +/// Foo behavior may also be specified with the following +/// optional parameters which have default values listed here. +/// - double capacityFactor: The ratio of actual production capacity to +/// the rated production capacity. Default is 1 (actual/rated). +/// - double availFactor: The percent of time the facility operates at +/// its capacity factor. Default is 100%. +/// - double capitalCost: The cost of constructing and commissioning +/// this facility. Default is 0 ($). +/// - double opCost: The annual cost of operation and maintenance of +/// this facility. Default is 0 ( $/year). +/// - int constrTime: The number of months it takes to construct and +/// commission this facility. Default is 0 (months). +/// - int decomTime: The number of months it takes to deconstruct and +/// decommission this facility. Default is 0 (months). +/// - Inst* inst: The institution responsible for this facility. +/// - string name: A non-generic name for this facility. + +/// @section detailed Detailed Behavior +/// @subsection finite If Finite Capacity: +/// The Foo starts operation when the simulation reaches the +/// month specified as the startDate. It immediately begins to produce +/// material at the rate defined by its capacity. Each month the +/// Foo adds the amount it has produced to its inventory. It +/// then offers to the appropriate market exactly as much material as it +/// has in its inventory. If an offer is matched with a request, the +/// Foo executes that order by subtracting the quantity from +/// its inventory and sending that amount to the requesting facility. +/// When the simulation time equals the startDate plus the lifeTime, the +/// facility ceases to operate. +/// @subsection infinite If Infinite Capacity: +/// The Foo starts operation when the simulation reaches the +/// month specified as the startDate. Each month the Foo +/// offers an infinite amount of material to the appropriate market. If +/// there is a request for that material, the Foo executes +/// that order by sending that amount to the requesting facility. When +/// the simulation time equals the startDate plus the lifeTime, the +/// facility ceases to operate. + +/// @subsection question Question: +/// What is the best way to allow offers of an infinite amount of +/// material on a market? + +class Foo : public cyclus::Facility, + public cyclus::toolkit::CommodityProducer { + public: + // --- Module Members --- + /// Constructor for the Foo class + /// @param ctx the cyclus context for access to simulation-wide parameters + Foo(cyclus::Context* ctx); + + virtual ~Foo() + + #pragma cyclus decl + + #pragma cyclus note {"doc": "A source facility that provides a " \ + "commodity with a given capacity"} + + /// Print information about this agent + virtual std::string str(); + // --- + + // --- Agent Members --- + virtual void EnterNotify(); + + /// Each facility is prompted to do its beginning-of-time-step + /// stuff at the tick of the timer. + + /// @param time is the time to perform the tick + virtual void Tick(); + + /// Each facility is prompted to its end-of-time-step + /// stuff on the tock of the timer. + + /// @param time is the time to perform the tock + virtual void Tock(); + + /// @brief Responds to each request for this source facility's commodity. + /// If a given request is more than this facility's capacity, it will offer + /// its capacity. + virtual std::set::Ptr> + GetMatlBids(cyclus::CommodMap::type& + commod_requests); + + /// @brief respond to each trade with a material made from this facility's + /// recipe + /// + /// @param trades all trades in which this trader is the supplier + /// @param responses a container to populate with responses to each trade + virtual void GetMatlTrades( + const std::vector< cyclus::Trade >& trades, + std::vector, + cyclus::Material::Ptr> >& responses); + // --- + + // --- Foo Members --- + /// @brief creates a material object to offer to a requester + /// @param target the material target a request desires + cyclus::Material::Ptr GetOffer(const cyclus::Material::Ptr target) const; + + /// sets the output commodity name + /// @param name the commodity name + inline void commodity(std::string name) { out_commod = name; } + + /// @return the output commodity + inline std::string commodity() const { return out_commod; } + + /// sets the capacity of a material generated at any given time step + /// @param capacity the production capacity + inline void Capacity(double cap) { + capacity = cap; + current_capacity = capacity; + } + + /// @return the production capacity at any given time step + inline double Capacity() const { return capacity; } + + /// sets the name of the recipe to be produced + /// @param name the recipe name + inline void recipe(std::string name) { recipe_name = name; } + + /// @return the name of the output recipe + inline std::string recipe() const { return recipe_name; } + + /// @return the current timestep's capacity + inline double CurrentCapacity() const { return current_capacity; } + + private: + cyclus::toolkit::Commodity commod_; + + /// This facility has only one output commodity + #pragma cyclus var {"tooltip": "source output commodity", \ + "doc": "output commodity that the source facility " \ + "supplies", \ + "uitype": "outcommodity"} + std::string out_commod; + + /// Name of the recipe this facility uses. + #pragma cyclus var {"tooltip": "commodity recipe name", \ + "doc": "recipe name for source facility's commodity", \ + "uitype": "recipe"} + std::string recipe_name; + + /// The capacity is defined in terms of the number of units of the + /// recipe that can be provided each time step. A very large number + /// can be provided to represent infinte capacity. + #pragma cyclus var {"default": 1e299, "tooltip": "source capacity", \ + "doc": "amount of commodity that can be supplied " \ + "at each time step"} + double capacity; + + /// The capacity at the current time step + #pragma cyclus var {'derived_init': 'current_capacity = capacity;'} + double current_capacity; + + // --- +}; + +} // namespace cycamore + +#endif // CYCAMORE_SRC_FOO_H_ diff --git a/src/foo_tests.cc b/src/foo_tests.cc new file mode 100644 index 0000000000..0973e794d0 --- /dev/null +++ b/src/foo_tests.cc @@ -0,0 +1,204 @@ +#include "foo_tests.h" + +#include + +#include + +#include "cyc_limits.h" +#include "resource_helpers.h" +#include "test_context.h" + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +void FooTest::SetUp() { + src_facility = new cycamore::Foo(tc.get()); + trader = tc.trader(); + InitParameters(); + SetUpFoo(); +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +void FooTest::TearDown() { + delete src_facility; +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +void FooTest::InitParameters() { + commod = "commod"; + recipe_name = "recipe"; + capacity = 5; // some magic number.. + + recipe = cyclus::Composition::CreateFromAtom(cyclus::CompMap()); + tc.get()->AddRecipe(recipe_name, recipe); +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +void FooTest::SetUpFoo() { + src_facility->commodity(commod); + src_facility->recipe(recipe_name); + src_facility->Capacity(capacity); +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +TEST_F(FooTest, InitialState) { + EXPECT_EQ(src_facility->Capacity(), capacity); + EXPECT_EQ(src_facility->commodity(), commod); + EXPECT_EQ(src_facility->recipe(), recipe_name); + EXPECT_EQ(src_facility->CurrentCapacity(), capacity); +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +TEST_F(FooTest, Clone) { + cyclus::Context* ctx = tc.get(); + cycamore::Foo* cloned_fac = dynamic_cast + (src_facility->Clone()); + + EXPECT_EQ(src_facility->commodity(), cloned_fac->commodity()); + EXPECT_EQ(src_facility->Capacity(), cloned_fac->Capacity()); + EXPECT_EQ(src_facility->recipe(), cloned_fac->recipe()); + EXPECT_EQ(src_facility->Capacity(), cloned_fac->CurrentCapacity()); + + delete cloned_fac; +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +TEST_F(FooTest, Print) { + EXPECT_NO_THROW(std::string s = src_facility->str()); +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +TEST_F(FooTest, GetOffer) { + using cyclus::Material; + + double qty = capacity - 1; + Material::Ptr mat = cyclus::NewBlankMaterial(qty); + Material::Ptr obs_mat = src_facility->GetOffer(mat); + EXPECT_EQ(obs_mat->quantity(), qty); + EXPECT_EQ(obs_mat->comp(), recipe); + + qty = capacity + 1; + mat = cyclus::NewBlankMaterial(qty); + obs_mat = src_facility->GetOffer(mat); + EXPECT_EQ(obs_mat->quantity(), capacity); + EXPECT_EQ(obs_mat->comp(), recipe); + + qty = capacity; + mat = cyclus::NewBlankMaterial(qty); + obs_mat = src_facility->GetOffer(mat); + EXPECT_EQ(obs_mat->quantity(), capacity); + EXPECT_EQ(obs_mat->comp(), recipe); +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +TEST_F(FooTest, AddBids) { + using cyclus::Bid; + using cyclus::BidPortfolio; + using cyclus::CapacityConstraint; + using cyclus::ExchangeContext; + using cyclus::Material; + + int nreqs = 5; + + boost::shared_ptr< cyclus::ExchangeContext > + ec = GetContext(nreqs, commod); + + std::set::Ptr> ports = + src_facility->GetMatlBids(ec.get()->commod_requests); + + ASSERT_TRUE(ports.size() > 0); + EXPECT_EQ(ports.size(), 1); + + BidPortfolio::Ptr port = *ports.begin(); + EXPECT_EQ(port->bidder(), src_facility); + EXPECT_EQ(port->bids().size(), nreqs); + + const std::set< CapacityConstraint >& constrs = port->constraints(); + ASSERT_TRUE(constrs.size() > 0); + EXPECT_EQ(constrs.size(), 1); + EXPECT_EQ(*constrs.begin(), CapacityConstraint(capacity)); +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +TEST_F(FooTest, Response) { + using cyclus::Bid; + using cyclus::Material; + using cyclus::Request; + using cyclus::Trade; + using test_helpers::get_mat; + + std::vector< cyclus::Trade > trades; + std::vector, + cyclus::Material::Ptr> > responses; + + // Null response + EXPECT_NO_THROW(src_facility->GetMatlTrades(trades, responses)); + EXPECT_EQ(responses.size(), 0); + + double qty = capacity / 3; + Request* request = + Request::Create(get_mat(), trader, commod); + Bid* bid = + Bid::Create(request, get_mat(), src_facility); + + Trade trade(request, bid, qty); + trades.push_back(trade); + + // 1 trade + ASSERT_EQ(src_facility->CurrentCapacity(), capacity); + src_facility->GetMatlTrades(trades, responses); + EXPECT_EQ(responses.size(), 1); + EXPECT_EQ(responses[0].second->quantity(), qty); + EXPECT_EQ(responses[0].second->comp(), recipe); + + // 2 trades, total qty = capacity + ASSERT_DOUBLE_EQ(src_facility->CurrentCapacity(), capacity - qty); + ASSERT_GT(src_facility->CurrentCapacity() - 2 * qty, -1 * cyclus::eps()); + trades.push_back(trade); + responses.clear(); + EXPECT_NO_THROW(src_facility->GetMatlTrades(trades, responses)); + EXPECT_EQ(responses.size(), 2); + ASSERT_TRUE(cyclus::AlmostEq(src_facility->CurrentCapacity(), 0)); + + // too much qty, capn! + EXPECT_THROW(src_facility->GetMatlTrades(trades, responses), + cyclus::ValueError); + + // reset! + src_facility->Tick(); + ASSERT_DOUBLE_EQ(src_facility->CurrentCapacity(), capacity); + + delete request; + delete bid; +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +boost::shared_ptr< cyclus::ExchangeContext > +FooTest::GetContext(int nreqs, std::string commod) { + using cyclus::Material; + using cyclus::Request; + using cyclus::ExchangeContext; + using test_helpers::get_mat; + + double qty = 3; + boost::shared_ptr< ExchangeContext > + ec(new ExchangeContext()); + for (int i = 0; i < nreqs; i++) { + ec->AddRequest(Request::Create(get_mat(), trader, commod)); + } + return ec; +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +cyclus::Agent* FooConstructor(cyclus::Context* ctx) { + return new cycamore::Foo(ctx); +} + +// required to get functionality in cyclus agent unit tests library +#ifndef CYCLUS_AGENT_TESTS_CONNECTED +int ConnectAgentTests(); +static int cyclus_agent_tests_connected = ConnectAgentTests(); +#define CYCLUS_AGENT_TESTS_CONNECTED cyclus_agent_tests_connected +#endif // CYCLUS_AGENT_TESTS_CONNECTED + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +INSTANTIATE_TEST_CASE_P(FooFac, FacilityTests, Values(&FooConstructor)); +INSTANTIATE_TEST_CASE_P(FooFac, AgentTests, Values(&FooConstructor)); diff --git a/src/foo_tests.h b/src/foo_tests.h new file mode 100644 index 0000000000..59888926b7 --- /dev/null +++ b/src/foo_tests.h @@ -0,0 +1,34 @@ +#ifndef CYCAMORE_SRC_FOO_TESTS_H_ +#define CYCAMORE_SRC_FOO_TESTS_H_ +#include "foo.h" + +#include + +#include + +#include "agent_tests.h" +#include "context.h" +#include "exchange_context.h" +#include "facility_tests.h" +#include "material.h" + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +class FooTest : public ::testing::Test { + public: + cyclus::TestContext tc; + TestFacility* trader; + cycamore::Foo* src_facility; + std::string commod, recipe_name; + double capacity; + cyclus::Composition::Ptr recipe; + + virtual void SetUp(); + virtual void TearDown(); + void InitParameters(); + void SetUpFoo(); + + boost::shared_ptr< cyclus::ExchangeContext > + GetContext(int nreqs, std::string commodity); +}; + +#endif // CYCAMORE_SRC_FOO_TESTS_H_ From df2a0c4c36666f77dbcb40bb13701a75defef15f Mon Sep 17 00:00:00 2001 From: Matthew Gidden Date: Thu, 23 Apr 2015 12:46:05 -0500 Subject: [PATCH 69/80] Revert "Squashing commits from cyclus/cycamore#301. This should fail on CI." This reverts commit 3bb92b3be3c5ccf879bc11c9c50243ab1a206bf0. --- src/CMakeLists.txt | 2 - src/foo.cc | 171 ------------------------------------- src/foo.h | 204 --------------------------------------------- src/foo_tests.cc | 204 --------------------------------------------- src/foo_tests.h | 34 -------- 5 files changed, 615 deletions(-) delete mode 100644 src/foo.cc delete mode 100644 src/foo.h delete mode 100644 src/foo_tests.cc delete mode 100644 src/foo_tests.h diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 29e907624e..6a29fcff22 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -12,8 +12,6 @@ USE_CYCLUS("cycamore" "sink") USE_CYCLUS("cycamore" "source") -USE_CYCLUS("cycamore" "foo") - USE_CYCLUS("cycamore" "deploy_inst") USE_CYCLUS("cycamore" "manager_inst") diff --git a/src/foo.cc b/src/foo.cc deleted file mode 100644 index 9ad8ada201..0000000000 --- a/src/foo.cc +++ /dev/null @@ -1,171 +0,0 @@ -#include "foo.h" - -#include -#include - -#include - -namespace cycamore { - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Foo::Foo(cyclus::Context* ctx) - : cyclus::Facility(ctx), - out_commod(""), - recipe_name(""), - capacity(std::numeric_limits::max()) {} - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Foo::~Foo() {} - -#pragma cyclus def clone cycamore::Foo - -#pragma cyclus def schema cycamore::Foo - -#pragma cyclus def annotations cycamore::Foo - -#pragma cyclus def infiletodb cycamore::Foo - -#pragma cyclus def snapshot cycamore::Foo - -#pragma cyclus def snapshotinv cycamore::Foo - -#pragma cyclus def initinv cycamore::Foo - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void Foo::InitFrom(Foo* m) { - #pragma cyclus impl initfromcopy cycamore::Foo - cyclus::toolkit::CommodityProducer::Copy(m); -} - -void Foo::InitFrom(cyclus::QueryableBackend* b) { - #pragma cyclus impl initfromdb cycamore::Foo - - commod_ = cyclus::toolkit::Commodity(out_commod); - cyclus::toolkit::CommodityProducer::Add(commod_); - cyclus::toolkit::CommodityProducer::SetCapacity(commod_, capacity); - cyclus::toolkit::CommodityProducer::SetCost(commod_, capacity); -} - -void Foo::EnterNotify() { - Facility::EnterNotify(); - commod_ = cyclus::toolkit::Commodity(out_commod); - cyclus::toolkit::CommodityProducer::Add(commod_); - cyclus::toolkit::CommodityProducer::SetCapacity(commod_, capacity); - cyclus::toolkit::CommodityProducer::SetCost(commod_, capacity); -} - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -std::string Foo::str() { - std::stringstream ss; - std::string ans; - if (cyclus::toolkit::CommodityProducer:: - Produces(cyclus::toolkit::Commodity(out_commod))) { - ans = "yes"; - } else { - ans = "no"; - } - ss << cyclus::Facility::str() - << " supplies commodity '" - << out_commod << "' with recipe '" - << recipe_name << "' at a capacity of " - << capacity << " kg per time step " - << " commod producer members: " << " produces " - << out_commod << "?: " << ans - << " capacity: " << cyclus::toolkit::CommodityProducer::Capacity(commod_) - << " cost: " << cyclus::toolkit::CommodityProducer::Cost(commod_); - return ss.str(); -} - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void Foo::Tick() { - LOG(cyclus::LEV_INFO3, "SrcFac") << prototype() << " is ticking {"; - LOG(cyclus::LEV_INFO4, "SrcFac") << "will offer " << capacity - << " kg of " - << out_commod << "."; - LOG(cyclus::LEV_INFO3, "SrcFac") << "Stats: " << str(); - LOG(cyclus::LEV_INFO3, "SrcFac") << "}"; - current_capacity = capacity; // reset capacity -} - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void Foo::Tock() { - LOG(cyclus::LEV_INFO3, "SrcFac") << prototype() << " is tocking {"; - LOG(cyclus::LEV_INFO3, "SrcFac") << "}"; -} - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -cyclus::Material::Ptr Foo::GetOffer( - const cyclus::Material::Ptr target) const { - using cyclus::Material; - double qty = std::min(target->quantity(), capacity); - return Material::CreateUntracked(qty, context()->GetRecipe(recipe_name)); -} - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -std::set::Ptr> -Foo::GetMatlBids( - cyclus::CommodMap::type& commod_requests) { - using cyclus::Bid; - using cyclus::BidPortfolio; - using cyclus::CapacityConstraint; - using cyclus::Material; - using cyclus::Request; - - std::set::Ptr> ports; - - if (commod_requests.count(out_commod) > 0) { - BidPortfolio::Ptr port(new BidPortfolio()); - - std::vector*>& requests = - commod_requests[out_commod]; - - std::vector*>::iterator it; - for (it = requests.begin(); it != requests.end(); ++it) { - Request* req = *it; - Material::Ptr offer = GetOffer(req->target()); - port->AddBid(req, offer, this); - } - - CapacityConstraint cc(capacity); - port->AddConstraint(cc); - ports.insert(port); - } - return ports; -} - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void Foo::GetMatlTrades( - const std::vector< cyclus::Trade >& trades, - std::vector, - cyclus::Material::Ptr> >& responses) { - using cyclus::Material; - using cyclus::Trade; - - double provided = 0; - std::vector< cyclus::Trade >::const_iterator it; - for (it = trades.begin(); it != trades.end(); ++it) { - double qty = it->amt; - current_capacity -= qty; - provided += qty; - // @TODO we need a policy on negatives.. - Material::Ptr response = Material::Create(this, qty, - context()->GetRecipe(recipe_name)); - responses.push_back(std::make_pair(*it, response)); - LOG(cyclus::LEV_INFO5, "SrcFac") << prototype() << " just received an order" - << " for " << qty - << " of " << out_commod; - } - if (cyclus::IsNegative(current_capacity)) { - std::stringstream ss; - ss << "is being asked to provide " << provided - << " but its capacity is " << capacity << "."; - throw cyclus::ValueError(Agent::InformErrorMsg(ss.str())); - } -} - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -extern "C" cyclus::Agent* ConstructFoo(cyclus::Context* ctx) { - return new Foo(ctx); -} - -} // namespace cycamore diff --git a/src/foo.h b/src/foo.h deleted file mode 100644 index e35ab83d99..0000000000 --- a/src/foo.h +++ /dev/null @@ -1,204 +0,0 @@ -#ifndef CYCAMORE_SRC_FOO_H_ -#define CYCAMORE_SRC_FOO_H_ - -#include -#include - -#include "cyclus.h" - -namespace cycamore { - -class Context; - -/// @class Foo -/// This cyclus::Facility provides a simple source of some capacity -/// (possibly infinite) of some commodity/Recipe. - -/// The Foo class inherits from the cyclus::Facility class and is -/// dynamically loaded by the Agent class when requested. - -/// @section introduction Introduction -/// The Foo is a facility type in Cyclus capable of providing -/// a finite or infinite.Supply of a particular material to the -/// simulation. A Foo generates material of a certain -/// composition and commodity type, then offers that material on the -/// appropriate market. Shipments of this material are executed when the -/// market issues an order that the offer has been matched with a -/// request. - -/// @section agentparams Agent Parameters -/// Foo behavior is comprehensively defined by the following -/// parameters: -/// - double capacity: The production capacity of the facility (units -/// vary, but typically kg/month). Capacity is infinite if a negative -/// value is provided. -/// - int startDate: The date on which the facility begins to operate -/// (months). -/// - int lifeTime: The length of time that the facility operates -/// (months). - std::string outCommod: the commodity that this facility -/// produces - double inventorysize: the maximum quantity of material to -/// be held in the inventory -/// - double commodprice: the price of the output material PER UNIT -/// - map outComp - -/// @section optionalparams Optional Parameters -/// Foo behavior may also be specified with the following -/// optional parameters which have default values listed here. -/// - double capacityFactor: The ratio of actual production capacity to -/// the rated production capacity. Default is 1 (actual/rated). -/// - double availFactor: The percent of time the facility operates at -/// its capacity factor. Default is 100%. -/// - double capitalCost: The cost of constructing and commissioning -/// this facility. Default is 0 ($). -/// - double opCost: The annual cost of operation and maintenance of -/// this facility. Default is 0 ( $/year). -/// - int constrTime: The number of months it takes to construct and -/// commission this facility. Default is 0 (months). -/// - int decomTime: The number of months it takes to deconstruct and -/// decommission this facility. Default is 0 (months). -/// - Inst* inst: The institution responsible for this facility. -/// - string name: A non-generic name for this facility. - -/// @section detailed Detailed Behavior -/// @subsection finite If Finite Capacity: -/// The Foo starts operation when the simulation reaches the -/// month specified as the startDate. It immediately begins to produce -/// material at the rate defined by its capacity. Each month the -/// Foo adds the amount it has produced to its inventory. It -/// then offers to the appropriate market exactly as much material as it -/// has in its inventory. If an offer is matched with a request, the -/// Foo executes that order by subtracting the quantity from -/// its inventory and sending that amount to the requesting facility. -/// When the simulation time equals the startDate plus the lifeTime, the -/// facility ceases to operate. -/// @subsection infinite If Infinite Capacity: -/// The Foo starts operation when the simulation reaches the -/// month specified as the startDate. Each month the Foo -/// offers an infinite amount of material to the appropriate market. If -/// there is a request for that material, the Foo executes -/// that order by sending that amount to the requesting facility. When -/// the simulation time equals the startDate plus the lifeTime, the -/// facility ceases to operate. - -/// @subsection question Question: -/// What is the best way to allow offers of an infinite amount of -/// material on a market? - -class Foo : public cyclus::Facility, - public cyclus::toolkit::CommodityProducer { - public: - // --- Module Members --- - /// Constructor for the Foo class - /// @param ctx the cyclus context for access to simulation-wide parameters - Foo(cyclus::Context* ctx); - - virtual ~Foo() - - #pragma cyclus decl - - #pragma cyclus note {"doc": "A source facility that provides a " \ - "commodity with a given capacity"} - - /// Print information about this agent - virtual std::string str(); - // --- - - // --- Agent Members --- - virtual void EnterNotify(); - - /// Each facility is prompted to do its beginning-of-time-step - /// stuff at the tick of the timer. - - /// @param time is the time to perform the tick - virtual void Tick(); - - /// Each facility is prompted to its end-of-time-step - /// stuff on the tock of the timer. - - /// @param time is the time to perform the tock - virtual void Tock(); - - /// @brief Responds to each request for this source facility's commodity. - /// If a given request is more than this facility's capacity, it will offer - /// its capacity. - virtual std::set::Ptr> - GetMatlBids(cyclus::CommodMap::type& - commod_requests); - - /// @brief respond to each trade with a material made from this facility's - /// recipe - /// - /// @param trades all trades in which this trader is the supplier - /// @param responses a container to populate with responses to each trade - virtual void GetMatlTrades( - const std::vector< cyclus::Trade >& trades, - std::vector, - cyclus::Material::Ptr> >& responses); - // --- - - // --- Foo Members --- - /// @brief creates a material object to offer to a requester - /// @param target the material target a request desires - cyclus::Material::Ptr GetOffer(const cyclus::Material::Ptr target) const; - - /// sets the output commodity name - /// @param name the commodity name - inline void commodity(std::string name) { out_commod = name; } - - /// @return the output commodity - inline std::string commodity() const { return out_commod; } - - /// sets the capacity of a material generated at any given time step - /// @param capacity the production capacity - inline void Capacity(double cap) { - capacity = cap; - current_capacity = capacity; - } - - /// @return the production capacity at any given time step - inline double Capacity() const { return capacity; } - - /// sets the name of the recipe to be produced - /// @param name the recipe name - inline void recipe(std::string name) { recipe_name = name; } - - /// @return the name of the output recipe - inline std::string recipe() const { return recipe_name; } - - /// @return the current timestep's capacity - inline double CurrentCapacity() const { return current_capacity; } - - private: - cyclus::toolkit::Commodity commod_; - - /// This facility has only one output commodity - #pragma cyclus var {"tooltip": "source output commodity", \ - "doc": "output commodity that the source facility " \ - "supplies", \ - "uitype": "outcommodity"} - std::string out_commod; - - /// Name of the recipe this facility uses. - #pragma cyclus var {"tooltip": "commodity recipe name", \ - "doc": "recipe name for source facility's commodity", \ - "uitype": "recipe"} - std::string recipe_name; - - /// The capacity is defined in terms of the number of units of the - /// recipe that can be provided each time step. A very large number - /// can be provided to represent infinte capacity. - #pragma cyclus var {"default": 1e299, "tooltip": "source capacity", \ - "doc": "amount of commodity that can be supplied " \ - "at each time step"} - double capacity; - - /// The capacity at the current time step - #pragma cyclus var {'derived_init': 'current_capacity = capacity;'} - double current_capacity; - - // --- -}; - -} // namespace cycamore - -#endif // CYCAMORE_SRC_FOO_H_ diff --git a/src/foo_tests.cc b/src/foo_tests.cc deleted file mode 100644 index 0973e794d0..0000000000 --- a/src/foo_tests.cc +++ /dev/null @@ -1,204 +0,0 @@ -#include "foo_tests.h" - -#include - -#include - -#include "cyc_limits.h" -#include "resource_helpers.h" -#include "test_context.h" - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void FooTest::SetUp() { - src_facility = new cycamore::Foo(tc.get()); - trader = tc.trader(); - InitParameters(); - SetUpFoo(); -} - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void FooTest::TearDown() { - delete src_facility; -} - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void FooTest::InitParameters() { - commod = "commod"; - recipe_name = "recipe"; - capacity = 5; // some magic number.. - - recipe = cyclus::Composition::CreateFromAtom(cyclus::CompMap()); - tc.get()->AddRecipe(recipe_name, recipe); -} - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void FooTest::SetUpFoo() { - src_facility->commodity(commod); - src_facility->recipe(recipe_name); - src_facility->Capacity(capacity); -} - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -TEST_F(FooTest, InitialState) { - EXPECT_EQ(src_facility->Capacity(), capacity); - EXPECT_EQ(src_facility->commodity(), commod); - EXPECT_EQ(src_facility->recipe(), recipe_name); - EXPECT_EQ(src_facility->CurrentCapacity(), capacity); -} - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -TEST_F(FooTest, Clone) { - cyclus::Context* ctx = tc.get(); - cycamore::Foo* cloned_fac = dynamic_cast - (src_facility->Clone()); - - EXPECT_EQ(src_facility->commodity(), cloned_fac->commodity()); - EXPECT_EQ(src_facility->Capacity(), cloned_fac->Capacity()); - EXPECT_EQ(src_facility->recipe(), cloned_fac->recipe()); - EXPECT_EQ(src_facility->Capacity(), cloned_fac->CurrentCapacity()); - - delete cloned_fac; -} - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -TEST_F(FooTest, Print) { - EXPECT_NO_THROW(std::string s = src_facility->str()); -} - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -TEST_F(FooTest, GetOffer) { - using cyclus::Material; - - double qty = capacity - 1; - Material::Ptr mat = cyclus::NewBlankMaterial(qty); - Material::Ptr obs_mat = src_facility->GetOffer(mat); - EXPECT_EQ(obs_mat->quantity(), qty); - EXPECT_EQ(obs_mat->comp(), recipe); - - qty = capacity + 1; - mat = cyclus::NewBlankMaterial(qty); - obs_mat = src_facility->GetOffer(mat); - EXPECT_EQ(obs_mat->quantity(), capacity); - EXPECT_EQ(obs_mat->comp(), recipe); - - qty = capacity; - mat = cyclus::NewBlankMaterial(qty); - obs_mat = src_facility->GetOffer(mat); - EXPECT_EQ(obs_mat->quantity(), capacity); - EXPECT_EQ(obs_mat->comp(), recipe); -} - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -TEST_F(FooTest, AddBids) { - using cyclus::Bid; - using cyclus::BidPortfolio; - using cyclus::CapacityConstraint; - using cyclus::ExchangeContext; - using cyclus::Material; - - int nreqs = 5; - - boost::shared_ptr< cyclus::ExchangeContext > - ec = GetContext(nreqs, commod); - - std::set::Ptr> ports = - src_facility->GetMatlBids(ec.get()->commod_requests); - - ASSERT_TRUE(ports.size() > 0); - EXPECT_EQ(ports.size(), 1); - - BidPortfolio::Ptr port = *ports.begin(); - EXPECT_EQ(port->bidder(), src_facility); - EXPECT_EQ(port->bids().size(), nreqs); - - const std::set< CapacityConstraint >& constrs = port->constraints(); - ASSERT_TRUE(constrs.size() > 0); - EXPECT_EQ(constrs.size(), 1); - EXPECT_EQ(*constrs.begin(), CapacityConstraint(capacity)); -} - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -TEST_F(FooTest, Response) { - using cyclus::Bid; - using cyclus::Material; - using cyclus::Request; - using cyclus::Trade; - using test_helpers::get_mat; - - std::vector< cyclus::Trade > trades; - std::vector, - cyclus::Material::Ptr> > responses; - - // Null response - EXPECT_NO_THROW(src_facility->GetMatlTrades(trades, responses)); - EXPECT_EQ(responses.size(), 0); - - double qty = capacity / 3; - Request* request = - Request::Create(get_mat(), trader, commod); - Bid* bid = - Bid::Create(request, get_mat(), src_facility); - - Trade trade(request, bid, qty); - trades.push_back(trade); - - // 1 trade - ASSERT_EQ(src_facility->CurrentCapacity(), capacity); - src_facility->GetMatlTrades(trades, responses); - EXPECT_EQ(responses.size(), 1); - EXPECT_EQ(responses[0].second->quantity(), qty); - EXPECT_EQ(responses[0].second->comp(), recipe); - - // 2 trades, total qty = capacity - ASSERT_DOUBLE_EQ(src_facility->CurrentCapacity(), capacity - qty); - ASSERT_GT(src_facility->CurrentCapacity() - 2 * qty, -1 * cyclus::eps()); - trades.push_back(trade); - responses.clear(); - EXPECT_NO_THROW(src_facility->GetMatlTrades(trades, responses)); - EXPECT_EQ(responses.size(), 2); - ASSERT_TRUE(cyclus::AlmostEq(src_facility->CurrentCapacity(), 0)); - - // too much qty, capn! - EXPECT_THROW(src_facility->GetMatlTrades(trades, responses), - cyclus::ValueError); - - // reset! - src_facility->Tick(); - ASSERT_DOUBLE_EQ(src_facility->CurrentCapacity(), capacity); - - delete request; - delete bid; -} - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -boost::shared_ptr< cyclus::ExchangeContext > -FooTest::GetContext(int nreqs, std::string commod) { - using cyclus::Material; - using cyclus::Request; - using cyclus::ExchangeContext; - using test_helpers::get_mat; - - double qty = 3; - boost::shared_ptr< ExchangeContext > - ec(new ExchangeContext()); - for (int i = 0; i < nreqs; i++) { - ec->AddRequest(Request::Create(get_mat(), trader, commod)); - } - return ec; -} - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -cyclus::Agent* FooConstructor(cyclus::Context* ctx) { - return new cycamore::Foo(ctx); -} - -// required to get functionality in cyclus agent unit tests library -#ifndef CYCLUS_AGENT_TESTS_CONNECTED -int ConnectAgentTests(); -static int cyclus_agent_tests_connected = ConnectAgentTests(); -#define CYCLUS_AGENT_TESTS_CONNECTED cyclus_agent_tests_connected -#endif // CYCLUS_AGENT_TESTS_CONNECTED - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -INSTANTIATE_TEST_CASE_P(FooFac, FacilityTests, Values(&FooConstructor)); -INSTANTIATE_TEST_CASE_P(FooFac, AgentTests, Values(&FooConstructor)); diff --git a/src/foo_tests.h b/src/foo_tests.h deleted file mode 100644 index 59888926b7..0000000000 --- a/src/foo_tests.h +++ /dev/null @@ -1,34 +0,0 @@ -#ifndef CYCAMORE_SRC_FOO_TESTS_H_ -#define CYCAMORE_SRC_FOO_TESTS_H_ -#include "foo.h" - -#include - -#include - -#include "agent_tests.h" -#include "context.h" -#include "exchange_context.h" -#include "facility_tests.h" -#include "material.h" - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -class FooTest : public ::testing::Test { - public: - cyclus::TestContext tc; - TestFacility* trader; - cycamore::Foo* src_facility; - std::string commod, recipe_name; - double capacity; - cyclus::Composition::Ptr recipe; - - virtual void SetUp(); - virtual void TearDown(); - void InitParameters(); - void SetUpFoo(); - - boost::shared_ptr< cyclus::ExchangeContext > - GetContext(int nreqs, std::string commodity); -}; - -#endif // CYCAMORE_SRC_FOO_TESTS_H_ From 7d6bb197cca7eaf62449a847b333a26ef97fd32a Mon Sep 17 00:00:00 2001 From: Matthew Gidden Date: Thu, 23 Apr 2015 14:18:47 -0500 Subject: [PATCH 70/80] adding commit msg indicator --- .travis-install.sh | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.travis-install.sh b/.travis-install.sh index 1e53559839..1f9e8a8e15 100755 --- a/.travis-install.sh +++ b/.travis-install.sh @@ -1,5 +1,9 @@ #!/bin/bash +# log +msg=`git log --pretty=oneline -1` +echo "Building commit: $msg" + # setup conda recipe wget https://github.com/gidden/ciclus/archive/travis.zip -O ciclus.zip unzip -j ciclus.zip "*/cycamore/*" -d conda-recipe From 858077e2a6a84f494cbab9a47c969c33dade99e4 Mon Sep 17 00:00:00 2001 From: Matthew Gidden Date: Thu, 23 Apr 2015 14:30:44 -0500 Subject: [PATCH 71/80] adding failure with an explicit check --- .travis-install.sh | 2 + src/CMakeLists.txt | 2 + src/foo.cc | 171 +++++++++++++++++++++++++++++++++++++ src/foo.h | 204 +++++++++++++++++++++++++++++++++++++++++++++ src/foo_tests.cc | 204 +++++++++++++++++++++++++++++++++++++++++++++ src/foo_tests.h | 34 ++++++++ 6 files changed, 617 insertions(+) create mode 100644 src/foo.cc create mode 100644 src/foo.h create mode 100644 src/foo_tests.cc create mode 100644 src/foo_tests.h diff --git a/.travis-install.sh b/.travis-install.sh index 1f9e8a8e15..08a02557a1 100755 --- a/.travis-install.sh +++ b/.travis-install.sh @@ -10,6 +10,8 @@ unzip -j ciclus.zip "*/cycamore/*" -d conda-recipe sed -i "s/- cyclus/- cyclus 0.0/g" conda-recipe/meta.yaml # build +"src/CMakeLists.txt:" +cat src/CMakeLists.txt cmd="conda build --no-test conda-recipe" echo "cmd: $cmd" $cmd diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 6a29fcff22..29e907624e 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -12,6 +12,8 @@ USE_CYCLUS("cycamore" "sink") USE_CYCLUS("cycamore" "source") +USE_CYCLUS("cycamore" "foo") + USE_CYCLUS("cycamore" "deploy_inst") USE_CYCLUS("cycamore" "manager_inst") diff --git a/src/foo.cc b/src/foo.cc new file mode 100644 index 0000000000..9ad8ada201 --- /dev/null +++ b/src/foo.cc @@ -0,0 +1,171 @@ +#include "foo.h" + +#include +#include + +#include + +namespace cycamore { + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +Foo::Foo(cyclus::Context* ctx) + : cyclus::Facility(ctx), + out_commod(""), + recipe_name(""), + capacity(std::numeric_limits::max()) {} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +Foo::~Foo() {} + +#pragma cyclus def clone cycamore::Foo + +#pragma cyclus def schema cycamore::Foo + +#pragma cyclus def annotations cycamore::Foo + +#pragma cyclus def infiletodb cycamore::Foo + +#pragma cyclus def snapshot cycamore::Foo + +#pragma cyclus def snapshotinv cycamore::Foo + +#pragma cyclus def initinv cycamore::Foo + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +void Foo::InitFrom(Foo* m) { + #pragma cyclus impl initfromcopy cycamore::Foo + cyclus::toolkit::CommodityProducer::Copy(m); +} + +void Foo::InitFrom(cyclus::QueryableBackend* b) { + #pragma cyclus impl initfromdb cycamore::Foo + + commod_ = cyclus::toolkit::Commodity(out_commod); + cyclus::toolkit::CommodityProducer::Add(commod_); + cyclus::toolkit::CommodityProducer::SetCapacity(commod_, capacity); + cyclus::toolkit::CommodityProducer::SetCost(commod_, capacity); +} + +void Foo::EnterNotify() { + Facility::EnterNotify(); + commod_ = cyclus::toolkit::Commodity(out_commod); + cyclus::toolkit::CommodityProducer::Add(commod_); + cyclus::toolkit::CommodityProducer::SetCapacity(commod_, capacity); + cyclus::toolkit::CommodityProducer::SetCost(commod_, capacity); +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +std::string Foo::str() { + std::stringstream ss; + std::string ans; + if (cyclus::toolkit::CommodityProducer:: + Produces(cyclus::toolkit::Commodity(out_commod))) { + ans = "yes"; + } else { + ans = "no"; + } + ss << cyclus::Facility::str() + << " supplies commodity '" + << out_commod << "' with recipe '" + << recipe_name << "' at a capacity of " + << capacity << " kg per time step " + << " commod producer members: " << " produces " + << out_commod << "?: " << ans + << " capacity: " << cyclus::toolkit::CommodityProducer::Capacity(commod_) + << " cost: " << cyclus::toolkit::CommodityProducer::Cost(commod_); + return ss.str(); +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +void Foo::Tick() { + LOG(cyclus::LEV_INFO3, "SrcFac") << prototype() << " is ticking {"; + LOG(cyclus::LEV_INFO4, "SrcFac") << "will offer " << capacity + << " kg of " + << out_commod << "."; + LOG(cyclus::LEV_INFO3, "SrcFac") << "Stats: " << str(); + LOG(cyclus::LEV_INFO3, "SrcFac") << "}"; + current_capacity = capacity; // reset capacity +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +void Foo::Tock() { + LOG(cyclus::LEV_INFO3, "SrcFac") << prototype() << " is tocking {"; + LOG(cyclus::LEV_INFO3, "SrcFac") << "}"; +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +cyclus::Material::Ptr Foo::GetOffer( + const cyclus::Material::Ptr target) const { + using cyclus::Material; + double qty = std::min(target->quantity(), capacity); + return Material::CreateUntracked(qty, context()->GetRecipe(recipe_name)); +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +std::set::Ptr> +Foo::GetMatlBids( + cyclus::CommodMap::type& commod_requests) { + using cyclus::Bid; + using cyclus::BidPortfolio; + using cyclus::CapacityConstraint; + using cyclus::Material; + using cyclus::Request; + + std::set::Ptr> ports; + + if (commod_requests.count(out_commod) > 0) { + BidPortfolio::Ptr port(new BidPortfolio()); + + std::vector*>& requests = + commod_requests[out_commod]; + + std::vector*>::iterator it; + for (it = requests.begin(); it != requests.end(); ++it) { + Request* req = *it; + Material::Ptr offer = GetOffer(req->target()); + port->AddBid(req, offer, this); + } + + CapacityConstraint cc(capacity); + port->AddConstraint(cc); + ports.insert(port); + } + return ports; +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +void Foo::GetMatlTrades( + const std::vector< cyclus::Trade >& trades, + std::vector, + cyclus::Material::Ptr> >& responses) { + using cyclus::Material; + using cyclus::Trade; + + double provided = 0; + std::vector< cyclus::Trade >::const_iterator it; + for (it = trades.begin(); it != trades.end(); ++it) { + double qty = it->amt; + current_capacity -= qty; + provided += qty; + // @TODO we need a policy on negatives.. + Material::Ptr response = Material::Create(this, qty, + context()->GetRecipe(recipe_name)); + responses.push_back(std::make_pair(*it, response)); + LOG(cyclus::LEV_INFO5, "SrcFac") << prototype() << " just received an order" + << " for " << qty + << " of " << out_commod; + } + if (cyclus::IsNegative(current_capacity)) { + std::stringstream ss; + ss << "is being asked to provide " << provided + << " but its capacity is " << capacity << "."; + throw cyclus::ValueError(Agent::InformErrorMsg(ss.str())); + } +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +extern "C" cyclus::Agent* ConstructFoo(cyclus::Context* ctx) { + return new Foo(ctx); +} + +} // namespace cycamore diff --git a/src/foo.h b/src/foo.h new file mode 100644 index 0000000000..e35ab83d99 --- /dev/null +++ b/src/foo.h @@ -0,0 +1,204 @@ +#ifndef CYCAMORE_SRC_FOO_H_ +#define CYCAMORE_SRC_FOO_H_ + +#include +#include + +#include "cyclus.h" + +namespace cycamore { + +class Context; + +/// @class Foo +/// This cyclus::Facility provides a simple source of some capacity +/// (possibly infinite) of some commodity/Recipe. + +/// The Foo class inherits from the cyclus::Facility class and is +/// dynamically loaded by the Agent class when requested. + +/// @section introduction Introduction +/// The Foo is a facility type in Cyclus capable of providing +/// a finite or infinite.Supply of a particular material to the +/// simulation. A Foo generates material of a certain +/// composition and commodity type, then offers that material on the +/// appropriate market. Shipments of this material are executed when the +/// market issues an order that the offer has been matched with a +/// request. + +/// @section agentparams Agent Parameters +/// Foo behavior is comprehensively defined by the following +/// parameters: +/// - double capacity: The production capacity of the facility (units +/// vary, but typically kg/month). Capacity is infinite if a negative +/// value is provided. +/// - int startDate: The date on which the facility begins to operate +/// (months). +/// - int lifeTime: The length of time that the facility operates +/// (months). - std::string outCommod: the commodity that this facility +/// produces - double inventorysize: the maximum quantity of material to +/// be held in the inventory +/// - double commodprice: the price of the output material PER UNIT +/// - map outComp + +/// @section optionalparams Optional Parameters +/// Foo behavior may also be specified with the following +/// optional parameters which have default values listed here. +/// - double capacityFactor: The ratio of actual production capacity to +/// the rated production capacity. Default is 1 (actual/rated). +/// - double availFactor: The percent of time the facility operates at +/// its capacity factor. Default is 100%. +/// - double capitalCost: The cost of constructing and commissioning +/// this facility. Default is 0 ($). +/// - double opCost: The annual cost of operation and maintenance of +/// this facility. Default is 0 ( $/year). +/// - int constrTime: The number of months it takes to construct and +/// commission this facility. Default is 0 (months). +/// - int decomTime: The number of months it takes to deconstruct and +/// decommission this facility. Default is 0 (months). +/// - Inst* inst: The institution responsible for this facility. +/// - string name: A non-generic name for this facility. + +/// @section detailed Detailed Behavior +/// @subsection finite If Finite Capacity: +/// The Foo starts operation when the simulation reaches the +/// month specified as the startDate. It immediately begins to produce +/// material at the rate defined by its capacity. Each month the +/// Foo adds the amount it has produced to its inventory. It +/// then offers to the appropriate market exactly as much material as it +/// has in its inventory. If an offer is matched with a request, the +/// Foo executes that order by subtracting the quantity from +/// its inventory and sending that amount to the requesting facility. +/// When the simulation time equals the startDate plus the lifeTime, the +/// facility ceases to operate. +/// @subsection infinite If Infinite Capacity: +/// The Foo starts operation when the simulation reaches the +/// month specified as the startDate. Each month the Foo +/// offers an infinite amount of material to the appropriate market. If +/// there is a request for that material, the Foo executes +/// that order by sending that amount to the requesting facility. When +/// the simulation time equals the startDate plus the lifeTime, the +/// facility ceases to operate. + +/// @subsection question Question: +/// What is the best way to allow offers of an infinite amount of +/// material on a market? + +class Foo : public cyclus::Facility, + public cyclus::toolkit::CommodityProducer { + public: + // --- Module Members --- + /// Constructor for the Foo class + /// @param ctx the cyclus context for access to simulation-wide parameters + Foo(cyclus::Context* ctx); + + virtual ~Foo() + + #pragma cyclus decl + + #pragma cyclus note {"doc": "A source facility that provides a " \ + "commodity with a given capacity"} + + /// Print information about this agent + virtual std::string str(); + // --- + + // --- Agent Members --- + virtual void EnterNotify(); + + /// Each facility is prompted to do its beginning-of-time-step + /// stuff at the tick of the timer. + + /// @param time is the time to perform the tick + virtual void Tick(); + + /// Each facility is prompted to its end-of-time-step + /// stuff on the tock of the timer. + + /// @param time is the time to perform the tock + virtual void Tock(); + + /// @brief Responds to each request for this source facility's commodity. + /// If a given request is more than this facility's capacity, it will offer + /// its capacity. + virtual std::set::Ptr> + GetMatlBids(cyclus::CommodMap::type& + commod_requests); + + /// @brief respond to each trade with a material made from this facility's + /// recipe + /// + /// @param trades all trades in which this trader is the supplier + /// @param responses a container to populate with responses to each trade + virtual void GetMatlTrades( + const std::vector< cyclus::Trade >& trades, + std::vector, + cyclus::Material::Ptr> >& responses); + // --- + + // --- Foo Members --- + /// @brief creates a material object to offer to a requester + /// @param target the material target a request desires + cyclus::Material::Ptr GetOffer(const cyclus::Material::Ptr target) const; + + /// sets the output commodity name + /// @param name the commodity name + inline void commodity(std::string name) { out_commod = name; } + + /// @return the output commodity + inline std::string commodity() const { return out_commod; } + + /// sets the capacity of a material generated at any given time step + /// @param capacity the production capacity + inline void Capacity(double cap) { + capacity = cap; + current_capacity = capacity; + } + + /// @return the production capacity at any given time step + inline double Capacity() const { return capacity; } + + /// sets the name of the recipe to be produced + /// @param name the recipe name + inline void recipe(std::string name) { recipe_name = name; } + + /// @return the name of the output recipe + inline std::string recipe() const { return recipe_name; } + + /// @return the current timestep's capacity + inline double CurrentCapacity() const { return current_capacity; } + + private: + cyclus::toolkit::Commodity commod_; + + /// This facility has only one output commodity + #pragma cyclus var {"tooltip": "source output commodity", \ + "doc": "output commodity that the source facility " \ + "supplies", \ + "uitype": "outcommodity"} + std::string out_commod; + + /// Name of the recipe this facility uses. + #pragma cyclus var {"tooltip": "commodity recipe name", \ + "doc": "recipe name for source facility's commodity", \ + "uitype": "recipe"} + std::string recipe_name; + + /// The capacity is defined in terms of the number of units of the + /// recipe that can be provided each time step. A very large number + /// can be provided to represent infinte capacity. + #pragma cyclus var {"default": 1e299, "tooltip": "source capacity", \ + "doc": "amount of commodity that can be supplied " \ + "at each time step"} + double capacity; + + /// The capacity at the current time step + #pragma cyclus var {'derived_init': 'current_capacity = capacity;'} + double current_capacity; + + // --- +}; + +} // namespace cycamore + +#endif // CYCAMORE_SRC_FOO_H_ diff --git a/src/foo_tests.cc b/src/foo_tests.cc new file mode 100644 index 0000000000..0973e794d0 --- /dev/null +++ b/src/foo_tests.cc @@ -0,0 +1,204 @@ +#include "foo_tests.h" + +#include + +#include + +#include "cyc_limits.h" +#include "resource_helpers.h" +#include "test_context.h" + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +void FooTest::SetUp() { + src_facility = new cycamore::Foo(tc.get()); + trader = tc.trader(); + InitParameters(); + SetUpFoo(); +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +void FooTest::TearDown() { + delete src_facility; +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +void FooTest::InitParameters() { + commod = "commod"; + recipe_name = "recipe"; + capacity = 5; // some magic number.. + + recipe = cyclus::Composition::CreateFromAtom(cyclus::CompMap()); + tc.get()->AddRecipe(recipe_name, recipe); +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +void FooTest::SetUpFoo() { + src_facility->commodity(commod); + src_facility->recipe(recipe_name); + src_facility->Capacity(capacity); +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +TEST_F(FooTest, InitialState) { + EXPECT_EQ(src_facility->Capacity(), capacity); + EXPECT_EQ(src_facility->commodity(), commod); + EXPECT_EQ(src_facility->recipe(), recipe_name); + EXPECT_EQ(src_facility->CurrentCapacity(), capacity); +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +TEST_F(FooTest, Clone) { + cyclus::Context* ctx = tc.get(); + cycamore::Foo* cloned_fac = dynamic_cast + (src_facility->Clone()); + + EXPECT_EQ(src_facility->commodity(), cloned_fac->commodity()); + EXPECT_EQ(src_facility->Capacity(), cloned_fac->Capacity()); + EXPECT_EQ(src_facility->recipe(), cloned_fac->recipe()); + EXPECT_EQ(src_facility->Capacity(), cloned_fac->CurrentCapacity()); + + delete cloned_fac; +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +TEST_F(FooTest, Print) { + EXPECT_NO_THROW(std::string s = src_facility->str()); +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +TEST_F(FooTest, GetOffer) { + using cyclus::Material; + + double qty = capacity - 1; + Material::Ptr mat = cyclus::NewBlankMaterial(qty); + Material::Ptr obs_mat = src_facility->GetOffer(mat); + EXPECT_EQ(obs_mat->quantity(), qty); + EXPECT_EQ(obs_mat->comp(), recipe); + + qty = capacity + 1; + mat = cyclus::NewBlankMaterial(qty); + obs_mat = src_facility->GetOffer(mat); + EXPECT_EQ(obs_mat->quantity(), capacity); + EXPECT_EQ(obs_mat->comp(), recipe); + + qty = capacity; + mat = cyclus::NewBlankMaterial(qty); + obs_mat = src_facility->GetOffer(mat); + EXPECT_EQ(obs_mat->quantity(), capacity); + EXPECT_EQ(obs_mat->comp(), recipe); +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +TEST_F(FooTest, AddBids) { + using cyclus::Bid; + using cyclus::BidPortfolio; + using cyclus::CapacityConstraint; + using cyclus::ExchangeContext; + using cyclus::Material; + + int nreqs = 5; + + boost::shared_ptr< cyclus::ExchangeContext > + ec = GetContext(nreqs, commod); + + std::set::Ptr> ports = + src_facility->GetMatlBids(ec.get()->commod_requests); + + ASSERT_TRUE(ports.size() > 0); + EXPECT_EQ(ports.size(), 1); + + BidPortfolio::Ptr port = *ports.begin(); + EXPECT_EQ(port->bidder(), src_facility); + EXPECT_EQ(port->bids().size(), nreqs); + + const std::set< CapacityConstraint >& constrs = port->constraints(); + ASSERT_TRUE(constrs.size() > 0); + EXPECT_EQ(constrs.size(), 1); + EXPECT_EQ(*constrs.begin(), CapacityConstraint(capacity)); +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +TEST_F(FooTest, Response) { + using cyclus::Bid; + using cyclus::Material; + using cyclus::Request; + using cyclus::Trade; + using test_helpers::get_mat; + + std::vector< cyclus::Trade > trades; + std::vector, + cyclus::Material::Ptr> > responses; + + // Null response + EXPECT_NO_THROW(src_facility->GetMatlTrades(trades, responses)); + EXPECT_EQ(responses.size(), 0); + + double qty = capacity / 3; + Request* request = + Request::Create(get_mat(), trader, commod); + Bid* bid = + Bid::Create(request, get_mat(), src_facility); + + Trade trade(request, bid, qty); + trades.push_back(trade); + + // 1 trade + ASSERT_EQ(src_facility->CurrentCapacity(), capacity); + src_facility->GetMatlTrades(trades, responses); + EXPECT_EQ(responses.size(), 1); + EXPECT_EQ(responses[0].second->quantity(), qty); + EXPECT_EQ(responses[0].second->comp(), recipe); + + // 2 trades, total qty = capacity + ASSERT_DOUBLE_EQ(src_facility->CurrentCapacity(), capacity - qty); + ASSERT_GT(src_facility->CurrentCapacity() - 2 * qty, -1 * cyclus::eps()); + trades.push_back(trade); + responses.clear(); + EXPECT_NO_THROW(src_facility->GetMatlTrades(trades, responses)); + EXPECT_EQ(responses.size(), 2); + ASSERT_TRUE(cyclus::AlmostEq(src_facility->CurrentCapacity(), 0)); + + // too much qty, capn! + EXPECT_THROW(src_facility->GetMatlTrades(trades, responses), + cyclus::ValueError); + + // reset! + src_facility->Tick(); + ASSERT_DOUBLE_EQ(src_facility->CurrentCapacity(), capacity); + + delete request; + delete bid; +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +boost::shared_ptr< cyclus::ExchangeContext > +FooTest::GetContext(int nreqs, std::string commod) { + using cyclus::Material; + using cyclus::Request; + using cyclus::ExchangeContext; + using test_helpers::get_mat; + + double qty = 3; + boost::shared_ptr< ExchangeContext > + ec(new ExchangeContext()); + for (int i = 0; i < nreqs; i++) { + ec->AddRequest(Request::Create(get_mat(), trader, commod)); + } + return ec; +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +cyclus::Agent* FooConstructor(cyclus::Context* ctx) { + return new cycamore::Foo(ctx); +} + +// required to get functionality in cyclus agent unit tests library +#ifndef CYCLUS_AGENT_TESTS_CONNECTED +int ConnectAgentTests(); +static int cyclus_agent_tests_connected = ConnectAgentTests(); +#define CYCLUS_AGENT_TESTS_CONNECTED cyclus_agent_tests_connected +#endif // CYCLUS_AGENT_TESTS_CONNECTED + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +INSTANTIATE_TEST_CASE_P(FooFac, FacilityTests, Values(&FooConstructor)); +INSTANTIATE_TEST_CASE_P(FooFac, AgentTests, Values(&FooConstructor)); diff --git a/src/foo_tests.h b/src/foo_tests.h new file mode 100644 index 0000000000..59888926b7 --- /dev/null +++ b/src/foo_tests.h @@ -0,0 +1,34 @@ +#ifndef CYCAMORE_SRC_FOO_TESTS_H_ +#define CYCAMORE_SRC_FOO_TESTS_H_ +#include "foo.h" + +#include + +#include + +#include "agent_tests.h" +#include "context.h" +#include "exchange_context.h" +#include "facility_tests.h" +#include "material.h" + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +class FooTest : public ::testing::Test { + public: + cyclus::TestContext tc; + TestFacility* trader; + cycamore::Foo* src_facility; + std::string commod, recipe_name; + double capacity; + cyclus::Composition::Ptr recipe; + + virtual void SetUp(); + virtual void TearDown(); + void InitParameters(); + void SetUpFoo(); + + boost::shared_ptr< cyclus::ExchangeContext > + GetContext(int nreqs, std::string commodity); +}; + +#endif // CYCAMORE_SRC_FOO_TESTS_H_ From 3797bf5dbc1f1d827b4c48ef2b5650b5a16e54f2 Mon Sep 17 00:00:00 2001 From: Matthew Gidden Date: Thu, 23 Apr 2015 14:53:53 -0500 Subject: [PATCH 72/80] Revert "adding failure with an explicit check" This reverts commit d7c653699506e3aa4229840db5b97f24bc73d4f4. --- .travis-install.sh | 2 - src/CMakeLists.txt | 2 - src/foo.cc | 171 ------------------------------------- src/foo.h | 204 --------------------------------------------- src/foo_tests.cc | 204 --------------------------------------------- src/foo_tests.h | 34 -------- 6 files changed, 617 deletions(-) delete mode 100644 src/foo.cc delete mode 100644 src/foo.h delete mode 100644 src/foo_tests.cc delete mode 100644 src/foo_tests.h diff --git a/.travis-install.sh b/.travis-install.sh index 08a02557a1..1f9e8a8e15 100755 --- a/.travis-install.sh +++ b/.travis-install.sh @@ -10,8 +10,6 @@ unzip -j ciclus.zip "*/cycamore/*" -d conda-recipe sed -i "s/- cyclus/- cyclus 0.0/g" conda-recipe/meta.yaml # build -"src/CMakeLists.txt:" -cat src/CMakeLists.txt cmd="conda build --no-test conda-recipe" echo "cmd: $cmd" $cmd diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 29e907624e..6a29fcff22 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -12,8 +12,6 @@ USE_CYCLUS("cycamore" "sink") USE_CYCLUS("cycamore" "source") -USE_CYCLUS("cycamore" "foo") - USE_CYCLUS("cycamore" "deploy_inst") USE_CYCLUS("cycamore" "manager_inst") diff --git a/src/foo.cc b/src/foo.cc deleted file mode 100644 index 9ad8ada201..0000000000 --- a/src/foo.cc +++ /dev/null @@ -1,171 +0,0 @@ -#include "foo.h" - -#include -#include - -#include - -namespace cycamore { - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Foo::Foo(cyclus::Context* ctx) - : cyclus::Facility(ctx), - out_commod(""), - recipe_name(""), - capacity(std::numeric_limits::max()) {} - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Foo::~Foo() {} - -#pragma cyclus def clone cycamore::Foo - -#pragma cyclus def schema cycamore::Foo - -#pragma cyclus def annotations cycamore::Foo - -#pragma cyclus def infiletodb cycamore::Foo - -#pragma cyclus def snapshot cycamore::Foo - -#pragma cyclus def snapshotinv cycamore::Foo - -#pragma cyclus def initinv cycamore::Foo - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void Foo::InitFrom(Foo* m) { - #pragma cyclus impl initfromcopy cycamore::Foo - cyclus::toolkit::CommodityProducer::Copy(m); -} - -void Foo::InitFrom(cyclus::QueryableBackend* b) { - #pragma cyclus impl initfromdb cycamore::Foo - - commod_ = cyclus::toolkit::Commodity(out_commod); - cyclus::toolkit::CommodityProducer::Add(commod_); - cyclus::toolkit::CommodityProducer::SetCapacity(commod_, capacity); - cyclus::toolkit::CommodityProducer::SetCost(commod_, capacity); -} - -void Foo::EnterNotify() { - Facility::EnterNotify(); - commod_ = cyclus::toolkit::Commodity(out_commod); - cyclus::toolkit::CommodityProducer::Add(commod_); - cyclus::toolkit::CommodityProducer::SetCapacity(commod_, capacity); - cyclus::toolkit::CommodityProducer::SetCost(commod_, capacity); -} - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -std::string Foo::str() { - std::stringstream ss; - std::string ans; - if (cyclus::toolkit::CommodityProducer:: - Produces(cyclus::toolkit::Commodity(out_commod))) { - ans = "yes"; - } else { - ans = "no"; - } - ss << cyclus::Facility::str() - << " supplies commodity '" - << out_commod << "' with recipe '" - << recipe_name << "' at a capacity of " - << capacity << " kg per time step " - << " commod producer members: " << " produces " - << out_commod << "?: " << ans - << " capacity: " << cyclus::toolkit::CommodityProducer::Capacity(commod_) - << " cost: " << cyclus::toolkit::CommodityProducer::Cost(commod_); - return ss.str(); -} - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void Foo::Tick() { - LOG(cyclus::LEV_INFO3, "SrcFac") << prototype() << " is ticking {"; - LOG(cyclus::LEV_INFO4, "SrcFac") << "will offer " << capacity - << " kg of " - << out_commod << "."; - LOG(cyclus::LEV_INFO3, "SrcFac") << "Stats: " << str(); - LOG(cyclus::LEV_INFO3, "SrcFac") << "}"; - current_capacity = capacity; // reset capacity -} - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void Foo::Tock() { - LOG(cyclus::LEV_INFO3, "SrcFac") << prototype() << " is tocking {"; - LOG(cyclus::LEV_INFO3, "SrcFac") << "}"; -} - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -cyclus::Material::Ptr Foo::GetOffer( - const cyclus::Material::Ptr target) const { - using cyclus::Material; - double qty = std::min(target->quantity(), capacity); - return Material::CreateUntracked(qty, context()->GetRecipe(recipe_name)); -} - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -std::set::Ptr> -Foo::GetMatlBids( - cyclus::CommodMap::type& commod_requests) { - using cyclus::Bid; - using cyclus::BidPortfolio; - using cyclus::CapacityConstraint; - using cyclus::Material; - using cyclus::Request; - - std::set::Ptr> ports; - - if (commod_requests.count(out_commod) > 0) { - BidPortfolio::Ptr port(new BidPortfolio()); - - std::vector*>& requests = - commod_requests[out_commod]; - - std::vector*>::iterator it; - for (it = requests.begin(); it != requests.end(); ++it) { - Request* req = *it; - Material::Ptr offer = GetOffer(req->target()); - port->AddBid(req, offer, this); - } - - CapacityConstraint cc(capacity); - port->AddConstraint(cc); - ports.insert(port); - } - return ports; -} - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void Foo::GetMatlTrades( - const std::vector< cyclus::Trade >& trades, - std::vector, - cyclus::Material::Ptr> >& responses) { - using cyclus::Material; - using cyclus::Trade; - - double provided = 0; - std::vector< cyclus::Trade >::const_iterator it; - for (it = trades.begin(); it != trades.end(); ++it) { - double qty = it->amt; - current_capacity -= qty; - provided += qty; - // @TODO we need a policy on negatives.. - Material::Ptr response = Material::Create(this, qty, - context()->GetRecipe(recipe_name)); - responses.push_back(std::make_pair(*it, response)); - LOG(cyclus::LEV_INFO5, "SrcFac") << prototype() << " just received an order" - << " for " << qty - << " of " << out_commod; - } - if (cyclus::IsNegative(current_capacity)) { - std::stringstream ss; - ss << "is being asked to provide " << provided - << " but its capacity is " << capacity << "."; - throw cyclus::ValueError(Agent::InformErrorMsg(ss.str())); - } -} - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -extern "C" cyclus::Agent* ConstructFoo(cyclus::Context* ctx) { - return new Foo(ctx); -} - -} // namespace cycamore diff --git a/src/foo.h b/src/foo.h deleted file mode 100644 index e35ab83d99..0000000000 --- a/src/foo.h +++ /dev/null @@ -1,204 +0,0 @@ -#ifndef CYCAMORE_SRC_FOO_H_ -#define CYCAMORE_SRC_FOO_H_ - -#include -#include - -#include "cyclus.h" - -namespace cycamore { - -class Context; - -/// @class Foo -/// This cyclus::Facility provides a simple source of some capacity -/// (possibly infinite) of some commodity/Recipe. - -/// The Foo class inherits from the cyclus::Facility class and is -/// dynamically loaded by the Agent class when requested. - -/// @section introduction Introduction -/// The Foo is a facility type in Cyclus capable of providing -/// a finite or infinite.Supply of a particular material to the -/// simulation. A Foo generates material of a certain -/// composition and commodity type, then offers that material on the -/// appropriate market. Shipments of this material are executed when the -/// market issues an order that the offer has been matched with a -/// request. - -/// @section agentparams Agent Parameters -/// Foo behavior is comprehensively defined by the following -/// parameters: -/// - double capacity: The production capacity of the facility (units -/// vary, but typically kg/month). Capacity is infinite if a negative -/// value is provided. -/// - int startDate: The date on which the facility begins to operate -/// (months). -/// - int lifeTime: The length of time that the facility operates -/// (months). - std::string outCommod: the commodity that this facility -/// produces - double inventorysize: the maximum quantity of material to -/// be held in the inventory -/// - double commodprice: the price of the output material PER UNIT -/// - map outComp - -/// @section optionalparams Optional Parameters -/// Foo behavior may also be specified with the following -/// optional parameters which have default values listed here. -/// - double capacityFactor: The ratio of actual production capacity to -/// the rated production capacity. Default is 1 (actual/rated). -/// - double availFactor: The percent of time the facility operates at -/// its capacity factor. Default is 100%. -/// - double capitalCost: The cost of constructing and commissioning -/// this facility. Default is 0 ($). -/// - double opCost: The annual cost of operation and maintenance of -/// this facility. Default is 0 ( $/year). -/// - int constrTime: The number of months it takes to construct and -/// commission this facility. Default is 0 (months). -/// - int decomTime: The number of months it takes to deconstruct and -/// decommission this facility. Default is 0 (months). -/// - Inst* inst: The institution responsible for this facility. -/// - string name: A non-generic name for this facility. - -/// @section detailed Detailed Behavior -/// @subsection finite If Finite Capacity: -/// The Foo starts operation when the simulation reaches the -/// month specified as the startDate. It immediately begins to produce -/// material at the rate defined by its capacity. Each month the -/// Foo adds the amount it has produced to its inventory. It -/// then offers to the appropriate market exactly as much material as it -/// has in its inventory. If an offer is matched with a request, the -/// Foo executes that order by subtracting the quantity from -/// its inventory and sending that amount to the requesting facility. -/// When the simulation time equals the startDate plus the lifeTime, the -/// facility ceases to operate. -/// @subsection infinite If Infinite Capacity: -/// The Foo starts operation when the simulation reaches the -/// month specified as the startDate. Each month the Foo -/// offers an infinite amount of material to the appropriate market. If -/// there is a request for that material, the Foo executes -/// that order by sending that amount to the requesting facility. When -/// the simulation time equals the startDate plus the lifeTime, the -/// facility ceases to operate. - -/// @subsection question Question: -/// What is the best way to allow offers of an infinite amount of -/// material on a market? - -class Foo : public cyclus::Facility, - public cyclus::toolkit::CommodityProducer { - public: - // --- Module Members --- - /// Constructor for the Foo class - /// @param ctx the cyclus context for access to simulation-wide parameters - Foo(cyclus::Context* ctx); - - virtual ~Foo() - - #pragma cyclus decl - - #pragma cyclus note {"doc": "A source facility that provides a " \ - "commodity with a given capacity"} - - /// Print information about this agent - virtual std::string str(); - // --- - - // --- Agent Members --- - virtual void EnterNotify(); - - /// Each facility is prompted to do its beginning-of-time-step - /// stuff at the tick of the timer. - - /// @param time is the time to perform the tick - virtual void Tick(); - - /// Each facility is prompted to its end-of-time-step - /// stuff on the tock of the timer. - - /// @param time is the time to perform the tock - virtual void Tock(); - - /// @brief Responds to each request for this source facility's commodity. - /// If a given request is more than this facility's capacity, it will offer - /// its capacity. - virtual std::set::Ptr> - GetMatlBids(cyclus::CommodMap::type& - commod_requests); - - /// @brief respond to each trade with a material made from this facility's - /// recipe - /// - /// @param trades all trades in which this trader is the supplier - /// @param responses a container to populate with responses to each trade - virtual void GetMatlTrades( - const std::vector< cyclus::Trade >& trades, - std::vector, - cyclus::Material::Ptr> >& responses); - // --- - - // --- Foo Members --- - /// @brief creates a material object to offer to a requester - /// @param target the material target a request desires - cyclus::Material::Ptr GetOffer(const cyclus::Material::Ptr target) const; - - /// sets the output commodity name - /// @param name the commodity name - inline void commodity(std::string name) { out_commod = name; } - - /// @return the output commodity - inline std::string commodity() const { return out_commod; } - - /// sets the capacity of a material generated at any given time step - /// @param capacity the production capacity - inline void Capacity(double cap) { - capacity = cap; - current_capacity = capacity; - } - - /// @return the production capacity at any given time step - inline double Capacity() const { return capacity; } - - /// sets the name of the recipe to be produced - /// @param name the recipe name - inline void recipe(std::string name) { recipe_name = name; } - - /// @return the name of the output recipe - inline std::string recipe() const { return recipe_name; } - - /// @return the current timestep's capacity - inline double CurrentCapacity() const { return current_capacity; } - - private: - cyclus::toolkit::Commodity commod_; - - /// This facility has only one output commodity - #pragma cyclus var {"tooltip": "source output commodity", \ - "doc": "output commodity that the source facility " \ - "supplies", \ - "uitype": "outcommodity"} - std::string out_commod; - - /// Name of the recipe this facility uses. - #pragma cyclus var {"tooltip": "commodity recipe name", \ - "doc": "recipe name for source facility's commodity", \ - "uitype": "recipe"} - std::string recipe_name; - - /// The capacity is defined in terms of the number of units of the - /// recipe that can be provided each time step. A very large number - /// can be provided to represent infinte capacity. - #pragma cyclus var {"default": 1e299, "tooltip": "source capacity", \ - "doc": "amount of commodity that can be supplied " \ - "at each time step"} - double capacity; - - /// The capacity at the current time step - #pragma cyclus var {'derived_init': 'current_capacity = capacity;'} - double current_capacity; - - // --- -}; - -} // namespace cycamore - -#endif // CYCAMORE_SRC_FOO_H_ diff --git a/src/foo_tests.cc b/src/foo_tests.cc deleted file mode 100644 index 0973e794d0..0000000000 --- a/src/foo_tests.cc +++ /dev/null @@ -1,204 +0,0 @@ -#include "foo_tests.h" - -#include - -#include - -#include "cyc_limits.h" -#include "resource_helpers.h" -#include "test_context.h" - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void FooTest::SetUp() { - src_facility = new cycamore::Foo(tc.get()); - trader = tc.trader(); - InitParameters(); - SetUpFoo(); -} - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void FooTest::TearDown() { - delete src_facility; -} - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void FooTest::InitParameters() { - commod = "commod"; - recipe_name = "recipe"; - capacity = 5; // some magic number.. - - recipe = cyclus::Composition::CreateFromAtom(cyclus::CompMap()); - tc.get()->AddRecipe(recipe_name, recipe); -} - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void FooTest::SetUpFoo() { - src_facility->commodity(commod); - src_facility->recipe(recipe_name); - src_facility->Capacity(capacity); -} - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -TEST_F(FooTest, InitialState) { - EXPECT_EQ(src_facility->Capacity(), capacity); - EXPECT_EQ(src_facility->commodity(), commod); - EXPECT_EQ(src_facility->recipe(), recipe_name); - EXPECT_EQ(src_facility->CurrentCapacity(), capacity); -} - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -TEST_F(FooTest, Clone) { - cyclus::Context* ctx = tc.get(); - cycamore::Foo* cloned_fac = dynamic_cast - (src_facility->Clone()); - - EXPECT_EQ(src_facility->commodity(), cloned_fac->commodity()); - EXPECT_EQ(src_facility->Capacity(), cloned_fac->Capacity()); - EXPECT_EQ(src_facility->recipe(), cloned_fac->recipe()); - EXPECT_EQ(src_facility->Capacity(), cloned_fac->CurrentCapacity()); - - delete cloned_fac; -} - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -TEST_F(FooTest, Print) { - EXPECT_NO_THROW(std::string s = src_facility->str()); -} - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -TEST_F(FooTest, GetOffer) { - using cyclus::Material; - - double qty = capacity - 1; - Material::Ptr mat = cyclus::NewBlankMaterial(qty); - Material::Ptr obs_mat = src_facility->GetOffer(mat); - EXPECT_EQ(obs_mat->quantity(), qty); - EXPECT_EQ(obs_mat->comp(), recipe); - - qty = capacity + 1; - mat = cyclus::NewBlankMaterial(qty); - obs_mat = src_facility->GetOffer(mat); - EXPECT_EQ(obs_mat->quantity(), capacity); - EXPECT_EQ(obs_mat->comp(), recipe); - - qty = capacity; - mat = cyclus::NewBlankMaterial(qty); - obs_mat = src_facility->GetOffer(mat); - EXPECT_EQ(obs_mat->quantity(), capacity); - EXPECT_EQ(obs_mat->comp(), recipe); -} - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -TEST_F(FooTest, AddBids) { - using cyclus::Bid; - using cyclus::BidPortfolio; - using cyclus::CapacityConstraint; - using cyclus::ExchangeContext; - using cyclus::Material; - - int nreqs = 5; - - boost::shared_ptr< cyclus::ExchangeContext > - ec = GetContext(nreqs, commod); - - std::set::Ptr> ports = - src_facility->GetMatlBids(ec.get()->commod_requests); - - ASSERT_TRUE(ports.size() > 0); - EXPECT_EQ(ports.size(), 1); - - BidPortfolio::Ptr port = *ports.begin(); - EXPECT_EQ(port->bidder(), src_facility); - EXPECT_EQ(port->bids().size(), nreqs); - - const std::set< CapacityConstraint >& constrs = port->constraints(); - ASSERT_TRUE(constrs.size() > 0); - EXPECT_EQ(constrs.size(), 1); - EXPECT_EQ(*constrs.begin(), CapacityConstraint(capacity)); -} - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -TEST_F(FooTest, Response) { - using cyclus::Bid; - using cyclus::Material; - using cyclus::Request; - using cyclus::Trade; - using test_helpers::get_mat; - - std::vector< cyclus::Trade > trades; - std::vector, - cyclus::Material::Ptr> > responses; - - // Null response - EXPECT_NO_THROW(src_facility->GetMatlTrades(trades, responses)); - EXPECT_EQ(responses.size(), 0); - - double qty = capacity / 3; - Request* request = - Request::Create(get_mat(), trader, commod); - Bid* bid = - Bid::Create(request, get_mat(), src_facility); - - Trade trade(request, bid, qty); - trades.push_back(trade); - - // 1 trade - ASSERT_EQ(src_facility->CurrentCapacity(), capacity); - src_facility->GetMatlTrades(trades, responses); - EXPECT_EQ(responses.size(), 1); - EXPECT_EQ(responses[0].second->quantity(), qty); - EXPECT_EQ(responses[0].second->comp(), recipe); - - // 2 trades, total qty = capacity - ASSERT_DOUBLE_EQ(src_facility->CurrentCapacity(), capacity - qty); - ASSERT_GT(src_facility->CurrentCapacity() - 2 * qty, -1 * cyclus::eps()); - trades.push_back(trade); - responses.clear(); - EXPECT_NO_THROW(src_facility->GetMatlTrades(trades, responses)); - EXPECT_EQ(responses.size(), 2); - ASSERT_TRUE(cyclus::AlmostEq(src_facility->CurrentCapacity(), 0)); - - // too much qty, capn! - EXPECT_THROW(src_facility->GetMatlTrades(trades, responses), - cyclus::ValueError); - - // reset! - src_facility->Tick(); - ASSERT_DOUBLE_EQ(src_facility->CurrentCapacity(), capacity); - - delete request; - delete bid; -} - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -boost::shared_ptr< cyclus::ExchangeContext > -FooTest::GetContext(int nreqs, std::string commod) { - using cyclus::Material; - using cyclus::Request; - using cyclus::ExchangeContext; - using test_helpers::get_mat; - - double qty = 3; - boost::shared_ptr< ExchangeContext > - ec(new ExchangeContext()); - for (int i = 0; i < nreqs; i++) { - ec->AddRequest(Request::Create(get_mat(), trader, commod)); - } - return ec; -} - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -cyclus::Agent* FooConstructor(cyclus::Context* ctx) { - return new cycamore::Foo(ctx); -} - -// required to get functionality in cyclus agent unit tests library -#ifndef CYCLUS_AGENT_TESTS_CONNECTED -int ConnectAgentTests(); -static int cyclus_agent_tests_connected = ConnectAgentTests(); -#define CYCLUS_AGENT_TESTS_CONNECTED cyclus_agent_tests_connected -#endif // CYCLUS_AGENT_TESTS_CONNECTED - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -INSTANTIATE_TEST_CASE_P(FooFac, FacilityTests, Values(&FooConstructor)); -INSTANTIATE_TEST_CASE_P(FooFac, AgentTests, Values(&FooConstructor)); diff --git a/src/foo_tests.h b/src/foo_tests.h deleted file mode 100644 index 59888926b7..0000000000 --- a/src/foo_tests.h +++ /dev/null @@ -1,34 +0,0 @@ -#ifndef CYCAMORE_SRC_FOO_TESTS_H_ -#define CYCAMORE_SRC_FOO_TESTS_H_ -#include "foo.h" - -#include - -#include - -#include "agent_tests.h" -#include "context.h" -#include "exchange_context.h" -#include "facility_tests.h" -#include "material.h" - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -class FooTest : public ::testing::Test { - public: - cyclus::TestContext tc; - TestFacility* trader; - cycamore::Foo* src_facility; - std::string commod, recipe_name; - double capacity; - cyclus::Composition::Ptr recipe; - - virtual void SetUp(); - virtual void TearDown(); - void InitParameters(); - void SetUpFoo(); - - boost::shared_ptr< cyclus::ExchangeContext > - GetContext(int nreqs, std::string commodity); -}; - -#endif // CYCAMORE_SRC_FOO_TESTS_H_ From 35aa9551ccef55900132ddd75d86648ce809468e Mon Sep 17 00:00:00 2001 From: Matthew Gidden Date: Thu, 23 Apr 2015 14:55:17 -0500 Subject: [PATCH 73/80] this should fail unit tests --- src/source_tests.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/source_tests.cc b/src/source_tests.cc index eea1d9c38d..556623a82f 100644 --- a/src/source_tests.cc +++ b/src/source_tests.cc @@ -107,7 +107,7 @@ TEST_F(SourceTest, Response) { // 1 trade src_facility->GetMatlTrades(trades, responses); EXPECT_EQ(responses.size(), 1); - EXPECT_EQ(responses[0].second->quantity(), qty); + EXPECT_EQ(responses[0].second->quantity(), qty + 1); EXPECT_EQ(responses[0].second->comp(), recipe); // 2 trades, total qty = capacity From facd65eff6f6d6bb106624aa3c4e9f1a9c86772c Mon Sep 17 00:00:00 2001 From: Matthew Gidden Date: Thu, 23 Apr 2015 15:04:56 -0500 Subject: [PATCH 74/80] Revert "this should fail unit tests" This reverts commit 8e904cdf8ddedbb16a18f6aa6487df6e33734ee7. --- src/source_tests.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/source_tests.cc b/src/source_tests.cc index 556623a82f..eea1d9c38d 100644 --- a/src/source_tests.cc +++ b/src/source_tests.cc @@ -107,7 +107,7 @@ TEST_F(SourceTest, Response) { // 1 trade src_facility->GetMatlTrades(trades, responses); EXPECT_EQ(responses.size(), 1); - EXPECT_EQ(responses[0].second->quantity(), qty + 1); + EXPECT_EQ(responses[0].second->quantity(), qty); EXPECT_EQ(responses[0].second->comp(), recipe); // 2 trades, total qty = capacity From 67172274292248624f70f838fbadca1d1b218f4b Mon Sep 17 00:00:00 2001 From: Matthew Gidden Date: Thu, 23 Apr 2015 15:32:58 -0500 Subject: [PATCH 75/80] Addressing @scopatz's comments --- .travis-install.sh | 10 ++++------ .travis.yml | 2 -- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/.travis-install.sh b/.travis-install.sh index 1f9e8a8e15..c6a2e10c90 100755 --- a/.travis-install.sh +++ b/.travis-install.sh @@ -1,5 +1,7 @@ #!/bin/bash +set -x + # log msg=`git log --pretty=oneline -1` echo "Building commit: $msg" @@ -10,9 +12,7 @@ unzip -j ciclus.zip "*/cycamore/*" -d conda-recipe sed -i "s/- cyclus/- cyclus 0.0/g" conda-recipe/meta.yaml # build -cmd="conda build --no-test conda-recipe" -echo "cmd: $cmd" -$cmd +conda build --no-test conda-recipe status=$? echo "status: $status" if [[ $status != 0 ]]; then @@ -20,9 +20,7 @@ if [[ $status != 0 ]]; then fi # install -cmd="conda install --use-local cycamore=0.0" -echo "cmd: $cmd" -$cmd +conda install --use-local cycamore=0.0 status=$? echo "status: $status" if [[ $status != 0 ]]; then diff --git a/.travis.yml b/.travis.yml index 5153f20149..54cdd1f8ad 100644 --- a/.travis.yml +++ b/.travis.yml @@ -39,8 +39,6 @@ install: script: - export PATH="$HOME/miniconda/bin:$PATH" - export LD_LIBRARY_PATH="$HOME/miniconda/lib:$LD_LIBRARY_PATH" - #- ls -l $HOME/miniconda/lib - #- ls -l $HOME/miniconda/envs/_build/lib - cycamore_unit_tests - conda install numpy pytables - nosetests -w tests From 09edea328a09e1d6e7131620437f18787d65a16a Mon Sep 17 00:00:00 2001 From: Matthew Gidden Date: Thu, 23 Apr 2015 15:38:05 -0500 Subject: [PATCH 76/80] set -e --- .travis-install.sh | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/.travis-install.sh b/.travis-install.sh index c6a2e10c90..f4cf6adae1 100755 --- a/.travis-install.sh +++ b/.travis-install.sh @@ -1,6 +1,7 @@ #!/bin/bash -set -x +set -x # print cmds +set -e # exit as soon as an error occurs # log msg=`git log --pretty=oneline -1` @@ -13,16 +14,6 @@ sed -i "s/- cyclus/- cyclus 0.0/g" conda-recipe/meta.yaml # build conda build --no-test conda-recipe -status=$? -echo "status: $status" -if [[ $status != 0 ]]; then - exit $status -fi # install conda install --use-local cycamore=0.0 -status=$? -echo "status: $status" -if [[ $status != 0 ]]; then - exit $status -fi From 59f3c6d882f536f5b881358072dfd65f6e3c3cf2 Mon Sep 17 00:00:00 2001 From: Matthew Gidden Date: Thu, 23 Apr 2015 15:04:32 -0500 Subject: [PATCH 77/80] removed testing-specific repo and branch info --- .travis.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 54cdd1f8ad..6a126fed6a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -27,9 +27,8 @@ install: - conda info -a # install cyclus - - git clone https://github.com/gidden/cyclus ../cyclus + - git clone https://github.com/cyclus/cyclus ../cyclus - cd ../cyclus - - git checkout origin/travis - ./.travis-install.sh - cd ../cycamore From 321d900077d1195536959120658ea44b24b7dbbd Mon Sep 17 00:00:00 2001 From: Matthew Gidden Date: Thu, 23 Apr 2015 15:35:05 -0500 Subject: [PATCH 78/80] updating ciclus pull --- .travis-install.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis-install.sh b/.travis-install.sh index f4cf6adae1..0ec08d2ea3 100755 --- a/.travis-install.sh +++ b/.travis-install.sh @@ -8,7 +8,7 @@ msg=`git log --pretty=oneline -1` echo "Building commit: $msg" # setup conda recipe -wget https://github.com/gidden/ciclus/archive/travis.zip -O ciclus.zip +wget https://github.com/cyclus/ciclus/archive/master.zip -O ciclus.zip unzip -j ciclus.zip "*/cycamore/*" -d conda-recipe sed -i "s/- cyclus/- cyclus 0.0/g" conda-recipe/meta.yaml From b1a429cf08b203c52576c602c59a3382af646bd3 Mon Sep 17 00:00:00 2001 From: Matthew Gidden Date: Fri, 24 Apr 2015 15:20:08 -0500 Subject: [PATCH 79/80] bad non-flat schema --- input/recycle.xml | 41 ++++++++++++++++++++++++++++++++++------- 1 file changed, 34 insertions(+), 7 deletions(-) diff --git a/input/recycle.xml b/input/recycle.xml index 406994c642..1167ad498f 100644 --- a/input/recycle.xml +++ b/input/recycle.xml @@ -1,5 +1,4 @@ - flat 600 1 @@ -110,12 +109,40 @@ - repo1 repo - r1 reactor - depleted1 depleted_src - fab1 fuelfab - sep1 separations - enrich1 enrichment + + SingleRegion + + + SingleInstitution + + + repo + 1 + + + reactor + 1 + + + depleted_src + 1 + + + fuelfab + 1 + + + separations + 1 + + + enrichment + 1 + + + + + natl_u From 741fbfd3045d36711f4595156fd3e75709b38e6e Mon Sep 17 00:00:00 2001 From: Matthew Gidden Date: Fri, 24 Apr 2015 18:43:38 -0500 Subject: [PATCH 80/80] using non-flat schema --- input/recycle.xml | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/input/recycle.xml b/input/recycle.xml index 1167ad498f..278662a345 100644 --- a/input/recycle.xml +++ b/input/recycle.xml @@ -6,6 +6,8 @@ + agents NullInst + agents NullRegion cycamore Source cycamore Sink cycamore Enrichment @@ -14,7 +16,7 @@ cycamore Separations - + enrichment @@ -27,9 +29,9 @@ 1e100 - + - + separations @@ -50,9 +52,9 @@ 2.0 - + - + fuelfab @@ -68,9 +70,9 @@ 30001 - + - + reactor @@ -87,9 +89,9 @@ 1 - + - + repo @@ -97,9 +99,9 @@ 1e100 - + - + depleted_src @@ -107,7 +109,7 @@ depleted_u - + SingleRegion