Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

duneuro integration & files organisation #1

Open
tmedani opened this issue Dec 19, 2019 · 77 comments
Open

duneuro integration & files organisation #1

tmedani opened this issue Dec 19, 2019 · 77 comments
Assignees
Labels
documentation Improvements or additions to documentation enhancement New feature or request help wanted Extra attention is needed

Comments

@tmedani
Copy link
Member

tmedani commented Dec 19, 2019

Hey @ftadel & @juangpc,

Sorry if you are getting many spams due to my recent activities in this repo.
I'm still learning how to use git and its fabulous features.

So to keep all the tracks on the code, this repo is connected to another repo:
(I discovered this funny git option 'submodule')

@ftadel here is the invitation, it is a toolbox called "duneuro interface",
where I collected the main functions to run and test duneuro from matlab.

@ftadel I followed your recommendation Nb 2, and I uploaded all to the bst_duneuro toolbox.
At the end of this message, tell me if I need to apply the recommendation Nb 1.

all the functions related to brainstorm integration are, hopefully, in the folder bst-duneuro.
otherwise, they are somewhere in the other folder named "toolbox".
We need just to move them to "bst-duneuro" folder.

Then, in this repo, I added a temporary folder, "bst_addons", where I put the original functions of brainstorm that I modified, listed in this picture (this image is also in this folder)
image

With all these together, I was able to run the EEG, MEG and combined MEG/EEG.

Also, please, don't hesitate to change, comment, criticize, and of course, modify these functions.
this is just a first attempt to make duneuro working from brainstorm.

I have still a lot of improvement that I notified on the code, but you know, code optimization has no limit.

@ftadel I added a lot of comments on the code, as a TODO, where either I didn't know how to do it, or the way how I did it is not the best one.

If you want, we can also plan a bluejeans/skype discussion in order to clarify all these.

Thank you & A+
Takfarinas

@ftadel
Copy link
Member

ftadel commented Dec 19, 2019

I discovered this funny git option 'submodule'

Funny, maybe, but it doesn't look that easy to manipulate... I'll let you deal with this fancy feature and will only work with the repo brainstorm-tools/bst-duneuro :)

tell me if I need to apply the recommendation Nb 1.

Yes, delete this subfolder bst_addons from this repo and open a PR to push them to the brainstorm3 repo.

otherwise, they are somewhere in the other folder named "toolbox".

Can you make sure it works without any functions outside of brainstorm3 and bst-duneuro folders?
(just remove the extra folders from your Matlab path)

If you want, we can also plan a bluejeans/skype discussion in order to clarify all these.

