-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add only the CEC class to ioh/iohcpp/problem.pyi.
- Loading branch information
Dimitri Rusin
committed
Feb 1, 2024
1 parent
7380fc6
commit e775553
Showing
11 changed files
with
449 additions
and
1,001 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#!/usr/bin/env fish | ||
|
||
true | ||
and rm -rf build/ | ||
and mkdir build/ | ||
and cd build/ | ||
and cmake -DCMAKE_C_COMPILER=gcc-9 -DCMAKE_CXX_COMPILER=g++-9 -DCMAKE_INSTALL_PREFIX=IOHexperimenter .. | ||
and make install |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#!/usr/bin/env fish | ||
|
||
true | ||
and conda activate base | ||
and rm -rf ./.conda_environment/ | ||
and rm -rf build/ | ||
and conda env create --prefix ./.conda_environment/ --file .conda.yaml | ||
and conda activate ./.conda_environment/ | ||
and pip install --requirement .pip.txt | ||
and CC=gcc-9 CXX=g++-9 pip install -e . -vvv |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
#!/usr/bin/env fish | ||
|
||
# Set the directory paths for the project and its includes | ||
set build_dir (pwd)"/build/tests" | ||
set c_implementation_cec_transformations_folder (pwd)"/build/tests/input_data" | ||
set external_dir (pwd)"/external" | ||
set include_dir (pwd)"/include" | ||
set ioh_cec_transformations_folder (pwd)"/static/cec_transformations" | ||
set tests_dir (pwd)"/tests/cpp" | ||
|
||
true | ||
|
||
for line in (cat .env) | ||
set -x (echo $line | cut -d '=' -f 1) (echo $line | cut -d '=' -f 2-) | ||
end | ||
# set -u IOH_RESOURCES | ||
|
||
# and ipython3 tests/python/test_cec_functions.py | ||
|
||
# The following line puts the debug log file and the test_cec_problem executable file | ||
# under the build/ tree. | ||
cd $build_dir | ||
|
||
and rm -f ./cec_test_log.txt ./cec_training_log.txt | ||
|
||
and c++ -Wall -Wextra -pedantic -std=c++17 -lstdc++fs \ | ||
-I$include_dir \ | ||
-I$tests_dir \ | ||
-I$external_dir/fmt/include \ | ||
-I$external_dir/clutchlog \ | ||
-I$external_dir/json/include \ | ||
-isystem $external_dir/googletest/googletest/include \ | ||
-isystem $external_dir/googletest/googletest \ | ||
$tests_dir/problem/test_cec_problem.cpp \ | ||
$tests_dir/entrypoint.cpp \ | ||
-o test_cec_problem \ | ||
$build_dir/../lib/libgtest.a -lpthread | ||
|
||
and rm -f $c_implementation_cec_transformations_folder | ||
and ln -s $ioh_cec_transformations_folder $c_implementation_cec_transformations_folder | ||
|
||
and ./test_cec_problem |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
dependencies: | ||
- python==3.9.18 | ||
- pip==23.3.1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
cmake==3.27.7 | ||
colored==2.2.3 | ||
jupyter==1.0.0 | ||
m2r2==0.3.3.post2 | ||
mypy==1.6.1 | ||
nbconvert==6.5.4 | ||
numpy==1.26.3 | ||
pybind11==2.11.1 | ||
xmltodict==0.13.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,298 @@ | ||
You might get this error message: | ||
```sh | ||
CMake Error at CMakeLists.txt:52 (add_subdirectory): | ||
The source directory | ||
|
||
/home/dimitri/Selbstgemachte_Software/IOHexperimenter/external/fmt | ||
|
||
does not contain a CMakeLists.txt file. | ||
``` | ||
|
||
In this case, run: | ||
```sh | ||
git submodule | ||
git submodule init | ||
git submodule update | ||
``` | ||
|
||
In fact, the first, of the three commands above, will give: | ||
```sh | ||
-32e70c1b3454a9411de2ae8d23020e08f5381f11 external/MkLandscape | ||
-1dcb44e79a17e703e024594487b3a442d87e4741 external/cxxopts | ||
-7df30f91aee5444a733cec0b911d21cebdeb62ae external/fmt | ||
-6a7ed316a5cdc07b6d26362c90770787513822d4 external/googletest | ||
-bc889afb4c5bf1c0d8ee29ef35eaaf4c8bef8a5d external/json | ||
-80dc998efced8ceb2be59756668a7e90e8bef917 external/pybind11 | ||
``` | ||
|
||
```sh | ||
# parentheses only work in the fish shell | ||
sudo chown -R (id -un):(id -gn) /home/dimitri/Selbstgemachte_Software/IOHexperimenter/ | ||
sudo chmod -R 700 /home/dimitri/Selbstgemachte_Software/IOHexperimenter/ | ||
``` | ||
|
||
```sh | ||
git clone [email protected]:Habimm/IOHexperimenter.git | ||
git submodule | ||
git submodule init | ||
git submodule update | ||
sudo chown -R (id -un):(id -gn) /home/dimitri/Selbstgemachte_Software/IOHexperimenter/ | ||
sudo chmod -R 700 /home/dimitri/Selbstgemachte_Software/IOHexperimenter/ | ||
mkdir build | ||
cd build | ||
cmake -DCMAKE_INSTALL_PREFIX=./IOHexperimenter_headers .. | ||
cd .. | ||
sudo make install | ||
``` | ||
|
||
To search for files under the current directory tree with a specific content: | ||
```sh | ||
grep -r "local_ioh" | ||
``` | ||
|
||
To search for files under the current directory tree with a specific filename: | ||
```sh | ||
find . -iname "*local_ioh*" | ||
``` | ||
|
||
To compile a file that uses the IOHexperimenter problems: | ||
```sh | ||
g++ -std=c++17 -I../external/fmt/include -I../include -o one_max one_max.cpp | ||
``` | ||
|
||
```sh | ||
set project_root /home/dimitri/code/IOHexperimenter | ||
set fmt_include_path $project_root/external/fmt/include | ||
set ioh_include_path $project_root/include | ||
|
||
g++ -o one_max -g -std=c++17 -I$fmt_include_path -I$ioh_include_path one_max.cpp | ||
./one_max | ||
``` | ||
|
||
```sh | ||
g++ -o one_max -g -std=c++17 -I$fmt_include_path -I$ioh_include_path one_max.cpp; and ./one_max | ||
``` | ||
|
||
g++ version | ||
```sh | ||
g++ 9.4.0 | ||
``` | ||
|
||
Build everything: | ||
```sh | ||
git clone [email protected]:Habimm/IOHexperimenter.git | ||
cd IOHexperimenter | ||
git submodule | ||
git submodule init | ||
git submodule update | ||
mkdir build | ||
cd build | ||
cmake -DCMAKE_INSTALL_PREFIX=./IOHexperimenter_headers .. | ||
cd .. | ||
sudo make install | ||
``` | ||
|
||
Single Objective Bound Constrained Benchmark | ||
CEC functions | ||
definitions | ||
```sh | ||
https://github.com/P-N-Suganthan/2022-SO-BO | ||
``` | ||
|
||
Prompt for writing CEC functions | ||
```sh | ||
void levy_func (double *x, double *f, int nx, double *Os,double *Mr, int s_flag, int r_flag) /* Levy */ | ||
{ | ||
int i; | ||
f[0] = 0.0; | ||
sr_func (x, z, nx, Os, Mr,1.0, s_flag, r_flag); /* shift and rotate */ | ||
|
||
double *w; | ||
w=(double *)malloc(sizeof(double) * nx); | ||
|
||
double sum1= 0.0; | ||
for (i=0; i<nx; i++) | ||
{ | ||
w[i] = 1.0 + (z[i] - 0.0)/4.0; | ||
} | ||
|
||
double term1 = pow((sin(PI*w[0])),2); | ||
double term3 = pow((w[nx-1]-1),2) * (1+pow((sin(2*PI*w[nx-1])),2)); | ||
|
||
double sum = 0.0; | ||
|
||
for (i=0; i<nx-1; i++) | ||
{ | ||
double wi = w[i]; | ||
double newv = pow((wi-1),2) * (1+10*pow((sin(PI*wi+1)),2)); | ||
sum = sum + newv; | ||
} | ||
|
||
f[0] = term1 + sum + term3;// - 1.442600987052770; // - 1.442600987052770 | ||
free(w); // ADD THIS LINE to free memory! Thanks for Dr. Janez | ||
} | ||
rewrite this in the style of this: | ||
double evaluate(const std::vector<double> &x) override | ||
{ | ||
auto sum1 = 0.0, sum2 = 0.0; | ||
for (const auto xi : x) | ||
{ | ||
sum1 += cos(2.0 * IOH_PI * xi); | ||
sum2 += xi * xi; | ||
} | ||
if (std::isinf(sum2)) { return sum2; } | ||
|
||
auto result = 10.0 * (static_cast<double>(x.size()) - sum1) + sum2; | ||
std::cout << "result: " << result << std::endl; | ||
return result; | ||
} | ||
ignore sr_func, further down the line replace z with x, the f will be returned as a double rather than its memory changed with a pointer | ||
``` | ||
lint C++-17 code | ||
```sh | ||
# put the .clang-format file in the same directory | ||
clang-format -i -style=llvm functions.hpp | ||
``` | ||
Test Python bindings | ||
```sh | ||
conda activate ./.conda_environment | ||
pip install -e . | ||
ipython3 | ||
from ioh import problem | ||
help(problem) | ||
``` | ||
```sh | ||
sudo apt install doxygen | ||
conda activate ./.conda_environment | ||
pip install breathe xmltodict sphinx sphinx-automodapi furo | ||
cd /home/dimitri/code/IOHexperimenter/build | ||
cmake -DBUILD_DOCS=ON .. | ||
make doc | ||
cd .. | ||
ipython3 doc/generate_docs.py | ||
``` | ||
```sh | ||
true | ||
git clone [email protected]:Habimm/IOHexperimenter.git | ||
cd IOHexperimenter | ||
and git submodule | ||
and git submodule init | ||
and git submodule update | ||
and . INSTALL | ||
and conda activate ./.conda_environment | ||
and pip install . | ||
and cd ~ | ||
and ipython3 /home/dimitri/code/IOHexperimenter/tests/python/test_cec_functions.py | ||
``` | ||
On a freshly cloned repo: | ||
```sh | ||
Step 1: Clone repo. | ||
Step 2: Update git submodules. | ||
Step 3: Install virtual environment. | ||
Step 4: Install ioh package. | ||
Step 5: Create .env file with a path to the static/ folder. | ||
Step 6: Source .env. | ||
Step 7: Run Python script. | ||
``` | ||
```sh | ||
echo "IOH_RESOURCES=/home/dimitri/code/IOHexperimenter/static" > .env | ||
for line in (cat .env) | ||
set -x (echo $line | cut -d '=' -f 1) (echo $line | cut -d '=' -f 2-) | ||
end | ||
``` | ||
```sh | ||
true | ||
and git clone [email protected]:Habimm/IOHexperimenter.git | ||
and cd IOHexperimenter | ||
and git submodule | ||
and git submodule init | ||
and git submodule update | ||
and ./INSTALL_IOH | ||
ln -fs (pwd)/static/cec_transformations build/tests/input_data | ||
and echo "IOH_RESOURCES=/home/dimitri/code/IOHexperimenter/static" > .env | ||
and ./RUN | ||
``` | ||
```sh | ||
./INSTALL_IOH | ||
ln -fs (pwd)/static/cec_transformations build/tests/input_data | ||
./RUN | ||
``` | ||
In GitHub Actions we have the following useful environment variables: | ||
```sh | ||
GITHUB_WORKSPACE=/home/runner/work/IOHexperimenter/IOHexperimenter | ||
RUNNER_WORKSPACE=/Users/runner/work/IOHexperimenter | ||
``` | ||
```sh | ||
sudo apt install doxygen | ||
conda activate ./.conda_environment | ||
pip install breathe xmltodict sphinx sphinx-automodapi furo | ||
cd /home/dimitri/code/IOHexperimenter/build | ||
cmake -DBUILD_DOCS=ON .. | ||
wine "/home/dimitri/.wine/drive_c/Program Files/CMake/bin/cmake.exe" -DBUILD_DOCS=ON .. | ||
make doc | ||
cd .. | ||
ipython3 doc/generate_docs.py | ||
``` | ||
Build everything: | ||
```sh | ||
git clone [email protected]:Habimm/IOHexperimenter.git | ||
cd IOHexperimenter | ||
git submodule | ||
git submodule init | ||
git submodule update | ||
mkdir build | ||
cd build | ||
cmake -DCMAKE_INSTALL_PREFIX=./IOHexperimenter_headers .. | ||
wine "/home/dimitri/.wine/drive_c/Program Files/CMake/bin/cmake.exe" -DBUILD_DOCS=ON .. | ||
wine "/home/dimitri/.wine/drive_c/Program Files/CMake/bin/cmake.exe" -DCMAKE_TOOLCHAIN_FILE=/home/dimitri/code/IOHexperimenter/mingw-w64-toolchain.cmake -DBUILD_DOCS=ON .. | ||
cmake -DCMAKE_TOOLCHAIN_FILE=/home/dimitri/code/IOHexperimenter/mingw-w64-toolchain.cmake -DCMAKE_INSTALL_PREFIX=./IOHexperimenter_headers .. | ||
sudo make install | ||
``` | ||
Build everything: | ||
```sh | ||
cd /home/dimitri/code/IOHexperimenter | ||
sudo rm -rf build | ||
mkdir build | ||
cd build | ||
cmake -DCMAKE_TOOLCHAIN_FILE=/home/dimitri/code/IOHexperimenter/mingw-w64-toolchain.cmake -DCMAKE_INSTALL_PREFIX=./IOHexperimenter_headers .. | ||
sudo make install | ||
``` | ||
February 1, 2024 | ||
=========================================================================== | ||
There is a problem with the Python package. Specifically, it shows that essentially, we write null characters inside the string that's supposed to be the optimization problem names. Apparently, the CEC functions are not loaded properly from C++ into Python. Now, there is also the problem that the CEC functions are not loaded at all, yet these weird signs appear and a function called Levy appears although it's loading code has been removed from problems.cpp. There is also a newer version of the package called ioh-1.14.0. There could be a way to load CEC functions, a way inside the package, that I'm unaware of. Also I get errors when running unit tests on Ubuntu, but there are no errors on 32-bit Windows. Additionally, Windows cannot find the ioh_data.zip file but Ubuntu on GitHub Actions seems to be able to find it. | ||
My judgment is that the package is broken. The package should be fixed properly. The package should run on local Ubuntu first, then verify that one CEC function is properly loaded on GitHub's Ubuntu. Then ensure that all one CEC function is properly loaded on GitHub's Windows. Then add more CEC functions, and test these on local Ubuntu first. Use the most-up-to-date IOH version. Verify that one CEC function is actually loaded as expected. |
Oops, something went wrong.