populse / mia_processes

The default processes repository for mia
Other
1 stars 2 forks source link

bricks.stat.spm.EstimateModel writes the pyscript.m file to populse_mia package #52

Closed servoz closed 9 months ago

servoz commented 10 months ago

For now, I have no idea of the exact cause of the issue and where it comes from (mia_processes, populse_mia, capsul, nipype, etc.)?. I'm opening this ticket in mia_processes but maybe it concerns another package ...

The mia_processes.bricks.stat.spm.EstimateModel brick writes the pyscript.m file to the root of the populse_mia package. It seems that only this brick of mia_processes produces this bug.

It's a pollution we can't accept (we don't have to write in the site-packages!!!!).

I've already spent several hours trying to figure out what's wrong, but I haven't yet managed to understand exactly what's going wrong...

servoz commented 9 months ago

The script is saved in the directory where populse_mia is launched (main.py or _main.py), exactly here, when process.spm_mat_file is defined (due to the capsul sync_process_output_traits() call back). I have the feeling that something is sub-optimal between capsul and nipype in some cases ... I still haven't managed to work out what and how ...!

servoz commented 9 months ago

Is this ticket linked with the one in capsul?

I'm beginning to understand what's going on ... maybe it will be possible to fix 2 tickets in one go ...? I'll make a summary ASAP.

denisri commented 9 months ago

Yes it's linked, sure ! The problem is that nipype writes this file in the current working directory, and this is not what we normally do in capsul and populse_mia. A possible solution would be to run nipype interfaces in a temp directory (as I think we already do for SPM outputs wrapping), this can be handled in the nipype wrapper.

servoz commented 9 months ago

Yes, you're right, we're already running nipype interfaces in a temporary directory, but the problem is that nipype makes system calls with (or without writing) pyscript files in some cases, during the module initialisation steps and at this stage we haven't yet changed the current directory to a temporary one.

I've spent some time trying to understand what's going on between populse and nipype (which has given me a better understanding of the machinery involved in running a process!) and it seems to me that we could perhaps simply change the current directory to a temporary directory just before running the process in capsul.process.process.Process.run_from_commandline(), then return to the initial current directory after execution? It's simple (and therefore generally robust!) and can be effective in all (or many) cases. Maybe I've forgotten something, a side effect?

I make a PR with a proposal along these lines, and that'll get us started for discussion if needed. From my point of view, it fix the populse/mia_processes#52 ticket.

servoz commented 9 months ago

Fixed.

servoz commented 9 months ago

I'm reopening this ticket because I just see again a pyscript generated with the CVR pipeline ... just to keep in mind, I take again this ASAP ticket ... Arggghh ...