Skip to content

Commit 912ad7e

Browse files
authored
Merge pull request #100 from Juice-jl/compressed-io
Support for `read` and `write` of circuits to *.gz compressed files
2 parents a6d61b1 + 4c1f95f commit 912ad7e

File tree

8 files changed

+60
-11
lines changed

8 files changed

+60
-11
lines changed

.github/workflows/slow_tests.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@ name: Slow Tests
33
# Controls when the action will run. Triggers the workflow on push or pull request
44
# events but only for the master branch
55
on:
6-
pull_request:
7-
branches:
8-
master
6+
# tests are not being maintained so don't run on pull requests
7+
# pull_request:
8+
# branches:
9+
# master
910

1011
schedule:
1112
- cron: '0 0 */7 * *'
@@ -26,14 +27,13 @@ jobs:
2627
- uses: actions/checkout@v2
2728
- uses: julia-actions/setup-julia@latest
2829
with:
29-
version: 1.5
30+
version: 1.6
3031

3132
# Runs a single command using the runners shell
3233
- name: Unit Tests
3334
run: |
3435
julia --project=test -e 'using Pkg; Pkg.instantiate(); Pkg.build(); Pkg.precompile();'
3536
julia --project=test -e 'using Pkg; Pkg.develop("ProbabilisticCircuits");'
36-
julia --project=test --check-bounds=yes --depwarn=yes test/_manual_/aqua_test.jl
3737
julia --project=test --check-bounds=yes --depwarn=yes test/_manual_/strudel_marginal_tests.jl
3838
julia --project=test --check-bounds=yes --depwarn=yes test/_manual_/strudel_likelihood_tests.jl
3939
julia --project=test --check-bounds=yes --depwarn=yes test/_manual_/ensembles_tests.jl

Project.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "ProbabilisticCircuits"
22
uuid = "2396afbe-23d7-11ea-1e05-f1aa98e17a44"
33
authors = ["Guy Van den Broeck <guyvdb@cs.ucla.edu>"]
4-
version = "0.3.1"
4+
version = "0.3.2"
55

66
[deps]
77
CUDA = "052768ef-5323-5732-b1bb-66c8b64840ba"
@@ -38,11 +38,11 @@ CUDA = "3"
3838
Clustering = "0.14"
3939
DataFrames = "1.2"
4040
DataStructures = "0.17, 0.18"
41+
DirectedAcyclicGraphs = "0.1.2"
4142
Distributions = "0.25"
42-
DirectedAcyclicGraphs = "0.1.1"
4343
Graphs = "1.4"
4444
Lerche = "0.5"
45-
LogicCircuits = "0.3.1"
45+
LogicCircuits = "0.3.2"
4646
LoopVectorization = "0.11, 0.12"
4747
MetaGraphs = "0.7"
4848
Metis = "1.0"

src/io/io.jl

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,12 @@ include("plot.jl")
1414
# if no logic circuit file format is given on read, infer file format from extension
1515

1616
function file2pcformat(file)
17-
if endswith(file,".jpc")
17+
if endswith(file,".gz")
18+
# duplicate code from `LogicCircuits.file2logicformat` -- not sure how to make this nicer
19+
file_inner, _ = splitext(file)
20+
format_inner = file2pcformat(file_inner)
21+
GzipFormat(format_inner)
22+
elseif endswith(file,".jpc")
1823
JpcFormat()
1924
elseif endswith(file,".psdd")
2025
PsddFormat()
@@ -64,6 +69,10 @@ Base.parse(::Type{ProbCircuit}, args...) =
6469
Base.read(io::IO, ::Type{ProbCircuit}, args...) =
6570
read(io, PlainProbCircuit, args...)
6671

72+
Base.read(io::IO, ::Type{ProbCircuit}, f::GzipFormat) =
73+
# avoid method ambiguity
74+
read(io, PlainProbCircuit, f)
75+
6776
# copy read/write API for tuples of files
6877

6978
function Base.read(files::Tuple{AbstractString, AbstractString}, ::Type{C}, args...) where C <: StructProbCircuit
@@ -81,4 +90,4 @@ function Base.write(files::Tuple{AbstractString,AbstractString},
8190
write((io1, io2), circuit, args...)
8291
end
8392
end
84-
end
93+
end

src/io/spn_io.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
export zoo_spn, zoo_spn_file,
2-
SpnFormat, SpnVtreeFormat
2+
SpnFormat
33

44
struct SpnFormat <: FileFormat end
55

test/io/jpc_io_test.jl

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,23 @@ include("../helper/pc_equals.jl")
6060
test_my_circuit(pc3)
6161
test_pc_equals(pc1, pc3)
6262
@test vtree(pc1) == vtree(pc3)
63+
64+
# read/write compressed
65+
write("$jpc_path.gz", pc1)
66+
pc2 = read("$jpc_path.gz", ProbCircuit)
67+
68+
test_my_circuit(pc2)
69+
test_pc_equals(pc1, pc2)
70+
71+
# read/write compressed structured
72+
paths = ("$jpc_path.gz", vtree_path)
73+
write(paths, pc1)
74+
pc3 = read(paths, StructProbCircuit)
75+
76+
@test pc3 isa StructProbCircuit
77+
test_my_circuit(pc3)
78+
test_pc_equals(pc1, pc3)
79+
@test vtree(pc1) == vtree(pc3)
6380

6481
end
6582

test/io/psdd_io_test.jl

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,22 @@ include("../helper/pc_equals.jl")
7070
@test vtree(pc1) == vtree(pc3)
7171
test_pc_equals(pc0, pc3)
7272

73+
# read/write compressed
74+
write("$psdd_path.gz", pc1)
75+
pc2 = read("$psdd_path.gz", ProbCircuit)
76+
77+
test_my_circuit(pc2)
78+
test_pc_equals(pc1, pc2)
79+
80+
# read/write compressed structured
81+
paths = ("$psdd_path.gz", vtree_path)
82+
write(paths, pc1)
83+
pc3 = read(paths, StructProbCircuit)
84+
85+
@test pc3 isa StructProbCircuit
86+
test_my_circuit(pc3)
87+
test_pc_equals(pc1, pc3)
88+
@test vtree(pc1) == vtree(pc3)
7389
end
7490

7591
end

test/io/spn_io_test.jl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,13 @@ include("../helper/pc_equals.jl")
4444
test_my_circuit(pc2)
4545
test_pc_equals(pc1, pc2)
4646

47+
# try compressed
48+
write("$spn_path.gz", pc1)
49+
pc2 = read("$spn_path.gz", ProbCircuit)
50+
51+
test_my_circuit(pc2)
52+
test_pc_equals(pc1, pc2)
53+
4754
end
4855

4956
end

0 commit comments

Comments
 (0)