Svalorzen / AI-Toolbox

A C++ framework for MDPs and POMDPs with Python bindings
GNU General Public License v3.0
648 stars 98 forks source link

Issuing Building AIToolboxFMDP (MacOSX) #41

Closed adamhall closed 4 years ago

adamhall commented 4 years ago

Hello,

I followed what was done in #35. I wanted to use python37, so I changed

For Python3.7, change COMPONENTS python3 REQUIRED to COMPONENTS python37 REQUIRED (line 167 of CMakeList.txt) and set(BOOST_PYTHON_LIBRARY_NAME "Boost_PYTHON37_LIBRARY") (line 168 of CMakeList.txt)

I also made /usr/local/include/lpsolve and copied all the lp_*.h into it. I also used the bash file cedavidyang provided.

This allowed cmake to succeed. Here is the output:

-- The CXX compiler identification is AppleClang 10.0.1.10010046
-- Check for working CXX compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++
-- Check for working CXX compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- IPO / LTO enabled

Build type: Release
Logging is DISABLED
# Building MDP
# Building Factored MDP
# Building POMDP
# Building Python bindings
# Building Tests
# Building Examples

-- Boost version: 1.70.0
-- Found Eigen3: /usr/local/include/eigen3 (Required is at least version "3.2.92") 
-- Performing Test LPSOLVE_LINKS_ALONE
-- Performing Test LPSOLVE_LINKS_ALONE - Success
-- Found LpSolve: /usr/local/lib/liblpsolve55.dylib  
-- Found PythonInterp: /anaconda/bin/python (found version "3.7.3") 
-- Found PythonLibs: /usr/local/Frameworks/Python.framework/Versions/3.7/lib/libpython3.7.dylib (found suitable version "3.7.5", minimum required is "3") 
-- Boost version: 1.70.0
-- Found the following Boost libraries:
--   python37
-- Boost version: 1.70.0
-- Found the following Boost libraries:
--   unit_test_framework
-- Configuring done
-- Generating done
-- Build files have been written to: /Users/Adam/Documents/UofT/Thesis/code/AI-Toolbox/build`

And then used make and got the error:

Scanning dependencies of target AIToolboxMDP
[  0%] Building CXX object src/CMakeFiles/AIToolboxMDP.dir/Impl/Seeder.cpp.o
[  1%] Building CXX object src/CMakeFiles/AIToolboxMDP.dir/Impl/CassandraParser.cpp.o
[  1%] Building CXX object src/CMakeFiles/AIToolboxMDP.dir/Utils/Combinatorics.cpp.o
[  1%] Building CXX object src/CMakeFiles/AIToolboxMDP.dir/Utils/Probability.cpp.o
[  2%] Building CXX object src/CMakeFiles/AIToolboxMDP.dir/Utils/Polytope.cpp.o
[  2%] Building CXX object src/CMakeFiles/AIToolboxMDP.dir/Utils/LP/LpSolveWrapper.cpp.o
[  2%] Building CXX object src/CMakeFiles/AIToolboxMDP.dir/Tools/Statistics.cpp.o
[  3%] Building CXX object src/CMakeFiles/AIToolboxMDP.dir/Bandit/Algorithms/RollingAverage.cpp.o
[  3%] Building CXX object src/CMakeFiles/AIToolboxMDP.dir/Bandit/Policies/EpsilonPolicy.cpp.o
[  3%] Building CXX object src/CMakeFiles/AIToolboxMDP.dir/Bandit/Policies/QGreedyPolicy.cpp.o
[  4%] Building CXX object src/CMakeFiles/AIToolboxMDP.dir/Bandit/Policies/QSoftmaxPolicy.cpp.o
[  4%] Building CXX object src/CMakeFiles/AIToolboxMDP.dir/Bandit/Policies/ThompsonSamplingPolicy.cpp.o
[  5%] Building CXX object src/CMakeFiles/AIToolboxMDP.dir/Bandit/Policies/LRPPolicy.cpp.o
[  5%] Building CXX object src/CMakeFiles/AIToolboxMDP.dir/Bandit/Policies/ESRLPolicy.cpp.o
[  5%] Building CXX object src/CMakeFiles/AIToolboxMDP.dir/MDP/Experience.cpp.o
[  6%] Building CXX object src/CMakeFiles/AIToolboxMDP.dir/MDP/Utils.cpp.o
[  6%] Building CXX object src/CMakeFiles/AIToolboxMDP.dir/MDP/Model.cpp.o
[  6%] Building CXX object src/CMakeFiles/AIToolboxMDP.dir/MDP/SparseExperience.cpp.o
[  7%] Building CXX object src/CMakeFiles/AIToolboxMDP.dir/MDP/SparseModel.cpp.o
[  7%] Building CXX object src/CMakeFiles/AIToolboxMDP.dir/MDP/IO.cpp.o
[  7%] Building CXX object src/CMakeFiles/AIToolboxMDP.dir/MDP/Algorithms/QLearning.cpp.o
[  8%] Building CXX object src/CMakeFiles/AIToolboxMDP.dir/MDP/Algorithms/HystereticQLearning.cpp.o
[  8%] Building CXX object src/CMakeFiles/AIToolboxMDP.dir/MDP/Algorithms/SARSA.cpp.o
[  8%] Building CXX object src/CMakeFiles/AIToolboxMDP.dir/MDP/Algorithms/ExpectedSARSA.cpp.o
[  9%] Building CXX object src/CMakeFiles/AIToolboxMDP.dir/MDP/Algorithms/SARSAL.cpp.o
[  9%] Building CXX object src/CMakeFiles/AIToolboxMDP.dir/MDP/Algorithms/ValueIteration.cpp.o
[  9%] Building CXX object src/CMakeFiles/AIToolboxMDP.dir/MDP/Algorithms/PolicyIteration.cpp.o
[ 10%] Building CXX object src/CMakeFiles/AIToolboxMDP.dir/MDP/Algorithms/Utils/OffPolicyTemplate.cpp.o
[ 10%] Building CXX object src/CMakeFiles/AIToolboxMDP.dir/MDP/Policies/PolicyWrapper.cpp.o
[ 10%] Building CXX object src/CMakeFiles/AIToolboxMDP.dir/MDP/Policies/Policy.cpp.o
[ 11%] Building CXX object src/CMakeFiles/AIToolboxMDP.dir/MDP/Policies/RandomPolicy.cpp.o
[ 11%] Building CXX object src/CMakeFiles/AIToolboxMDP.dir/MDP/Policies/EpsilonPolicy.cpp.o
[ 11%] Building CXX object src/CMakeFiles/AIToolboxMDP.dir/MDP/Policies/QPolicyInterface.cpp.o
[ 12%] Building CXX object src/CMakeFiles/AIToolboxMDP.dir/MDP/Policies/QGreedyPolicy.cpp.o
[ 12%] Building CXX object src/CMakeFiles/AIToolboxMDP.dir/MDP/Policies/QSoftmaxPolicy.cpp.o
[ 12%] Building CXX object src/CMakeFiles/AIToolboxMDP.dir/MDP/Policies/WoLFPolicy.cpp.o
[ 13%] Building CXX object src/CMakeFiles/AIToolboxMDP.dir/MDP/Policies/PGAAPPPolicy.cpp.o
[ 13%] Building CXX object src/CMakeFiles/AIToolboxMDP.dir/MDP/Environments/Utils/GridWorld.cpp.o
[ 13%] Linking CXX static library ../libAIToolboxMDP.a
[ 13%] Built target AIToolboxMDP
Scanning dependencies of target AIToolboxPOMDP
[ 14%] Building CXX object src/CMakeFiles/AIToolboxPOMDP.dir/POMDP/Utils.cpp.o
[ 14%] Building CXX object src/CMakeFiles/AIToolboxPOMDP.dir/POMDP/IO.cpp.o
[ 14%] Building CXX object src/CMakeFiles/AIToolboxPOMDP.dir/POMDP/Algorithms/AMDP.cpp.o
[ 15%] Building CXX object src/CMakeFiles/AIToolboxPOMDP.dir/POMDP/Algorithms/GapMin.cpp.o
[ 15%] Building CXX object src/CMakeFiles/AIToolboxPOMDP.dir/POMDP/Algorithms/IncrementalPruning.cpp.o
[ 15%] Building CXX object src/CMakeFiles/AIToolboxPOMDP.dir/POMDP/Algorithms/LinearSupport.cpp.o
[ 16%] Building CXX object src/CMakeFiles/AIToolboxPOMDP.dir/POMDP/Algorithms/PBVI.cpp.o
[ 16%] Building CXX object src/CMakeFiles/AIToolboxPOMDP.dir/POMDP/Algorithms/PERSEUS.cpp.o
[ 16%] Building CXX object src/CMakeFiles/AIToolboxPOMDP.dir/POMDP/Algorithms/BlindStrategies.cpp.o
[ 17%] Building CXX object src/CMakeFiles/AIToolboxPOMDP.dir/POMDP/Algorithms/FastInformedBound.cpp.o
[ 17%] Building CXX object src/CMakeFiles/AIToolboxPOMDP.dir/POMDP/Algorithms/QMDP.cpp.o
[ 17%] Building CXX object src/CMakeFiles/AIToolboxPOMDP.dir/POMDP/Algorithms/Witness.cpp.o
[ 18%] Building CXX object src/CMakeFiles/AIToolboxPOMDP.dir/POMDP/Policies/Policy.cpp.o
[ 18%] Linking CXX static library ../libAIToolboxPOMDP.a
[ 18%] Built target AIToolboxPOMDP
Scanning dependencies of target AIToolboxFMDP
[ 19%] Building CXX object src/CMakeFiles/AIToolboxFMDP.dir/Factored/Utils/FactoredContainer.cpp.o
[ 19%] Building CXX object src/CMakeFiles/AIToolboxFMDP.dir/Factored/Utils/Core.cpp.o
[ 19%] Building CXX object src/CMakeFiles/AIToolboxFMDP.dir/Factored/Utils/FactoredMatrix.cpp.o
[ 20%] Building CXX object src/CMakeFiles/AIToolboxFMDP.dir/Factored/Utils/FactoredVectorOps.cpp.o
[ 20%] Building CXX object src/CMakeFiles/AIToolboxFMDP.dir/Factored/Utils/FactoredMatrix2DOps.cpp.o
[ 20%] Building CXX object src/CMakeFiles/AIToolboxFMDP.dir/Factored/Utils/BayesianNetwork.cpp.o
[ 21%] Building CXX object src/CMakeFiles/AIToolboxFMDP.dir/Factored/Bandit/Algorithms/Utils/VariableElimination.cpp.o
[ 21%] Building CXX object src/CMakeFiles/AIToolboxFMDP.dir/Factored/Bandit/Algorithms/Utils/MultiObjectiveVariableElimination.cpp.o
[ 21%] Building CXX object src/CMakeFiles/AIToolboxFMDP.dir/Factored/Bandit/Algorithms/Utils/UCVE.cpp.o
/Users/Adam/Documents/UofT/Thesis/code/AI-Toolbox/src/Factored/Bandit/Algorithms/Utils/UCVE.cpp:162:55: error: 
      'max' in capture list does not name a variable
                    std::remove_if(begin + 1, bound, [max, x_u = x_u, logtA12 = logtA12...
                                                      ^
/Users/Adam/Documents/UofT/Thesis/code/AI-Toolbox/src/Factored/Bandit/Algorithms/Utils/UCVE.cpp:162:155: error: 
      reference to local binding 'max' declared in enclosing function
      'AIToolbox::Factored::Bandit::(anonymous namespace)::Global::endFactorCrossSum'
  ...= logtA12](const UCVE::Entry & e) { return computeValue(e, x_u, logtA12) <= max; }),
                                                                                 ^
/Users/Adam/Documents/UofT/Thesis/code/AI-Toolbox/src/Factored/Bandit/Algorithms/Utils/UCVE.cpp:156:30: note: 
      'max' declared here
                auto [maxIt, max] = max_element_unary(begin, bound, [x_l = x_l, logtA1...
                             ^
2 errors generated.
make[2]: *** [src/CMakeFiles/AIToolboxFMDP.dir/Factored/Bandit/Algorithms/Utils/UCVE.cpp.o] Error 1
make[1]: *** [src/CMakeFiles/AIToolboxFMDP.dir/all] Error 2
make: *** [all] Error 2

I'm not the best at using CMake, so now I'm a little confused about how to proceed. I also tried to not build FMDP using

cmake -DPYTHON_LIBRARY=$PYTHON_LIBRARY \
   -DPYTHON_INCLUDE_DIR=$PYTHON_INCLUDE_DIR -DMAKE_LIB=1 \
    -DMAKE_MDP=1 -DMAKE_POMDP=1 -DMAKE_TESTS=1 -DMAKE_EXAMPLES=1 ..

But I received the same error. Any thoughts?

Svalorzen commented 4 years ago

Hey,

this doesn't look like a CMake problem, looks more like a bug in Apple Clang. It's trying to compile a file but gives an error, but the code is correct. Does this only happen when setting Python to 3, or also with Python 2? From what I am seeing the problem looks to be completely unrelated to Python.

If you want, you could go at line 161 in file src/Factored/Bandit/Algorithms/Utils/UCVE.cpp and try to replace

            newFactorCrossSum.erase(
                std::remove_if(begin + 1, bound, [max, x_u = x_u, logtA12 = logtA12](const UCVE::Entry & e) { return computeValue(e, x_u, logtA12) <= max; }),
                end
            );

with

            auto tmpMax = max;
            newFactorCrossSum.erase(
                std::remove_if(begin + 1, bound, [tmpMax, x_u = x_u, logtA12 = logtA12](const UCVE::Entry & e) { return computeValue(e, x_u, logtA12) <= tmpMax; }),
                end
            );

This might side-skip the bug. Let me know!

adamhall commented 4 years ago

Thanks for the quick reply! I tried using python2.7 and got the same issue during make. So it not's python related.

I then made the updates to UCVE.cpp as you suggested above, and built using python37. It worked! And all 66 tests passed. Thanks!

I'll let you know if I have any further problems working with the library in python.