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
Decouple produce_or_load
and savename
#322
Comments
TL;DR: Yes for adding a If I understood everything, you want to turn if !isfile(filename)
data = f(config)
save(filename)
end This is a tremendously simple code snippet. It is only 4 lines of code. I am surprised that such a simple codesnippet would require you to present such a complicated modification to a function which I would say is already complicated. I'm trying to understand your approach: why do you want to make so fundamental modifications to functions when the solution is so simple? Change how the path works, change how the filename works, or having even more complicated ways to set things path like this Nevertheless, the argument that "I don't want to use In the end of the day, we save a string generated by |
So you're more or less okay with option 1, which is implemented in #323?
Well, no, I still want all the other stuff in
Everything except the automatic
The modification wouldn't be that complicated: a4d3c63, and a lot of that is error handling/warnings, which could be handled differently, see below.
I agree with that 100%!
I took care of the default value of the suffix (by using the extension of But I wasn't sure
makes sense. It produces an error in my current patch. I'd be okay with the above producing a file
right now produces a warning that How do you want to handle
Should it ignore So if you prefer, I can use the new |
You need to make a fundamental distinction here. if !isfile(filename)
@info "producing $filename # this is your logging. 1 extra line.
data = f(config)
@tagsave(filename, data)
end and now I'm almost sure you get what you asked for.
You don't.
That was the original suggestion, yes. Just replace the call to Actually, good design can make it so you don't have to even replace the I'm convinced that what I suggested here is a clear improvement for |
Yes, that works perfectly and does exactly what I want. The one tiny caveat is the
Indeed, that would be my preference as well
I agree! :-) |
Rationale
There are two situations where it could be nice to circumvent the internal use of
savename
inproduce_or_load
and to directly pass it a full file name:If the filename is already used in the script before the call to
produce_or_load
with an explicit call tosavename
, it can make the code slightly cleaner to pass that existing filename toproduce_or_load
. It would also eliminate the possibility of bugs due to any inconsistency between the two calls.If for some reason a project does not want to interpolate the key-value pairs from
config
into the output filename, e.g., if there are two many parameters (see Workflow for managing multiple output files, or files with too many parameters, and metadata #316), it might be difficult to "fight" the internalsavename
to give the desired filename.Implementation
In #315 (comment), I proposed implementing an alternative method for
produce_or_load
. However, on further reflection that was an overly complicated solution. The "problem" is only a single line of code inproduce_or_load
,DrWatson.jl/src/saving_files.jl
Line 54 in 4a92f3e
So it seems easiest to slightly tweak the routine, maybe add a parameter to modify just that line.
I would consider the following possibilities:
Add a
filename=nothing
keyword argument toproduce_or_load
The above line would simply turn into
Thus, if
filename
is given as a string, it will serve as the output filename directly.Advantages:
filename
being the return value (including the full path)Problems:
path=""
suffix
: suffix should be set to the file extension offilename
prefix
andkwargs...
. If these are non-emtpy, a warning should be printed, maybe even anerror
.Allow
path
to include the filename directly. Whetherpath
is a folder or a filename is determined by whether it has an extension.Advantages:
produce_or_load
Problems:
path
is rather subtle. Users might find this kind of implicit behavior confusing.suffix
: suffix should be set to the file extension ofpath
prefix
andkwargs...
. If these are non-emtpy, a warning should be printed.Add a new
auto_filename=true
(or some other name, maybeuse_savename
, not sure). Usepath
as the full filename ifauto_filename=false
Advantages:
Problems:
path
to change meaning depending onauto_filename
suffix
: suffix should be set to the file extension ofpath
prefix
andkwargs...
. If these are non-emtpy, a warning should be printed.The above are in order of my preference (number 1 being my most preferred solution).
The text was updated successfully, but these errors were encountered: