simulation-alg 0.1.7__tar.gz → 0.1.9__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {simulation_alg-0.1.7 → simulation_alg-0.1.9}/Cargo.lock +5 -5
- {simulation_alg-0.1.7 → simulation_alg-0.1.9}/Cargo.toml +2 -2
- {simulation_alg-0.1.7 → simulation_alg-0.1.9}/PKG-INFO +1 -1
- {simulation_alg-0.1.7 → simulation_alg-0.1.9}/pyproject.toml +1 -1
- {simulation_alg-0.1.7 → simulation_alg-0.1.9}/simulation.pyi +20 -1
- {simulation_alg-0.1.7 → simulation_alg-0.1.9}/src/graph/hypergraph.rs +47 -5
- {simulation_alg-0.1.7 → simulation_alg-0.1.9}/src/lib.rs +4 -0
- simulation_alg-0.1.9/test.py +57 -0
- {simulation_alg-0.1.7 → simulation_alg-0.1.9}/.github/workflows/ci.yml +0 -0
- {simulation_alg-0.1.7 → simulation_alg-0.1.9}/.gitignore +0 -0
- {simulation_alg-0.1.7 → simulation_alg-0.1.9}/.gitmodules +0 -0
- {simulation_alg-0.1.7 → simulation_alg-0.1.9}/LICENSE +0 -0
- {simulation_alg-0.1.7 → simulation_alg-0.1.9}/README.md +0 -0
- {simulation_alg-0.1.7 → simulation_alg-0.1.9}/hyper-simulation.log +0 -0
- {simulation_alg-0.1.7 → simulation_alg-0.1.9}/python/__init__.py +0 -0
- {simulation_alg-0.1.7 → simulation_alg-0.1.9}/requirements.txt +0 -0
- {simulation_alg-0.1.7 → simulation_alg-0.1.9}/src/graph/mod.rs +0 -0
- {simulation_alg-0.1.7 → simulation_alg-0.1.9}/src/graph/networkx_graph.rs +0 -0
- {simulation_alg-0.1.7 → simulation_alg-0.1.9}/src/utils.rs +0 -0
- {simulation_alg-0.1.7 → simulation_alg-0.1.9}/tests/test_hyper_simulation.py +0 -0
- {simulation_alg-0.1.7 → simulation_alg-0.1.9}/tests/test_simulation.py +0 -0
|
@@ -177,9 +177,9 @@ dependencies = [
|
|
|
177
177
|
|
|
178
178
|
[[package]]
|
|
179
179
|
name = "graph-base"
|
|
180
|
-
version = "0.1.
|
|
180
|
+
version = "0.1.14"
|
|
181
181
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
182
|
-
checksum = "
|
|
182
|
+
checksum = "1c337eeba84f9bf9bd65f89631119a34215bf46251e751abc1a6819195d71287"
|
|
183
183
|
dependencies = [
|
|
184
184
|
"lazy_static",
|
|
185
185
|
"rand",
|
|
@@ -188,9 +188,9 @@ dependencies = [
|
|
|
188
188
|
|
|
189
189
|
[[package]]
|
|
190
190
|
name = "graph-simulation"
|
|
191
|
-
version = "0.1.
|
|
191
|
+
version = "0.1.24"
|
|
192
192
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
193
|
-
checksum = "
|
|
193
|
+
checksum = "3744a0d1d724cad58fef5eee7383bcdc3cd318952f4611ca9f3916fe0bf01e46"
|
|
194
194
|
dependencies = [
|
|
195
195
|
"bincode",
|
|
196
196
|
"env_logger",
|
|
@@ -543,7 +543,7 @@ dependencies = [
|
|
|
543
543
|
|
|
544
544
|
[[package]]
|
|
545
545
|
name = "simulation"
|
|
546
|
-
version = "0.1.
|
|
546
|
+
version = "0.1.8"
|
|
547
547
|
dependencies = [
|
|
548
548
|
"graph-base",
|
|
549
549
|
"graph-simulation",
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[package]
|
|
2
2
|
name = "simulation"
|
|
3
|
-
version = "0.1.
|
|
3
|
+
version = "0.1.8"
|
|
4
4
|
edition = "2021"
|
|
5
5
|
license = "MIT"
|
|
6
6
|
description = "A Python package for simulation algorithms"
|
|
@@ -14,7 +14,7 @@ crate-type = ["cdylib"]
|
|
|
14
14
|
|
|
15
15
|
[dependencies]
|
|
16
16
|
pyo3 = { version = "0.27.1", features = ["extension-module"] }
|
|
17
|
-
graph-simulation = "0.1.
|
|
17
|
+
graph-simulation = "0.1.24"
|
|
18
18
|
graph-base = "0.1.13"
|
|
19
19
|
rayon = "1.10.0"
|
|
20
20
|
# [tool.maturin]
|
|
@@ -49,7 +49,17 @@ class Hyperedge:
|
|
|
49
49
|
def id_set(self) -> set[int]: ...
|
|
50
50
|
def desc(self) -> str: ...
|
|
51
51
|
|
|
52
|
+
class Event:
|
|
53
|
+
"""
|
|
54
|
+
Event class.
|
|
55
|
+
"""
|
|
56
|
+
phrase: str
|
|
57
|
+
sc_id: int
|
|
58
|
+
binary_relation: set[tuple[int, int]]
|
|
59
|
+
|
|
60
|
+
def __init__(self, phrase: str, sc_id: int, binary_relation: set[tuple[int, int]]): ...
|
|
52
61
|
|
|
62
|
+
# (cluster_u, cluster_v)
|
|
53
63
|
class DMatch:
|
|
54
64
|
"""
|
|
55
65
|
D-Match for hyper simulation
|
|
@@ -62,13 +72,16 @@ class DMatch:
|
|
|
62
72
|
For a sematic cluster pair by `id`, we set map[(id, id)] = R as the relation, where (u_id, v_id) in R, are node's id.
|
|
63
73
|
"""
|
|
64
74
|
|
|
65
|
-
class Delta:
|
|
75
|
+
class Delta: # Delta(u, v)
|
|
66
76
|
def __init__(self) -> None: ...
|
|
67
77
|
def add_sematic_cluster_pair(self, u: Node, v: Node, cluster_u: list[Hyperedge], cluster_v: list[Hyperedge]) -> int: ...
|
|
68
78
|
"""
|
|
69
79
|
Add a sematic of (u, v), register a id of the pair that, (cluster_u, id) and (cluster_v, id)
|
|
70
80
|
"""
|
|
71
81
|
|
|
82
|
+
# (u, v) (cluster_u, cluster_v)
|
|
83
|
+
# (u', v')
|
|
84
|
+
|
|
72
85
|
class Hypergraph:
|
|
73
86
|
"""
|
|
74
87
|
Hypergraph class.
|
|
@@ -88,6 +101,11 @@ class Hypergraph:
|
|
|
88
101
|
|
|
89
102
|
def get_node_desc_by_id(self, node_id: int) -> Optional[str]: ...
|
|
90
103
|
|
|
104
|
+
def get_hyper_simulation_trace(self) -> list[Event]:
|
|
105
|
+
"""
|
|
106
|
+
Get trace events of last time hyper simulation.
|
|
107
|
+
"""
|
|
108
|
+
|
|
91
109
|
@staticmethod
|
|
92
110
|
def hyper_simulation(query: 'Hypergraph', data: 'Hypergraph', l_match_fn: Callable[[Hyperedge, Hyperedge], dict[int, set[int]]]) -> dict[int, set[int]]:
|
|
93
111
|
"""
|
|
@@ -105,3 +123,4 @@ class Hypergraph:
|
|
|
105
123
|
"""
|
|
106
124
|
Hyper Simulation
|
|
107
125
|
"""
|
|
126
|
+
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
use std::{collections::{HashMap, HashSet}, fmt::Display, hash::Hash};
|
|
2
2
|
|
|
3
3
|
use pyo3::{prelude::*, types::PyList};
|
|
4
|
-
use graph_simulation::algorithm::hyper_simulation::{DMatch, Delta, HyperSimulation, LMatch, LPredicate, SematicCluster};
|
|
4
|
+
use graph_simulation::{algorithm::hyper_simulation::{DMatch, Delta, HSEvent, HyperSimulation, HyperSimulationTrace, LMatch, LPredicate, SematicCluster}, utils::logger::TraceLog};
|
|
5
5
|
use graph_base::interfaces::{edge, graph::{self, SingleId}, hypergraph::{self, ContainedHyperedge}, typed, vertex};
|
|
6
|
+
|
|
6
7
|
// use graph_base::interfaces::hypergraph;
|
|
7
8
|
|
|
8
9
|
#[derive(Clone, Debug, Eq)]
|
|
@@ -86,6 +87,25 @@ pub struct Hypergraph {
|
|
|
86
87
|
l_predicate_fn: Option<Py<PyAny>>, // (Hyperedge, Hyperedge) -> bool
|
|
87
88
|
}
|
|
88
89
|
|
|
90
|
+
#[pyclass(name = "Event")]
|
|
91
|
+
pub struct Event {
|
|
92
|
+
pub phrase: String,
|
|
93
|
+
pub sc_id: usize,
|
|
94
|
+
pub binary_relation: HashSet<(usize, usize)>
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
#[pymethods]
|
|
98
|
+
impl Event {
|
|
99
|
+
#[new]
|
|
100
|
+
pub fn new(phrase: String, sc_id: usize, binary_relation: HashSet<(usize, usize)>) -> Self {
|
|
101
|
+
Event {
|
|
102
|
+
phrase,
|
|
103
|
+
sc_id,
|
|
104
|
+
binary_relation,
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
89
109
|
#[pymethods]
|
|
90
110
|
impl Hypergraph {
|
|
91
111
|
#[new]
|
|
@@ -153,6 +173,25 @@ impl Hypergraph {
|
|
|
153
173
|
.map(|(k, v)| (k.id(), v.into_iter().map(|n| n.id()).collect()))
|
|
154
174
|
.collect()
|
|
155
175
|
}
|
|
176
|
+
|
|
177
|
+
pub fn get_hyper_simulation_trace(&self) -> Vec<Event> {
|
|
178
|
+
let trace = HyperSimulationTrace::get_trace("hyper_simulation.trace").unwrap();
|
|
179
|
+
let events = trace.into_iter().map(|event| {
|
|
180
|
+
match event {
|
|
181
|
+
HSEvent::Base(sc_id, relation) => Event {
|
|
182
|
+
phrase: "base".to_string(),
|
|
183
|
+
sc_id,
|
|
184
|
+
binary_relation: relation
|
|
185
|
+
},
|
|
186
|
+
HSEvent::Derivation(sc_id, relation) => Event {
|
|
187
|
+
phrase: "derivation".to_string(),
|
|
188
|
+
sc_id,
|
|
189
|
+
binary_relation: relation
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
}).collect();
|
|
193
|
+
events
|
|
194
|
+
}
|
|
156
195
|
}
|
|
157
196
|
|
|
158
197
|
impl Display for Node {
|
|
@@ -381,9 +420,8 @@ impl DMatchImpl {
|
|
|
381
420
|
}
|
|
382
421
|
}
|
|
383
422
|
|
|
384
|
-
// #[pyclass(name = "Delta")]
|
|
385
423
|
struct DeltaImpl<'a> {
|
|
386
|
-
sematic_cluster: HashMap<(&'a Node, &'a Node), Vec<(SematicCluster<'a, Hyperedge>, SematicCluster<'a, Hyperedge>)
|
|
424
|
+
sematic_cluster: HashMap<(&'a Node, &'a Node), Vec<(SematicCluster<'a, Hyperedge>, SematicCluster<'a, Hyperedge>)>>,
|
|
387
425
|
}
|
|
388
426
|
|
|
389
427
|
impl<'a> Delta<'a> for DeltaImpl<'a> {
|
|
@@ -414,12 +452,16 @@ impl<'a> DeltaImpl<'a> {
|
|
|
414
452
|
|
|
415
453
|
let sc_q = SematicCluster::new(q_id, q_edges);
|
|
416
454
|
let sc_d = SematicCluster::new(d_id, d_edges);
|
|
455
|
+
// Update sematic_cluster_cache
|
|
417
456
|
|
|
457
|
+
// sematic_cluster_cache.insert((&sc_q, &sc_d), q_id);
|
|
458
|
+
|
|
418
459
|
pair_map.entry((u, v)).or_default().push((sc_q, sc_d));
|
|
419
460
|
}
|
|
420
461
|
}
|
|
462
|
+
|
|
421
463
|
let res = DeltaImpl {
|
|
422
|
-
sematic_cluster: pair_map
|
|
464
|
+
sematic_cluster: pair_map,
|
|
423
465
|
};
|
|
424
466
|
|
|
425
467
|
return res;
|
|
@@ -431,7 +473,7 @@ impl<'a> DeltaImpl<'a> {
|
|
|
431
473
|
#[derive(Clone)]
|
|
432
474
|
#[pyclass(name = "Delta")]
|
|
433
475
|
pub struct DeltaPy {
|
|
434
|
-
sematic_cluster_cache: HashMap<(usize, usize), Vec<((Vec<usize>, usize), (Vec<usize>, usize))>>,
|
|
476
|
+
sematic_cluster_cache: HashMap<(usize, usize), Vec<((Vec<usize>, usize), (Vec<usize>, usize))>>, // (u_id, v_id) -> Vec<((q_edge_ids, sc_id), (d_edge_ids, sc_id))>
|
|
435
477
|
global_cnt: usize
|
|
436
478
|
}
|
|
437
479
|
|
|
@@ -11,6 +11,10 @@ fn simulation(m: &Bound<'_, PyModule>) -> PyResult<()> {
|
|
|
11
11
|
m.add_class::<graph::hypergraph::Node>()?;
|
|
12
12
|
m.add_class::<graph::hypergraph::Hyperedge>()?;
|
|
13
13
|
m.add_class::<graph::hypergraph::LMatchImpl>()?;
|
|
14
|
+
m.add_class::<graph::hypergraph::DeltaPy>()?;
|
|
15
|
+
m.add_class::<graph::hypergraph::DMatchImpl>()?;
|
|
16
|
+
m.add_class::<graph::hypergraph::Event>()?;
|
|
17
|
+
|
|
14
18
|
m.add_function(wrap_pyfunction!(graph::networkx_graph::get_simulation_inter, m)?)?;
|
|
15
19
|
m.add_function(wrap_pyfunction!(graph::networkx_graph::get_simulation_inter_fn, m)?)?;
|
|
16
20
|
m.add_function(wrap_pyfunction!(graph::networkx_graph::is_simulation_isomorphic, m)?)?;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import simulation
|
|
2
|
+
|
|
3
|
+
from simulation import *
|
|
4
|
+
query = Hypergraph()
|
|
5
|
+
query.add_node("a") # id 0
|
|
6
|
+
query.add_node("b") # id 1
|
|
7
|
+
query.add_node("c") # id 2
|
|
8
|
+
query.add_hyperedge(Hyperedge({0, 1}, "e1", 0))
|
|
9
|
+
query.add_hyperedge(Hyperedge({1, 2}, "e2", 1))
|
|
10
|
+
query.add_hyperedge(Hyperedge({0, 2}, "e3", 2))
|
|
11
|
+
|
|
12
|
+
data = Hypergraph()
|
|
13
|
+
data.add_node("a")
|
|
14
|
+
data.add_node("b")
|
|
15
|
+
data.add_node("c")
|
|
16
|
+
data.add_hyperedge(Hyperedge({0, 1}, "e1", 0))
|
|
17
|
+
data.add_hyperedge(Hyperedge({1, 2}, "e2", 1))
|
|
18
|
+
data.add_hyperedge(Hyperedge({0, 2}, "e3", 2))
|
|
19
|
+
|
|
20
|
+
# register type_same
|
|
21
|
+
|
|
22
|
+
query_vertices = []
|
|
23
|
+
data_vertices = []
|
|
24
|
+
|
|
25
|
+
m1= {}
|
|
26
|
+
|
|
27
|
+
for u in query_vertices:
|
|
28
|
+
for v in data_vertices:
|
|
29
|
+
# nli,
|
|
30
|
+
m1[u, v] = True
|
|
31
|
+
|
|
32
|
+
query.set_type_same_fn(lambda x_id, y_id: m1[x_id, y_id])
|
|
33
|
+
|
|
34
|
+
delta = Delta()
|
|
35
|
+
|
|
36
|
+
likely_vertices = []
|
|
37
|
+
m2 = {}
|
|
38
|
+
|
|
39
|
+
for (u, v) in likely_vertices:
|
|
40
|
+
pairs = []
|
|
41
|
+
for pair in pairs:
|
|
42
|
+
delta.add_sematic_cluster_pair(u, v, pair[0], pair[1])
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
matches = {}
|
|
48
|
+
for (u, v), pair in m2.items():
|
|
49
|
+
matches[u, v] = [(1, 2)]
|
|
50
|
+
|
|
51
|
+
d_match = DMatch.from_dict(matches)
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
sim = Hypergraph.get_hyper_simulation(query, data, delta, d_match)
|
|
56
|
+
|
|
57
|
+
# set[tuple[int, int]]
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|