How to prevent Chaste from overwriting output folder

+1 vote
70 views
asked Oct 23, 2017 by J-H Plank (440 points)
retagged Oct 23, 2017 by J-H Plank

Dear all,

while using the Heart component of Chaste I find it quite annoying, that the simulations
overwrite the output folder by default. I'd prefer a new output folder
would be created if the given one already exists, i.e. by adding an
integer to the original folder name. Is something like that already
implemented?

Thanks in advance for any answers!

Jan-Hendrik

Remark: This question was already asked to the mailing list (20.10.2017 "Some questions concerning using Chaste Heart")

commented Oct 23, 2017 by GaryM (940 points)

Hi, are you using the cardiac executable, or the source code?

commented Oct 23, 2017 by J-H Plank (440 points)

I'm using the Source Code.

2 Answers

+1 vote
answered Oct 23, 2017 by fcooper (390 points)

‚ÄčThere is no mechanism specifically for doing this, as far as I know. Your best bet would be to add a unique string to the output directory. One way of doing this neatly would be to ‚Äčappend the wall time to the directory name. Chaste has a Timer class which could be used as follows:

#include "Timer.hpp"
...
Timer timer;
std::string dir_name = "your/directory/name" + std::to_string(timer.GetWallTime());

(You could of course std::lround(timer.GetWallTime()) to get an integer if you didn't want a decimal point in your directory name.)

As you say, this is often related to performing parameter sweeps when you want to run multiple simulations (see this question), where it is often easy and convenient to add an integer ID to directory names.

commented Oct 23, 2017 by GaryM (940 points)

Yep, if doing a parameter sweep you could add the parameters directly (or their indices in a vector etc.) to the file/foldername too.

+1 vote
answered Oct 30, 2017 by J-H Plank (440 points)

Dear all,

I now wrote some code myself, that does the trick for me.

#include <cstdlib>
...    
int filecounter = 1;
std::string dir_name = "Output/Directory" + std::to_string(filecounter);                   //set the output Directory
std::string full_path = std::string(std::getenv("CHASTE_TEST_OUTPUT")) + "/" + dir_name;   //get the full path to be able to check wether this already exists
while (boost::filesystem::exists( full_path ))                                             //use a boost library to check
{
    filecounter = filecounter + 1;                                                         //if this output directory already exist increase the filecounter by one
    dir_name = "CreateRandomChaos/Try" + std::to_string(filecounter);                      //update dir_name and full_path
    full_path = std::string(std::getenv("CHASTE_TEST_OUTPUT")) + "/" + dir_name;
}

Are there any pitfalls doing it like this that I am not aware of?

commented Oct 30, 2017 by GaryM (940 points)

Only pitfall I can think of is the use of "/" if you may want platform-independent code (windows/linux). If you have a look at the FileFinder class it can do the existence check for you and paths relative to testoutput etc.

But if you just want this to run on your own machine / linux machines, then that looks fine to me.

commented Oct 30, 2017 by J-H Plank (440 points)

Good point! I didn't think about that. But since I'm using Linux anyway this is not a problem for me.

Welcome to Chaste Q&A, where you can ask questions and receive answers from other members of the community of Chaste developers and users.

See the Chaste wiki for installation instructions, guides and tutorials.

...