TensorBFS / TensorInference.jl

Probabilistic inference using contraction of tensor networks
https://tensorbfs.github.io/TensorInference.jl/
MIT License
18 stars 2 forks source link

refactor uai reading #51

Closed GiggleLiu closed 1 year ago

GiggleLiu commented 1 year ago

julia> problem = dataset["PR"]["Pedigree"][11] ArtifactProblemSpec("/home/leo/.julia/artifacts/199ed43697fe22447c6c64a939b222fd4073f2d0", "PR", "Pedigree", 11)

julia> read_instance(problem);

julia> read_evidence(problem) Dict{Int64, Int64} with 37 entries: 305 => 2 52 => 0 72 => 0 180 => 1 17 => 0 37 => 0 256 => 1 ⋮ => ⋮

julia> read_queryvars(problem) ERROR: SystemError: opening file "/home/leo/.julia/artifacts/199ed43697fe22447c6c64a939b222fd4073f2d0/PR/Pedigree_11.uai.query": No such file or directory Stacktrace: ...



* Changed `TensorNetworkModel` and `MMAPModel` constructors to fit the changes. Variables are more explicitly set.
codecov[bot] commented 1 year ago

Codecov Report

Merging #51 (dae58ad) into main (79797ea) will increase coverage by 0.51%. The diff coverage is 83.33%.

@@            Coverage Diff             @@
##             main      #51      +/-   ##
==========================================
+ Coverage   81.07%   81.59%   +0.51%     
==========================================
  Files           9        9              
  Lines         502      489      -13     
==========================================
- Hits          407      399       -8     
+ Misses         95       90       -5     
Impacted Files Coverage Δ
src/TensorInference.jl 100.00% <ø> (+25.00%) :arrow_up:
src/Core.jl 46.29% <23.52%> (-7.23%) :arrow_down:
src/mmap.jl 71.18% <86.66%> (ø)
src/map.jl 100.00% <100.00%> (ø)
src/mar.jl 94.64% <100.00%> (ø)
src/sampling.jl 98.75% <100.00%> (ø)
src/utils.jl 89.68% <100.00%> (+0.42%) :arrow_up:
GiggleLiu commented 1 year ago

@mroavi Please be aware of the upcoming incompatible changes. I have bumped the version to 0.2.

GiggleLiu commented 1 year ago

Fixed.

  1. read_instance_from_file -> read_model_file.
  2. Making terms consistent,
    1. model is a UAIModel instance.
    2. problem is an ArtifactProblemSpec instance.
mroavi commented 1 year ago

Today I came up with an idea. Let me know what you think:

We could have one method called load (or extend read) that can be used to read any kind of file (model, evid, or query). It would take one path (AbstractString) as an argument. That function would have some logic that calls the proper read function based on the extension of the given path. However, if the path points to a directory instead of a file, then the function tries to read all files (model, evid, and query) in that dir. So if the extension of the given argument is .uai then we read the model, if it is .evid we read the evidence file, etc. If we receive a path to a directory, then we try to read all three files from that dir and return nothing for the files that did not exist in that dir.

This would mean that the user would use load (or read if you prefer) for everything, which simplifies the user experience. Let me know what you think.

mroavi commented 1 year ago

After thinking about this a bit more, it might be better to skip my previous idea for now since we might want to support other file formats in the future, and this decision might make that more difficult.