I'll start reviewing all your code after your create the brainstorm3 repo pull request, and we'll see if we need to schedule some more live discussions.
(not sure I'll have time to do it before January, but I guess there is no emergency, is there?)

@tmedani
Copy link
Member Author

tmedani commented Dec 20, 2019

ok, sounds good,
No, there is no emergency.

@juangpc
Copy link
Contributor

juangpc commented Jan 7, 2020

Hey,
I'm ready to work a little bit on the documentation. Is it ok if I push some changes here?

@tmedani
Copy link
Member Author

tmedani commented Jan 7, 2020

Hey,
I'm ready to work a little bit on the documentation. Is it ok if I push some changes here?

Everything & any contributions are welcome !!

@juangpc
Copy link
Contributor

juangpc commented Jan 22, 2020

Hi,

I've finished the documentation and during the following minutes will push some final versions of the compilation script.
I've managed to make it as simple and seamless as possible.
If you clone the repo and run

config/setup_bst_duneuro.sh all

It downloads the source code, cleans previous builds (reduces the chances of problems during compilation), builds everything both for windows and Linux and finally copies the binary application files to /bin folder with the compilation date in the name of the app.

@ftadel following your idea, I've checked and run the compilation using a new ubuntu virtualbox instance. So I guess anybody could re-do the compilation again.

Hope this script is useful once we move on and forget how this all worked.

Let me know if you have any doubts.

@tmedani 2 things.
Could you check that the cpp files in config/toto folder are the last version of the application?
I'm wondering if we could you put all these .m files in the repo's main folder into another folder, like say... matlab or something of the sort? I think it would make it all a bit cleaner. Right now the readme file is only displayed way down after showing all the list of files.

@tmedani
Copy link
Member Author

tmedani commented Jan 23, 2020

Hey there,

Thank you, @juangpc for this wonderful work.
I would say, this is a nice "compression" of the hard steps in one easy command.
I hope also that will be useful, we need to document all this.

Just a small comment, is it possible to change the "toto" folder to "brainstorm_app" os something similar?

@tmedani 2 things.
Could you check that the cpp files in config/toto folder are the last version of the application?

I have checked, and update it.
The original files are in this repo: https://github.com/tmedani/duneuro_interface/tree/master/toolbox/duneuro_cpp/src

I'm wondering if we could you put all these .m files in the repo's main folder into another folder, like say... matlab or something of the sort? I think it would make it all a bit cleaner. Right now the readme file is only displayed way down after showing all the list of files.

done, all the matalb code is moved to a new folder called "matlab"

@tmedani
Copy link
Member Author

tmedani commented Jan 23, 2020

Comments on Matlab and mex file implementation.
If you have Matlab installed in your linux version and you plan to use Brainstorm in this system, you can take advantage of the possibility of building the application as a mex file which will decrease execution times and allow for more interaction between Matlab and duneuro.

In order to do this modify Matlab's path in config/config_release_linux.opts and modify src/duneuro-matlab/toto/CMakeLists.txt file in order to add a separate mex application.

@juangpc : for this part, we need to write a new interface that call original Duneuro Matlab binding.

@ftadel
Copy link
Member

ftadel commented Jan 23, 2020

@juangpc
I would be amazing to have something that simple working!

I tried to run your script on my WSL/Ubuntu, but it didn't work.
Before the long error log, two minor comments:

  • The file config/setup_bst_duneuro.sh is not executable in the repo, easy to fix
  • The script doesn't work if we call it from the config folder, it has to be executed from the bst-duneuro folder directly, which is not so intuitive.

Now the error log:

#####################################################

               Patching fortran issue!!

#####################################################

sed: can't read src/dune-common/cmake/modules/DuneMacros.cmake: No such file or directory

Copying toto folder to duneuro-matlab.

cp: cannot stat 'config/toto': No such file or directory
grep: src/duneuro-matlab/CMakeLists.txt: No such file or directory

Adding subdirectory toto to cmake lists file.

sed: can't read src/duneuro-matlab/CMakeLists.txt: No such file or directory
grep: config/config_release_windows.opts: No such file or directory

Adding full path to toolchain file.

sed: can't read config/config_release_windows.opts: No such file or directory

Deleting previous builds.


Building duneuro. Log file created in build_release_windows_log.txt

----- using default flags $CMAKE_FLAGS from /home/ftadel/bst-duneuro/config/config_release_windows.                         opts -----
/home/ftadel/bst-duneuro/src/dune-common/bin/../lib/dunemodules.lib: line 201: pkg-config: command                          not found
/home/ftadel/bst-duneuro/src/dune-common/bin/../lib/dunemodules.lib: line 88: pkg-config: command n                         ot found
/home/ftadel/bst-duneuro/src/dune-common/bin/../lib/dunemodules.lib: line 88: pkg-config: command n                         ot found
/home/ftadel/bst-duneuro/src/dune-common/bin/../lib/dunemodules.lib: line 88: pkg-config: command n                         ot found
/home/ftadel/bst-duneuro/src/dune-common/bin/../lib/dunemodules.lib: line 88: pkg-config: command n                         ot found
/home/ftadel/bst-duneuro/src/dune-common/bin/../lib/dunemodules.lib: line 88: pkg-config: command n                         ot found
/home/ftadel/bst-duneuro/src/dune-common/bin/../lib/dunemodules.lib: line 88: pkg-config: command n                         ot found
/home/ftadel/bst-duneuro/src/dune-common/bin/../lib/dunemodules.lib: line 88: pkg-config: command n                         ot found
/home/ftadel/bst-duneuro/src/dune-common/bin/../lib/dunemodules.lib: line 88: pkg-config: command n                         ot found
/home/ftadel/bst-duneuro/src/dune-common/bin/../lib/dunemodules.lib: line 88: pkg-config: command n                         ot found
/home/ftadel/bst-duneuro/src/dune-common/bin/../lib/dunemodules.lib: line 88: pkg-config: command n                         ot found
/home/ftadel/bst-duneuro/src/dune-common/bin/../lib/dunemodules.lib: line 392: pkg-config: command                          not found
ERROR: could not find module 'dune-functions',
       module is also unknown to pkg-config.
       Maybe you need to adjust PKG_CONFIG_PATH!
       'dune-functions' is required by dune-pdelab
Execution of dunecontrol terminated due to errors!

 Something went wrong. Check build_release_windows_log.txt or build_release_windows_rebuild_log.txt                          .


Deleting previous builds.


Building duneuro. Log file created in build_release_linux_log.txt

----- using default flags $CMAKE_FLAGS from /home/ftadel/bst-duneuro/config/config_release_linux.op                         ts -----
/home/ftadel/bst-duneuro/src/dune-common/bin/../lib/dunemodules.lib: line 201: pkg-config: command                          not found
/home/ftadel/bst-duneuro/src/dune-common/bin/../lib/dunemodules.lib: line 88: pkg-config: command n                         ot found
/home/ftadel/bst-duneuro/src/dune-common/bin/../lib/dunemodules.lib: line 88: pkg-config: command n                         ot found
/home/ftadel/bst-duneuro/src/dune-common/bin/../lib/dunemodules.lib: line 88: pkg-config: command n                         ot found
/home/ftadel/bst-duneuro/src/dune-common/bin/../lib/dunemodules.lib: line 88: pkg-config: command n                         ot found
/home/ftadel/bst-duneuro/src/dune-common/bin/../lib/dunemodules.lib: line 88: pkg-config: command n                         ot found
/home/ftadel/bst-duneuro/src/dune-common/bin/../lib/dunemodules.lib: line 88: pkg-config: command n                         ot found
/home/ftadel/bst-duneuro/src/dune-common/bin/../lib/dunemodules.lib: line 88: pkg-config: command n                         ot found
/home/ftadel/bst-duneuro/src/dune-common/bin/../lib/dunemodules.lib: line 88: pkg-config: command n                         ot found
/home/ftadel/bst-duneuro/src/dune-common/bin/../lib/dunemodules.lib: line 88: pkg-config: command n                         ot found
/home/ftadel/bst-duneuro/src/dune-common/bin/../lib/dunemodules.lib: line 88: pkg-config: command n                         ot found
/home/ftadel/bst-duneuro/src/dune-common/bin/../lib/dunemodules.lib: line 392: pkg-config: command                          not found
ERROR: could not find module 'dune-functions',
       module is also unknown to pkg-config.
       Maybe you need to adjust PKG_CONFIG_PATH!
       'dune-functions' is required by dune-pdelab
Execution of dunecontrol terminated due to errors!

 Something went wrong. Check build_release_linux_log.txt or build_release_linux_rebuild_log.txt .




@juangpc
Copy link
Contributor

juangpc commented Jan 23, 2020

That's new. something not working.
I'll fix the issues.

@juangpc
Copy link
Contributor

juangpc commented Jan 24, 2020

Hi,
the script setup_bst_duneuro.sh :

  • has a 777 permission scheme.
  • works from wherever you want to call it from.
  • it downloads builds and saves into bin/ the versions for windows and linux.

Hope it works.

The output will be a file named bst_duneuro_meeg_<<date>><<ext>> where <> can, for instance, be "24_01_2020" and extension can be ".exe" in windows and empty in linux.

This means that matlab's call to the executable will need to include the date/version number. I got this idea from the way inverse computation scripts are called (2016 vs 2018 versions, etc...). I think we should enforce some kind of way to verify which version it is being called. We have too many links in this chain and if something is not working we should be able to easily discard sources of the error. This is my intention with the builddate-in-the-name thing. Another possibility would be to have the output of the executable application include the version of the code being executed. Right now, the app will create two separate binary files each storing some matrix. The binary information is preseeded with the following info:
::numRows::numCols::
followed by floating point numbers which are subsecuently read with fread from matlab.
If you guys think so, I can add some kind of ::version::numrows::numcols:: or something of the sort. But for now, to have at least the day of the build in the name of the file is something.
Let me know what you think.

@juangpc
Copy link
Contributor

juangpc commented Jan 24, 2020

Ah! and toto->brainstorm_app...

@tmedani
Copy link
Member Author

tmedani commented Jan 24, 2020

Super @juangpc ... I will set up a new virtual machine and check it.
also, does it make sense to move the file: src_vault.tar.gz to "config" folder

This means that matlab's call to the executable will need to include the date/version number. I got this idea from the way inverse computation scripts are called (2016 vs 2018 versions, etc...). I think we should enforce some kind of way to verify which version it is being called.

I have just added a way to call the exact 'binaries' from Matlab, assuming that the binaries of the linux and windows are the same (8476ca7#r36958908).

This is my intention with the builddate-in-the-name thing. Another possibility would be to have the output of the executable application include the version of the code being executed. Right now, the app will create two separate binary files each storing some matrix. The binary information is preseeded with the following info:
::numRows::numCols::
followed by floating point numbers which are subsecuently read with fread from matlab.
If you guys think so, I can add some kind of ::version::numrows::numcols:: or something of the sort. But for now, to have at least the day of the build in the name of the file is something.
Let me know what you think.

also good, but need more modification on the Cpp code-writer and the MatLab reader.

@juangpc
Copy link
Contributor

juangpc commented Jan 25, 2020 via email

@ftadel
Copy link
Member

ftadel commented Jan 27, 2020

bst_duneuro_meeg_<><>

Maybe there are things I didn't follow here, but this does not seem to be a very standard practice, and I'm not sure this is necessary because there is already a check done in Brainstorm itself (and the installation/update of these binaries will be done by Brainstorm in most cases).
When using Brainstorm, it will always ask to use the latest package of bst-duneuro available on the neuroimage webserver. The current online version is returned with a PHP script (https://neuroimage.usc.edu/bst/getversion_duneuro.php) and the current version installed on the computer is saved in the user folder ($HOME/.brainstorm/bst-duneuro/url).

I added a webhook that calls a PHP script on the neuroimage server that repackages bst-duneuro.zip every time something is pushed to the bst-duneuro repository. So if you update the binaries on the github, you'll be sure that everybody start using this new version immediately.

@ftadel
Copy link
Member

ftadel commented Jan 27, 2020

And regarding the compilation, I still have errors like these.
Is there anything I'm doing wrong?

ftadel@DESKTOP-SQA66ET:~/bst-duneuro/config$ ./setup_bst_duneuro.sh  all

Deleting previous builds.


Deleting previously downloaded code.


Deleting previously downloaded code.

Cloning into 'dune-common'...
remote: Enumerating objects: 59395, done.
remote: Counting objects: 100% (59395/59395), done.
remote: Compressing objects: 100% (15126/15126), done.
remote: Total 59395 (delta 44144), reused 59340 (delta 44103)
Receiving objects: 100% (59395/59395), 13.63 MiB | 2.06 MiB/s, done.
Resolving deltas: 100% (44144/44144), done.
Checking connectivity... done.
Cloning into 'dune-geometry'...
remote: Enumerating objects: 6246, done.
remote: Counting objects: 100% (6246/6246), done.
remote: Compressing objects: 100% (1646/1646), done.
remote: Total 6246 (delta 4603), reused 6208 (delta 4570)
Receiving objects: 100% (6246/6246), 1.94 MiB | 1.67 MiB/s, done.
Resolving deltas: 100% (4603/4603), done.
Checking connectivity... done.
Cloning into 'dune-grid'...
remote: Enumerating objects: 76122, done.
remote: Counting objects: 100% (76122/76122), done.
remote: Compressing objects: 100% (17340/17340), done.
remote: Total 76122 (delta 58669), reused 76028 (delta 58607)
Receiving objects: 100% (76122/76122), 22.57 MiB | 1.19 MiB/s, done.
Resolving deltas: 100% (58669/58669), done.
Checking connectivity... done.
Checking out files: 100% (545/545), done.
Cloning into 'dune-localfunctions'...
remote: Enumerating objects: 15343, done.
remote: Counting objects: 100% (15343/15343), done.
remote: Compressing objects: 100% (3126/3126), done.
remote: Total 15343 (delta 11923), reused 15263 (delta 11848)
Receiving objects: 100% (15343/15343), 1.99 MiB | 2.28 MiB/s, done.
Resolving deltas: 100% (11923/11923), done.
Checking connectivity... done.
Cloning into 'dune-istl'...
fatal: unable to access 'https://gitlab.dune-project.org/core/dune-istl.git/': Failed to connect to gitlab.dune-project.org port 443: Connection refused
Cloning into 'dune-typetree'...
fatal: unable to access 'https://gitlab.dune-project.org/staging/dune-typetree.git/': Failed to connect to gitlab.dune-project.org port 443: Connection refused
Cloning into 'dune-uggrid'...
fatal: unable to access 'https://gitlab.dune-project.org/staging/dune-uggrid.git/': gnutls_handshake() failed: The TLS connection was non-properly terminated.
Cloning into 'dune-functions'...
remote: Enumerating objects: 9922, done.
remote: Counting objects: 100% (9922/9922), done.
remote: Compressing objects: 100% (3050/3050), done.
remote: Total 9922 (delta 6884), reused 9887 (delta 6860)
Receiving objects: 100% (9922/9922), 1.84 MiB | 1.61 MiB/s, done.
Resolving deltas: 100% (6884/6884), done.
Checking connectivity... done.
Note: checking out 'bd847eb9f6617b116f5d6cb4930e5417d7b6e9a7'.

You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by performing another checkout.

If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -b with the checkout command again. Example:

  git checkout -b <new-branch-name>

HEAD is now at bd847eb... [doc] Introduce uniform and flat index maps
Switched to a new branch 'c-interface'
Cloning into 'dune-pdelab'...
remote: Enumerating objects: 40262, done.
remote: Counting objects: 100% (40262/40262), done.
remote: Compressing objects: 100% (10318/10318), done.
remote: Total 40262 (delta 29328), reused 40156 (delta 29238)
Receiving objects: 100% (40262/40262), 6.61 MiB | 2.03 MiB/s, done.
Resolving deltas: 100% (29328/29328), done.
Checking connectivity... done.
Checking out files: 100% (420/420), done.
Cloning into 'duneuro'...
remote: Enumerating objects: 3298, done.
remote: Counting objects: 100% (3298/3298), done.
remote: Compressing objects: 100% (1007/1007), done.
remote: Total 3298 (delta 2436), reused 3047 (delta 2268)
Receiving objects: 100% (3298/3298), 916.05 KiB | 0 bytes/s, done.
Resolving deltas: 100% (2436/2436), done.
Checking connectivity... done.
Cloning into 'duneuro-matlab'...
fatal: unable to access 'https://gitlab.dune-project.org/duneuro/duneuro-matlab.git/': gnutls_handshake() failed: The TLS connection was non-properly terminated.


#####################################################

               Patching fortran issue!!

#####################################################


Copying brainstorm_app folder to duneuro-matlab.


Adding subdirectory brainstorm_app to cmake lists file.


Adding full path to toolchain file.


Deleting previous builds.


Building duneuro. Log file created in build_release_windows_log.txt

----- using default flags $CMAKE_FLAGS from /home/ftadel/bst-duneuro/config/config_release_windows.opts -----
/home/ftadel/bst-duneuro/src/dune-common/bin/../lib/dunemodules.lib: line 201: pkg-config: command not found
/home/ftadel/bst-duneuro/src/dune-common/bin/../lib/dunemodules.lib: line 88: pkg-config: command not found
/home/ftadel/bst-duneuro/src/dune-common/bin/../lib/dunemodules.lib: line 88: pkg-config: command not found
/home/ftadel/bst-duneuro/src/dune-common/bin/../lib/dunemodules.lib: line 88: pkg-config: command not found
/home/ftadel/bst-duneuro/src/dune-common/bin/../lib/dunemodules.lib: line 88: pkg-config: command not found
/home/ftadel/bst-duneuro/src/dune-common/bin/../lib/dunemodules.lib: line 88: pkg-config: command not found
/home/ftadel/bst-duneuro/src/dune-common/bin/../lib/dunemodules.lib: line 88: pkg-config: command not found
/home/ftadel/bst-duneuro/src/dune-common/bin/../lib/dunemodules.lib: line 88: pkg-config: command not found
/home/ftadel/bst-duneuro/src/dune-common/bin/../lib/dunemodules.lib: line 392: pkg-config: command not found
WARNING: could not find module 'dune-uggrid',
       module is also unknown to pkg-config.
       Maybe you need to adjust PKG_CONFIG_PATH!
       'dune-uggrid' is suggested by dune-grid
Skipping 'dune-uggrid'!
/home/ftadel/bst-duneuro/src/dune-common/bin/../lib/dunemodules.lib: line 392: pkg-config: command not found
ERROR: could not find module 'dune-typetree',
       module is also unknown to pkg-config.
       Maybe you need to adjust PKG_CONFIG_PATH!
       'dune-typetree' is required by dune-functions
Execution of dunecontrol terminated due to errors!

 Something went wrong. Check build_release_windows_log.txt or build_release_windows_rebuild_log.txt .


Deleting previous builds.


Building duneuro. Log file created in build_release_linux_log.txt

----- using default flags $CMAKE_FLAGS from /home/ftadel/bst-duneuro/config/config_release_linux.opts -----
/home/ftadel/bst-duneuro/src/dune-common/bin/../lib/dunemodules.lib: line 201: pkg-config: command not found
/home/ftadel/bst-duneuro/src/dune-common/bin/../lib/dunemodules.lib: line 88: pkg-config: command not found
/home/ftadel/bst-duneuro/src/dune-common/bin/../lib/dunemodules.lib: line 88: pkg-config: command not found
/home/ftadel/bst-duneuro/src/dune-common/bin/../lib/dunemodules.lib: line 88: pkg-config: command not found
/home/ftadel/bst-duneuro/src/dune-common/bin/../lib/dunemodules.lib: line 88: pkg-config: command not found
/home/ftadel/bst-duneuro/src/dune-common/bin/../lib/dunemodules.lib: line 88: pkg-config: command not found
/home/ftadel/bst-duneuro/src/dune-common/bin/../lib/dunemodules.lib: line 88: pkg-config: command not found
/home/ftadel/bst-duneuro/src/dune-common/bin/../lib/dunemodules.lib: line 88: pkg-config: command not found
/home/ftadel/bst-duneuro/src/dune-common/bin/../lib/dunemodules.lib: line 392: pkg-config: command not found
WARNING: could not find module 'dune-uggrid',
       module is also unknown to pkg-config.
       Maybe you need to adjust PKG_CONFIG_PATH!
       'dune-uggrid' is suggested by dune-grid
Skipping 'dune-uggrid'!
/home/ftadel/bst-duneuro/src/dune-common/bin/../lib/dunemodules.lib: line 392: pkg-config: command not found
ERROR: could not find module 'dune-typetree',
       module is also unknown to pkg-config.
       Maybe you need to adjust PKG_CONFIG_PATH!
       'dune-typetree' is required by dune-functions
Execution of dunecontrol terminated due to errors!

 Something went wrong. Check build_release_linux_log.txt or build_release_linux_rebuild_log.txt .

@juangpc
Copy link
Contributor

juangpc commented Jan 27, 2020

Hi,
@tmedani I've added the feature of automatically unzip the vault file whenever the download process didn't work for any reason. I think it is much cleaner now.

pkg-config: command not found

@ftadel I think your problem is that you don't have installed pkg-config. Please do the following.

sudo apt-get install git pkg-config cmake mingw-w64 g++-mingw-w64 libc6-dev-i386 python3-pip libeigen3-dev

try calling setup_bst_duneuro.sh all from wherever you want to. At the end, you should be able to find two apps in the test/ folder called: bst_duneuro_meeg_<<date>> and bst_duneuro_meeg_<<date>>.exe for linux and win versions.

Sorry for previous not-perfectly working deploys. The last thing I want to do is make you waste your time. I've downloaded everything from scracth and tested it twice and it is working here. Let me know if something's not working again.

@ftadel I've updated the readme file so that the packages needed etc... are more clear now.

@tmedani
Copy link
Member Author

tmedani commented Jan 27, 2020

bst_duneuro_meeg_<><>

Maybe there are things I didn't follow here, but this does not seem to be a very standard practice, and I'm not sure this is necessary because there is already a check done in Brainstorm itself (and the installation/update of these binaries will be done by Brainstorm in most cases).
When using Brainstorm, it will always ask to use the latest package of bst-duneuro available on the neuroimage webserver. The current online version is returned with a PHP script (https://neuroimage.usc.edu/bst/getversion_duneuro.php) and the current version installed on the computer is saved in the user folder ($HOME/.brainstorm/bst-duneuro/url).

I added a webhook that calls a PHP script on the neuroimage server that repackages bst-duneuro.zip every time something is pushed to the bst-duneuro repository. So if you update the binaries on the github, you'll be sure that everybody start using this new version immediately.

Ok, then the user will not be aware about the duneuro binaries updates, I think also he doesn't need it.
@juan how should we proceed?

I think in any case, from the "coding" view, both versions will work.

@juangpc
Copy link
Contributor

juangpc commented Jan 27, 2020

OK @tmedani and @ftadel I see what you mean:

  • Production-wise, the webhook captures binaries called bst_duneuro_meeg and bst_duneuro_meeg.exe from bin/ . So far so good.
  • Development-wise, the problem is that the development environment is part of duneuro which is updated separately by another repository. So here is my solution:
  1. The source is hard linked between the config/brainstorm_app folder and the src/duneuro-matlab/brainstorm_app. This way it all compiles and code updates are seamlessly updated to github. 2. None of the build* folders nor the logs get pushed to github.
  2. Cpp development code is synced to github and compiled at the same time. Setup script copies the binaries to the test/ folder where tests can be performed. @tmedani can you push all the development ini files to test/ folder in the repository?
  3. Once a new feature is developed tested and so forth, it can be manually copied to bin/ folder as a way to "put it into production".
    Is this ok with you people? I understand it is a bit messy but is the least messy it can get.

@juangpc
Copy link
Contributor

juangpc commented Jan 27, 2020

At some point Id like to try that git large file storage for the zipped src folder.

@juangpc
Copy link
Contributor

juangpc commented Jan 28, 2020

Hi, I've been reading about it. git large files support requires all collaborators to have installed the feature, otherwise, they'll just see a reference file not the actual file. Given it is just one file, and that the amount of forks in this repo is going to probably be... let's say, close to zero... I'm dropping my idea of using such a feature of git. Though it is one fine thing to know about.

Pd. I've been trying to do a bit of further testing and GitLab is down right now... Good thing we have this vault.

@tmedani
Copy link
Member Author

tmedani commented Jan 28, 2020

2. . @tmedani can you push all the development ini files to test/ folder in the repository?

@juangpc the files are already in the folder

3. Once a new feature is developed tested and so forth, it can be manually copied to bin/ folder as a way to "put it into production".
Is this ok with you people? I understand it is a bit messy but is the least messy it can get

sounds good.
I think we are not going to change many time these binaries.

@juangpc
Copy link
Contributor

juangpc commented Jan 28, 2020 via email

@tmedani
Copy link
Member Author

tmedani commented Jan 31, 2020

Hello,

@ftadel I updated the bst-duneuro folder, it's ready for your reviews.
I fully tested a simple EEG Duneuro computation using the Venant method.
(for fast debugging/testing, you can use the 3 layers head model with a coarse mesh and a basic source space, with less than 20 electrodes, here is my testing model 👍
image
)

So, regarding my last modifications, the duneuro binaries will not be copied to the bst temporary folder, but before running the binaries we 'cd' to the \bin\
all the related files are created on the \tmp\ folder, then used by Duneuro from the \bin\ folder

However, the outputs of the binaries are in the \bin\ folder (the leadfiled matrix and the transfer matrix)
So, for now, bst will read the G matrix from this folder.
You can find the "TODO" word, it related to the parts where I was either stuck or it needs further coding/optimisation.

Some explanations about the binaries: there are mainly two outputs
1- the leadfield (LF) matrix or the Gain matrix (G)
2- the transfer matrix

The LF is used immediately, and the TM is just saved for now.
WHY?
The transfer matrix (TM) is important, 80% (or more) of the FEM computation time is related to this matrix.
To compute the LF, only a simple multiplication of the TM by the FEM source space is performed.
So, in the case where the user changes ONLY the source space, the LF computation will be much faster.
However, if ONE of these parameters changes:

  • Head model (mesh, nb of tissue ...)
  • Conductivity value
  • Electrodes' positions

The TF needs to be computed again,

So, in the scenario, where the user changes the cortex (source space) and want to compute again the FEM, we can call this matrix.

The duneuro binaries are already programmed to check if there is any TM in the current folder.
We need now to manage all this from the bst side.

@ftadel
Copy link
Member

ftadel commented Jan 31, 2020

However, the outputs of the binaries are in the \bin\ folder (the leadfiled matrix and the transfer matrix). So, for now, bst will read the G matrix from this folder.

They don't have any way of specifying the output folder?
It seems very unlikely that they designed their program so that it only works with the output data in the binary folder: binaries are most of the time supposed to be in folders where the user doesn't have the write rights... If there is no such feature, it should be reported to them and fixed.

So, in the scenario, where the user changes the cortex (source space) and want to compute again the FEM, we can call this matrix.

We had coded optimized things like this for OpenMEEG as well, to reuse intermediate computation steps, but ended up dropping them. It was causing more confusion than it was helping, and it was making the updates of the software more complicated... In practice, most Brainstorm users do not compute different forward models, especially not with different source spaces. If there is something that they compute multiple times, it's the inverse solutions. If they compute different forward models, it is to compare different methods (ie. same source space, but to compare a spherical model with a BEM).

I think storing this transfer matrix would be useful almost only for the developers (you, Juan, myself). For other users and a standard processing pipeline, it can bring more trouble than advantages.
Maybe we can find a slightly hacked way of reusing this matrix (for instance, by not emptying the temporary folder at the beginning of the process, so that duneuro reuses the existing files), but only for advanced user as a debugging feature, and documenting it in an advanced section of the tutorial. It could be done by setting a global variable for instance.

Maybe it's not necessary to spend time on making this a public standard feature at the moment.

@juangpc
Copy link
Contributor

juangpc commented Jan 31, 2020

Hi,
This is so cool!! what you guys are doing with the meshes. It is great. 🥇

Regarding the discussion of saving the transfer matrix. I'm sorry to disagree but I do think that it makes a lot of sense to save it. For instance, one of the scenarios where this all might become truly useful is in seeg, where you might want to check different electrode positions before surgery. I think that, since it is already working, I would leave it. Besides, nobody "really needs" to understand the dynamics of it all. Some users will notice the second time you compute a similar model the computation is much faster, but they don't really need to know. Still, let me offer a few ideas:

  • I could try to make make the matrix persistent. There are, as far as I've been reading, several solutions libraries in c++ that help you achieve this. This way it will be, implicitly persistent for matlab. As far as any call to the function knows... it will be there. The only problem is that this will be at the cost of main memory of the users computer. If the user doesn't have too much memory... this can all turn quite unstable.
  • I can add another input to the cpp code so that we have an output folder specified in the call.

They don't have any way of specifying the output folder?
It seems very unlikely that they designed their program so that it only works with the output data in the binary folder: binaries are most of the time supposed to be in folders where the user doesn't have the write rights... If there is no such feature, it should be reported to them and fixed

by "they" and "them" you are actually referring to probably @tmedani and myself 😸 😸

@ftadel
Copy link
Member

ftadel commented Jan 31, 2020

How big is this transfer matrix?
With OpenMEEG, the temporary files we were saving were several hundreds of Mb, that were almost never used. That was another reason not to keep it. The databases are big enough, if we can save a few Gb here and there, it's always interesting.
If it's big, maybe we can make it an option to save it (since we'll already need an option panel, it wouldn't cost much to have an extra checkbox).

I could try to make make the matrix persistent

No, let's avoid packing the memory...

I can add another input to the cpp code so that we have an output folder specified in the call

It would be good to have a solution with which 1) we don't have to copy the binaries 2) we don't need to save the output in the binary directory (in the compiled version, the binary folder will be embedded in the brainstorm distribution and possibly read-only). So yes, an output folder option would be good.

by "they" and "them" you are actually referring to probably @tmedani and myself

Oops, I didn't realize that this step was coded by you guys, I thought it was coming from the duneuro people :)

@tmedani
Copy link
Member Author

tmedani commented Jan 31, 2020

How big is this transfer matrix?

Not too big, its size is [Number of Sensor X Number of Source]

From this answer, I think I wrote something wrong in my previous post, sorry guys!.
The transfer matrix depends on the FEM source model and not the source space (also source model but does not mean the same thing!).
It's confusing me, and for sure I confused you... Sorry!
I need to review the theory and I will come back to you with a more accurate answer.
In any way, the transfer matrix is useful to have it.

  1. we don't have to copy the binaries

This is already solved in the last version of bst-duneuro code.

  1. we don't need to save the output in the binary directory

We will updates the binaries asap and add an output directory.
@juangpc we need to discuss this, I think the best way to do it is to add a variable on the INI file and then read it.

@juangpc
Copy link
Contributor

juangpc commented Jan 31, 2020

Hi, I've been doing some testing the cpp app seems to work.

Nice input Tak. Yes I now have a way to specify the output folder within the .ini file
image
And it works.
I still need to push a few details but it seems to be working. I'll push it sometime next week.

But I guess, now my question is. How do you want to use it within brainstorm? Or in other words... we can:

  • We can ask brainstorm to modify the *.ini file with the location of the temp folder for every installation of brainstorm. and then call the bst-duneuro app which will read this address from the text file.
  • We can include a separate parameter like --output /home/username which would be easier for brainstorm because we do know where the temp folder will be. I think this might be less elegant but a bit more convenient since we are doing a system call from brainstorm, which implies creating a string for the system call.

By the way, both relative and absolute paths will work in both options. let me know which one you prefer and I'll compile and push.

@tmedani
Copy link
Member Author

tmedani commented Jan 31, 2020

Hi @juangpc ,
This is super! bravo.

For your question

How do you want to use it within brainstorm?

As it is implemented now, when it's needed,
bst-duneuro toolbox will be download and installed on
.brainstorm\
and when the FEM is called, all the temporary folders (dipole, electrode, mesh ....) will be saved to
.brainstrom\tmp
for now, only the binaries outputs are on
bst-duneuro\bin
but with your modification, they will be also moved to the tmp folder, which will keep the bst-duneuro/bin clean
so, we need just to add on the ini file the value of the outputfolder like this :
outputfolder = .brainstorm\tmp
Then we are done with this :)
@ftadel do you agree?

@juangpc
Copy link
Contributor

juangpc commented Jan 31, 2020 via email

@juangpc
Copy link
Contributor

juangpc commented Feb 6, 2020

Hi @tmedani, sorry I wasn't understanding you.
After several tests I can confirm that if you put a path in the ini file either as a text, with or without spaces, or using single or double quotes, it will be parsed correctly and used.

But as I understand it right now, the problem is in fact inside matlab, not the cpp. The way matlab handles the spaces... I'll show you the fix so you can solve the issue yourself, I don't want to mess around with the scripts while you're working with them.
I've done some testing and the call is working just fine right now. You just need to suround your path to the binary in double-quotes.
I've created to separate folders in my pc: my folder and my other folder. If copy the binary into the 1st folder, an ini file into the 2nd, and you run the following code...

clear
bstfpath = 'C:\projects\my folder';
bstfname = 'bst_duneuro_meeg';
bstext = '.exe';
inifpath = 'C:\projects\my other folder';
inifname = 'eeg_transfer_cg_0001.ini';
arghelp = '--h';

callStr1 = [ bstfpath  filesep bstfname bstext ' ' inifpath filesep inifname ' ' arghelp];
callStr2 = [ '"' bstfpath  filesep bstfname bstext '" "' inifpath filesep inifname ' ' arghelp '"'];
callStr3 = [ '"' bstfpath  filesep bstfname bstext '" ' inifpath filesep inifname ' ' arghelp];
callStr4 = [ '"' bstfpath  filesep bstfname bstext ' ' inifpath filesep inifname ' ' arghelp '"'];

system(callStr1)
system(callStr2);
system(callStr3);
system(callStr4);

>> system(callStr1)
'C:\projects\my' is not recognized as an internal or external command,
operable program or batch file.
ans =
1

>> system(callStr2);
Dune reported error: Dune::IOError [readINITree:/home/juan/bst-duneuro/src/dune-common/dune/common/parametertreeparser.cc:49]: Could not open configuration file C:\projects\my other folder\eeg_transfer_cg_0001.ini --h

>> system(callStr3);

BST_DUNEURO_MEEG 
This script computes lead fields for EEG, MEG and combined MEG/EEG forward problem. 
Based on duneuro softweare (www.duneuro.org) 
Designed to work with Brainstorm Toolbox (https://neuroimage.usc.edu/brainstorm)       
Created initially by the Duneuro team. 
Adapted and modified by Takfarinas Medani and Juan Garcia-Prieto 
 
Usage: bst_duneuro_meeg config_file.ini --mode 
 
    - config_file.ini 
      Configuration file containing the parmeters of the forward model to compute. 
 
    - mode: {eeg, meg, meeg} 
 
This application computes the MEG, MEG and combined MEG/EEG transfer matrix and the final leadfields solution 
If the source/sensor models are not modified, the application will search for a previously computed transfer 
matrix (stored in eeg_transfer.dat or meg_transfer.dat binary files. 
The final output leadfiedl martix will be stored in a binary and a text file named eeg_lf.dat/txt and/or 
meg_lf.dat/txt 
 
 
Examples: 
 
    - bst_duneuro --help                                 Will print this help. 
 
    - bst_duneuro eeg_config_file.mini --eeg             Will compute solution for eeg. 
 
    - bst_duneuro meg_config_file.mini --meg             Will compute solution for meg. 
 
    - bst_duneuro meeg_config_file.mini --meeg           Will compute solution for both/combined meg and eeg. 

>> system(callStr4);
The filename, directory name, or volume label syntax is incorrect.

--
Short answer... none of the above really work. It is interesting. What really happens is that you have to include open and close double quote markes in every argument of a system call. First argument will be the actual binary path and filename with extension. Following arguments would be... the ini file or the '--h' if you want help.

so...

callStr5 = [ '"' bstfpath  filesep bstfname bstext '"' ' ' '"' inifpath filesep inifname '"' ' ' '"' arghelp '"'];
callStr6 = [ '"' bstfpath  filesep bstfname bstext '"' ' ' '"' inifpath filesep inifname '"'];
system(callStr5);
system(callStr6);

>> system(callStr5);

BST_DUNEURO_MEEG 
This script computes lead fields for EEG, MEG and combined MEG/EEG forward problem. 
Based on duneuro softweare (www.duneuro.org) 
Designed to work with Brainstorm Toolbox (https://neuroimage.usc.edu/brainstorm)       
Created initially by the Duneuro team. 
Adapted and modified by Takfarinas Medani and Juan Garcia-Prieto 
 
Usage: bst_duneuro_meeg config_file.ini --mode 
 
    - config_file.ini 
      Configuration file containing the parmeters of the forward model to compute. 
 
    - mode: {eeg, meg, meeg} 
 
This application computes the MEG, MEG and combined MEG/EEG transfer matrix and the final leadfields solution 
If the source/sensor models are not modified, the application will search for a previously computed transfer 
matrix (stored in eeg_transfer.dat or meg_transfer.dat binary files. 
The final output leadfiedl martix will be stored in a binary and a text file named eeg_lf.dat/txt and/or 
meg_lf.dat/txt 
 
 
Examples: 
 
    - bst_duneuro --help                                 Will print this help. 
 
    - bst_duneuro eeg_config_file.mini --eeg             Will compute solution for eeg. 
 
    - bst_duneuro meg_config_file.mini --meg             Will compute solution for meg. 
 
    - bst_duneuro meeg_config_file.mini --meeg           Will compute solution for both/combined meg and eeg. 

>> system(callStr6);
Dune reported error: DGFException [DGFGridFactory:/home/juan/bst-duneuro/src/dune-grid/dune/grid/io/file/dgfparser/dgfug.hh:107]: Error: Macrofile test_sphere_hex.dgf not found

Both callStr5 or callStr6 will work JUST FINE!
so @tmedani what needs to be done is to generate a call concatenating with spaces diferent arguments. Each argument with double quotes... that way it will work!

@juangpc
Copy link
Contributor

juangpc commented Feb 6, 2020

By the way, we need to update the help message!

@tmedani
Copy link
Member Author

tmedani commented Feb 7, 2020

so @tmedani what needs to be done is to generate a call concatenating with spaces different arguments. Each argument with double quotes... that way it will work!

Super Juan .... thanks for the super-review.
I have just updated the function call.

By the way, we need to update the help message!

indeed... still a lot to do...

@juangpc
Copy link
Contributor

juangpc commented Mar 20, 2020

Hi all.

Its been quite painful to adapt the code to run in a mac. I'm writing this to inform you and also as a reminder for myself in case I need to go through this fantastic experience of adapting code designed for a different OS, again.

There were some random errors and some need for static allocations, and other things.
There seems to be a problem in the EEG transfer method, because after computing the lead field, there is a segmentation error. It doesn't seem to be related to the stack size because I've enlarged it to several dozen mb and the error is still there. However, the app does work. The segfault was not happening in high sierra but it is occurring in catalina. I've tried to valgrind it but there is still not a valgrind port for catalina... so, given that it is working. I just kept going with my life.

I've renamed the binary files, for linux64, win64 and mac64. The first call seems to be working. The second call "sometimes" produces this segfault, right before closing. I figure it might be related to the ownership of some smart pointer.

linux and windows compilation can be done with the same linux machine automatically (see help).
For Mac version you need a mac with a couple of things installed, nothing fancy (brew, gcc, dpkg-config I think).

Take care @tmedani and @ftadel (and anybody else out there reading).

@juangpc
Copy link
Contributor

juangpc commented Mar 20, 2020

Windows, Linux and Mac binaries can be found in the test/ folder, as of 3a57e61

@tmedani
Copy link
Member Author

tmedani commented Mar 22, 2020

Thank you @juangpc for this detailed report, and for the lot of efforts that you put to make it work...

If I understand, I have to updates the call for the binaries from bst_duneuro...
now the MAC app is not the same as the Linux.

I will updates this asap.

Take care @tmedani and @ftadel (and anybody else out there reading).

Thank you... take care and stay safe all of you ...
I hope that this nightmare will finish soon.

@juangpc
Copy link
Contributor

juangpc commented Mar 23, 2020

HI @tmedani , yep.

If you look in /bin folder you will see 3 binaries now for all mayor x64 OS. We agreed (I trhink) to keep these 3, right? The code is practically unchanged between mac and linux, but the binaries are different.

There were some problems with a pointer and a few other minor things. Also, another issue was that macos "sed", is surprisingly not equivalent to gnu's. It took a while to figure this out. Apart from that, the code compiles now. And all the compiling scripts too.

There is this issue, still. It doesn't appear in windows, nor linux. It didn't appear in high sierra but for some reason I am seeing this segmentation fault in Catalina. I just can't figure it out. And, valgrind is... as mentioned, still not ready for Catalina, so:

  • I say we keep this version since the error seems to happen while destructing objects at the end of the program.
  • I think it would be nice if some other member tried to run all 3 binary versions. In order to "validate" before considering things done. What do you think?

@ftadel
Copy link
Member

ftadel commented Mar 24, 2020

@tmedani @juangpc
I'd like to start working on cleaning, packaging and testing bst-duneuro.

We need to split what is currently on brainstorm-tools/bst-duneuro in two:

  1. on one side, we keep what is strictly necessary for Brainstorm to compute a FEM forward model: this is downloaded automatically when needed as a .zip file generated automatically on the neuroimage server by some PHP scripts. At the moment, this package is updated every time there is a modification on the brainstorm-tools/bst-duneuro repository, but we might need to change this. I would like to keep this package under 10Mb (zipped).
  2. on the other side, everything related to the compilation and expert/developer's use of duneuro, your work in progress, your tests and examples (todoDuneuroBst.m, config/, test/...)

Two possible solutions:

  1. I create a new repository bst-duneuro-dev,
  2. In the existing repository, you create a new folder "dev" and move there everything we don't need to install on users' computers. In my builder scripts, I would simply exclude this dev folder from the creation of .zip package. And I would need to change the update logic: we wouldn't need to update the .zip package and force all users to update bst-duneuro if you change something in this folder.

What do you think?

@juangpc
Copy link
Contributor

juangpc commented Mar 24, 2020

Hi there,
As far as I understand it, strictly necessary is just:

  1. contents of the binary folder, only one binary for each OS.

image

Why not running some kind of:

platform = mexext;
if strcmp(platform,'mexmaci64')
    % Code to run on Mac.
    % download mac version of binary
    binUrl = 'https://github.com/brainstorm-tools/bst-duneuro/blob/master/bin/bst_duneuro_meeg_mac64?raw=true';
    filename = 'bst_duneuro_meeg';
    outfilename = websave(filename,binUrl);
    system('chmod +x bst_duneuro_meeg');
elseif strcmp(platform,'mexa64')
    % Code to run on Linux platform
    % equivalent linux code
elseif strcmp(platform,'mexw64')
    % Code to run on Windows platform
    % equivalent win code
else
    disp('Platform not supported')
end

As usual @ftadel I don't intend to mind the way you like to write bst or matlab code in general. What I want to do is learn and improve my cs knowledge. That is why I'm proposing this snippet. Is it a bad idea? (I am assuming it is) 😅 But why? instead of a webhook whatever we do on our dev side, we just make sure the name of the bin file is that one, and therefore it will always be there.
And if we want to continue dev we can always create new branches later to be merged with master... Or if at some point we want to only download a specific node in the graph, we can substitute the word 'master' in the url, with the hashkey and done!

Personally, I would definitely discard creating another repo.

@juangpc
Copy link
Contributor

juangpc commented Mar 24, 2020

I forgot to mention other things you need. So strictly necessary is:

  • binary app. (previous post).
  • ini configuration file.
  • all the necessary channel location, source model, head model, etc... that go with the fem computation.

@tmedani
Copy link
Member Author

tmedani commented Mar 24, 2020

Hey @ftadel @juangpc

I'd like to start working on cleaning, packaging and testing bst-duneuro.

great, please let me know when you will start.
I will push the last changes and stop working on them.

Two possible solutions:

  1. I create a new repository bst-duneuro-dev,
  2. In the existing repository, you create a new folder "dev" and move there everything we don't need to install on users' computers. In my builder scripts, I would simply exclude this dev folder from the creation of .zip package. And I would need to change the update logic: we wouldn't need to update the .zip package and force all users to update bst-duneuro if you change something in this folder.

in order to keep the actual development (DTI/anisotropy) I prefer the option 2,
instead, to remove files we can put all the "not needed" files on the "dev" folder and when validated we can move to the users' version and we will clean the rest.

@ftadel does it work for you?

Personally, I would definitely discard creating another repo.

agree also, we have already too much for this project.

@juangpc

The code is practically unchanged between mac and linux, but the binaries are different

How this is possible?
just by using different machines?

  • I say we keep this version since the error seems to happen while destructing objects at the end of the program.
  • I think it would be nice if some other member tried to run all 3 binary versions. In order to "validate" before considering things done. What do you think?

I have Linux and windows but nor mac, I will try to test on these machines asap.

also, we will have at least one student from Carsten's group who will start working with this tool and we can have their feedback.

@ftadel
Copy link
Member

ftadel commented Mar 25, 2020

@tmedani

instead, to remove files we can put all the "not needed" files on the "dev" folder and when validated we can move to the users' version and we will clean the rest.
@ftadel does it work for you?

Yes, please do.
Everything outside of the /dev folder, I might rewrite, reorganize and rename, or even delete if it does not appear to be needed in Brainstorm... :)

@juangpc

As usual @ftadel I don't intend to mind the way you like to write bst or matlab code in general. What I want to do is learn and improve my cs knowledge. That is why I'm proposing this snippet. Is it a bad idea? (I am assuming it is) 😅 But why?

Where do you want to put this code? I don't understand why you want to re-download the macos binaries, and only the mac binaries, while there is already a mechanism in place that download the three executables at once and keep them updated.
Strictly about why not using websave: it is not available on older Matlab versions, it does not offer a progress bar , we already have much better tools available.
https://github.com/brainstorm-tools/brainstorm3/blob/master/toolbox/process/functions/process_generate_fem.m#L1326

@juangpc
Copy link
Contributor

juangpc commented Mar 25, 2020

Hi,

I don't understand why you want to re-download the macos binaries, and only the mac binaries, while there is already a mechanism in place that download the three executables at once and keep them updated.

The "only mac" was because that's the only case I coded, but I meant to show the snippet as an example. Just to do the same for all 3 major platforms.

Regarding the other mechanisms in place:

I added a webhook that calls a PHP script on the neuroimage server that repackages bst-duneuro.zip every time something is pushed to the bst-duneuro repository. So if you update the binaries on the github, you'll be sure that everybody starts using this new version immediately.

I understand from the code, and from this message, you shared a few weeks ago (previous paragraph). That every time something is pushed to the repo, a copy of the binaries and only the binaries is saved in neuroimage server, from where bst users will then download the actual apps. Ok, questions:

  1. Users will download all 3 binaries, regardless of their OS? It is ok if this is how you want it to be. I just want to understand it. My initial understanding is that it seems simpler to just download the binary for your OS. However, it doesn't seem like a big deal either way. It is just that it is very unlikely that a BST installation will run on two different OS, so, why would you want to have a macos binary in a windows machine. But, as I said, it is ok with me.

  2. I see the version number is right now the date of the last push. OK. Why not let the users download directly from github? Why add the extra layer of downloading a version from github to neuroimage and then users access this copy instead of the binaries in github? I mean github is a five nines system.

  3. How are different versions and developments allowed once we follow this scheme? I mean, if a new branch in the repo is created will the webhook still make the php in neuroimage to update the binaries?
    I'm really not sure how much development will there be in this repo (probably not much). But still, it would be nice to be able to test code and push it to a dev branch, or whatever.

  4. Related to previous point. It would be nice to be able to "freeze" a specific development in a stale branch so that it is always accessible in the future, for comparison purposes, etc... And maybe keep master updated, but keep, for instance, a branch with june2020's state in a branch, froze.

@ftadel
Copy link
Member

ftadel commented Mar 25, 2020

I understand from the code, and from this message, you shared a few weeks ago (previous paragraph). That every time something is pushed to the repo, a copy of the binaries and only the binaries is saved in neuroimage server, from where bst users will then download the actual apps.

No. When something is pushed to the bst-duneuro repo, it calls a packaging script that clones and zips the ENTIRE repository and makes it available on the Brainstorm download page:
https://neuroimage.usc.edu/bst/download.php

When Brainstorm needs to get bst-duneuro, it gets from there, with a different PHP script but reading the same .zip file:
https://github.com/brainstorm-tools/brainstorm3/blob/master/toolbox/process/functions/process_generate_fem.m#L1355

  1. Users will download all 3 binaries, regardless of their OS?

Once zipped, each of this binary executable is ~2Mb... I think it's ok to download 4Mb extra for the other OS. I didn't think these 4Mb were a good reason to get to the trouble of generating 3 different packages.

  1. I see the version number is right now the date of the last push. OK. Why not let the users download directly from github? Why add the extra layer of downloading a version from github to neuroimage and then users access this copy instead of the binaries in github?

Automatic installation from Brainstorm, which is not possible otherwise without having git installed on the system. Possibility to disconnect the "released package" from what is happening on the git repo, if we need it (and we will, because we will generate a package that includes only a part of the repo, excluding the dev folder).

  1. How are different versions and developments allowed once we follow this scheme?

None, for the general user.
But you have the bst-duneuro folder available in your Matlab path, Brainstorm will not bother you, so you're free to do whatever your want.
But for the general public, it will be managed fully automatically.

Related to previous point. It would be nice to be able to "freeze" a specific development in a stale branch so that it is always accessible in the future, for comparison purposes, etc... And maybe keep master updated, but keep, for instance, a branch with june2020's state in a branch, froze.

Sure.
This is up to the developers (you and @tmedani) to decide when you want to make snapshots of "stable" versions. You can use the "release" feature of github as well.

@juangpc
Copy link
Contributor

juangpc commented Mar 25, 2020

Automatic installation from Brainstorm, which is not possible otherwise without having git installed on the system.

I'm not understanding you. You only need an internet connection and use urlread/webread/websave to download a file. You do not need git installed. And the disconnection from what is happening in the git repo is done by fixing a hash value in the actual url. But, anyhow, if this is how you want it to work, that is just fine too. Thanks for the explanation anyway.

Regarding the /dev folder. I could create a /dev folder and mv inside /config and /test. But, during compilation, also /src and /build are created. It is ok to change it but it can spend a day testing it. Would it make sense to you, just delete the /config and the / test folders, instead of the /dev in your php script, before zipping the clone?

If your answer is no. You want a /dev folder. Could you guys push your changes so that I can create it, avoiding merge conflicts?

@ftadel
Copy link
Member

ftadel commented Mar 26, 2020

Yes, we could leave everything the way it is now if simpler for you, but it is not very intuitive to understand what is the "brainstorm plugin" (matlab scripts + compiled binaries) and what is "your development environment" (everything else). These are two different subprojects of this repository.
I'm not thinking only about our own current organization (we know what we're doing), but about any new person who would take over the project in a few years from now. Projects well organized are easier to maintain :)

But ok to avoid any additional work for you.
I could do the following: I move the required .m files (panel_duneuro.m, generate_conductivity_tensor.m) from the root to /matlab and when creating my brainstorm plugin package, I zip only /matlab and /bin. I would ignore any additional todo list or notes you have as text files in the root at the moment.

Does this work for both of you?

@juangpc
Copy link
Contributor

juangpc commented Mar 26, 2020

Yes, this works. Thank you very much.
I've added some of these details to the readme file. A bit wordy, but, following your concerns, if we or some new team member wants to work on this, she should now be able to figure things out easier.

@ftadel
Copy link
Member

ftadel commented Mar 26, 2020

@tmedani Ok for you as well?
What is the status of the .m files in the root of the repository?

@tmedani
Copy link
Member Author

tmedani commented Mar 26, 2020

@ftadel , yes agree,

there some some nonuseful functions on root.
let me clean the folder before you start working on it,
I will do it today (in a few hours).

@ftadel
Copy link
Member

ftadel commented Mar 27, 2020

FYI: I modified the packaging script (which is called when something is pushed to the bst-duneuro repo), so that it zips two subfolders only: /bin and /matlab. Everything else is just ignored.

The "brainstorm plugin" which is downloaded automatically by Brainstorm when needed (also available at the bottom of the download page: https://neuroimage.usc.edu/bst/download.php) is now only 9Mb, instead of 120Mb before.

@juangpc
Copy link
Contributor

juangpc commented Mar 27, 2020

Thanks!

@juangpc
Copy link
Contributor

juangpc commented Apr 3, 2020

Hi @tmedani and @ftadel ,
Hope you and your families are not directly affected.
Few things:

  • Just figured out that we actually don't need the duneuro-matlab any more. Just the duneuro module would be enough.
  • And also now that my fluency with c++ is increasing, I think that all the physical flux related functions could start to work.
  • The simbiosphere related solutions would also be accessible to brainstorm.

Now the catch... I would need my Linux box which is at my desk, where I'm not supposed to go... I can remote desktop but it is a bit laggy. The linux is actually virtual machine, so it would imply to remote to a windows and then into a virtualized linux... a bit of a pain to code that way. So. Do you think this is needed, or maybe it is not a priority?

@ftadel
Copy link
Member

ftadel commented Apr 3, 2020

Just figured out that we actually don't need the duneuro-matlab any more. Just the duneuro module would be enough.

What do you mean? Nothing in the /matlab folder is actually needed to compute a FEM forward model with duneuro?

Do you think this is needed, or maybe it is not a priority?

I'm not sure what it entails. Maybe this is more a question for @tmedani?

@juangpc
Copy link
Contributor

juangpc commented Apr 3, 2020

Nothing in the /matlab folder is actually needed to compute a FEM forward model with duneuro?

No, sorry for the confusion. This might be a bit into the details, but here it is... Dune is the linux only project that we are using for fem. Actually a sub-project of that one called DuNeuro. This subproject can run in two different ways now: as a c++ application and as a mex file to be used within matlab api... with a catch... it only works for matlab's linux version... This last one, the matlab version is the one we're using to build our non-matlab exe file. Why? ... you might ask. Because it didn't work otherwise... But now I think I know how to make it work. That was my message.

@tmedani
Copy link
Member Author

tmedani commented Apr 3, 2020

Hey,

@ftadel this is related to the hidden nightmare of the compilation.

@juangpc this is great ... I know that it's possible but never manage to do it...
how do you do it ? is it related to changes on the cmakelist of the duneuro modules?

Then, with this, it would be better to avoid to clone the matlab module and move all the brainstorm_app from duneuro_matlab to duneuro module?

we can also keep an option that creates the mex file ... for advanced users who want to use Linux
does it make sense?

Let's discuss it ... when you can.

@juangpc
Copy link
Contributor

juangpc commented Apr 3, 2020

yes. modifying some paths. and the cmake tool.

we can also keep an option that creates the mex file ... for advanced users who want to use Linux
does it make sense?

Given this repo is for brainstorm use... I would say that it is better to stay away of the mex api. However, if you guys want to duplicate the fem functionality for the case of linux based brainstorm users, the function would end up being very similar, although there would be no need to read the resulting binary file... because matlab would have access to the memory assigned to duneuro.

@tmedani
Copy link
Member Author

tmedani commented Apr 3, 2020

great ... let have a look ... later

However, if you guys want to duplicate the fem functionality for the case of linux based brainstorm users, the function would end up being very similar, although there would be no need to read the resulting binary file... because matlab would have access to the memory assigned to duneuro.

no need to change all the process, it could be faster ... but how much?
it needs more investigation and more work...
also the user needs to compile the duneruo for its self... maybe useful for developers

however, changing the brainstorm_app folder to duneruo_module could be nice.

@juangpc
Copy link
Contributor

juangpc commented Apr 3, 2020 via email

@ftadel
Copy link
Member

ftadel commented Apr 22, 2020

@juangpc FYI: I tested the compilation of the bst-duneuro binaries following your instructions in the README on Windows10 and WSL/Ubuntu18 and both worked at the first attempt! Nice

@juangpc
Copy link
Contributor

juangpc commented Apr 22, 2020

😅

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

3 participants