Comments (5)
Hi @racinmat ,
I am sorry but I don't understand your problem... :(
Please provide the error message.
The title of your message says that produce_or_load
doesn't work with anonymous functions. I assume that what you mean is that you cannot save an anonymous function. Another problem could be that if the function f
that is an argument to produce_or_load
is an anonymous function, then produce_or_load
doesn't work. To be clear, which of the two is the problem you have?
DrWatson does not do any saving. All save
commands call FileIo
. Maybe it already has a backend which saves via serialization?
from drwatson.jl.
With suffix="jld"
you can at least save a function to the result file. BSON which is the default can't do that. However, this is not reflected in the savename, as Function
is not considered to be a valid type for generation.
Something like this:
using DrWatson
function g(conf)
# Compute something
Dict(:y=>conf[:f](conf[:x]),:f=>conf[:f])
end
file = produce_or_load(
"data",
Dict(:x=>-13,:f=>x->x^2),
g,
suffix="jld")
Alternatively you could map your functions to a Symbol
maybe:
using DrWatson
const my_functions = Dict(
:square => x->x^2,
:times2 => x->2*x)
function g(conf)
# Compute something
Dict(:y=>my_functions[conf[:f]](conf[:x]))
end
file = produce_or_load(
"data",
Dict(:x=>-13,:f=>:square),
g,
suffix="jld")
from drwatson.jl.
@Datseris yes, I want to save an anonymous function.
Yes, it's the backend, the FileIO.
@sebastianpech oh, thanks, I didn't know I can use the jld extension.
Unfortunately the code snipped you provided did not work for me either, causing
Warning: Could not save file, got error ErrorException("Keys must be strings (the names of variables), got y").
but when I used @strdict(model, edge_descriptor)
instead of @dict(model, edge_descriptor)
the code started working, and with "jld" extension and @strdict
macro it works.
Maybe the documentation should state this behaviour, because nowhere in documentation of DrWatson I found any information about suffixes (or the need to use strdict).
from drwatson.jl.
The need to use strdict
doesn't come from DrWatson, please check the error stack traces. It comes from JLD which demands that all dictionaries have string type as key.
Information about suffixes is found in savename
: https://juliadynamics.github.io/DrWatson.jl/dev/name/#DrWatson.savename
while produce_or_load
states that it uses savename
(and thus one should look there).
Where else do you think this should be mentioned? Please keep in mind that it is not DrWatson's duty to inform you about every package hooked to FileIO. The responsibility to know what savetypes e.g. the package JLD needs is yours, since it is impossible for us to be informed for all hundreds of packages that FileIO can use... You are welcome to make a Pull Request to the documentation and clarify this in a place you see fit.
from drwatson.jl.
from drwatson.jl.
Related Issues (20)
- DOCS: make example project CamelCase instead of it having space in its name HOT 2
- Allow `dict_list` to return other types than dictionaries
- GitReference should be LibGit2.GitReference HOT 1
- Use a project name without a space in the examples in the documentation HOT 3
- Dev docukentation build seems to not update
- ERROR: Package DrWatson errored during testing HOT 3
- ERROR: LoadError: Some tests did not pass: 354 passed, 11 failed, 9 errored, 0 broken.
- [DISCUSSION] Using DrWatson for Non-Simulation Based Projects HOT 2
- Pristine initialize_project provides Warning and subsequent quickactivate does not work HOT 2
- Is there a way to leave a project? HOT 2
- v2.12.2 breaks compatibility of produce_or_load() and datadir() HOT 2
- Slashes removed in #380 HOT 2
- `rinclude` argument in `collect_results` finds matches in the absolute path
- tag with git commit message HOT 4
- "verbose &&" before @info "Scanning folder $folder for result files." HOT 2
- `savename` with Unitful `Quantity`s HOT 3
- produce_or_load doubles filename prefixes HOT 5
- collect_results handles .jld2 with groups incorrectly HOT 4
- Make a project to be a module by default HOT 2
- Move to Julia 1.9, use extensions remove Requires for `collect_results` and Dataframes
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from drwatson.jl.