Skip to content

Commit 01b9fd3

Browse files
authored
Merge pull request #60 from JetBrains-Research/dev
Patch 1.0.1
2 parents ca24cf9 + be9fc3e commit 01b9fd3

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+751
-242
lines changed

cfpq_data/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
experimental analysis of context-free path querying algorithms
88
"""
99

10-
__version__ = "1.0.0"
10+
__version__ = "1.0.1"
1111

1212
import cfpq_data.config
1313
from cfpq_data.config import *

cfpq_data/grammars/readwrite/rsm.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def rsm_from_text(source: str, start_symbol: Variable = Variable("S")) -> RSM:
5252
boxes = list()
5353

5454
for production in source.splitlines():
55-
if not production:
55+
if " -> " not in production:
5656
continue
5757

5858
head, body = production.split(" -> ")

cfpq_data/grammars/rsm.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ def to_text(self) -> str:
7171
productions = [f"{box[0]} -> {box[1].to_regex()}" for box in self.boxes]
7272
return "\n".join(productions)
7373

74-
def to_cfg(self):
74+
def to_cfg(self) -> CFG:
7575
"""Create a context-free grammar [1]_
7676
from Recursive State Machine [2]_.
7777

cfpq_data/graphs/generators/fast_labeled_binomial_graph.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import numpy as np
99
from networkx import MultiDiGraph, fast_gnp_random_graph
1010
from numpy.random import RandomState
11+
from tqdm import tqdm
1112

1213
__all__ = ["fast_labeled_binomial_graph"]
1314

@@ -17,6 +18,7 @@ def fast_labeled_binomial_graph(
1718
edge_probability: float,
1819
seed: Union[int, RandomState, None] = None,
1920
edge_labels: Iterable[str] = "a",
21+
verbose: bool = True,
2022
) -> MultiDiGraph:
2123
"""Returns a $G_{n,p}$ random graph,
2224
also known as an Erdős-Rényi graph or
@@ -38,12 +40,17 @@ def fast_labeled_binomial_graph(
3840
edge_labels: Iterable[str]
3941
Labels that will be used to mark the edges of the graph.
4042
43+
verbose : bool
44+
If true, a progress bar will be displayed.
45+
4146
Examples
4247
--------
4348
>>> import cfpq_data
44-
>>> g = cfpq_data.fast_labeled_binomial_graph(42, 0.42, seed=42)
45-
>>> g.number_of_nodes(), g.number_of_edges()
46-
(42, 722)
49+
>>> g = cfpq_data.fast_labeled_binomial_graph(42, 0.42, seed=42, verbose=False)
50+
>>> g.number_of_nodes()
51+
42
52+
>>> g.number_of_edges()
53+
722
4754
4855
Returns
4956
-------
@@ -78,7 +85,7 @@ def fast_labeled_binomial_graph(
7885
random.seed(seed)
7986
np.random.seed(seed)
8087

81-
for edge in g.edges:
88+
for edge in tqdm(g.edges, disable=not verbose, desc="Generation..."):
8289
g.edges[edge]["label"] = np.random.choice(list(edge_labels))
8390

8491
return g

cfpq_data/graphs/generators/labeled_barabasi_albert_graph.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import numpy as np
1212
from networkx import MultiDiGraph, barabasi_albert_graph
1313
from numpy.random import RandomState
14+
from tqdm import tqdm
1415

1516
__all__ = ["labeled_barabasi_albert_graph"]
1617

@@ -20,6 +21,7 @@ def labeled_barabasi_albert_graph(
2021
number_of_edges: int,
2122
seed: Union[int, RandomState, None] = None,
2223
edge_labels: Iterable[str] = "abcd",
24+
verbose: bool = True,
2325
) -> MultiDiGraph:
2426
"""Returns a random graph according
2527
to the Barabási–Albert preferential attachment model
@@ -42,12 +44,17 @@ def labeled_barabasi_albert_graph(
4244
edge_labels: Iterable[str]
4345
Labels that will be used to mark the edges of the graph.
4446
47+
verbose : bool
48+
If true, a progress bar will be displayed.
49+
4550
Examples
4651
--------
4752
>>> import cfpq_data
48-
>>> g = cfpq_data.labeled_barabasi_albert_graph(42, 29, 42)
49-
>>> g.number_of_nodes(), g.number_of_edges()
50-
(42, 754)
53+
>>> g = cfpq_data.labeled_barabasi_albert_graph(42, 29, 42, verbose=False)
54+
>>> g.number_of_nodes()
55+
42
56+
>>> g.number_of_edges()
57+
754
5158
5259
Returns
5360
-------
@@ -73,7 +80,7 @@ def labeled_barabasi_albert_graph(
7380
random.seed(seed)
7481
np.random.seed(seed)
7582

76-
for edge in g.edges:
83+
for edge in tqdm(g.edges, disable=not verbose, desc="Generation..."):
7784
label = np.random.choice(list(edge_labels))
7885
g.edges[edge]["label"] = label
7986

cfpq_data/graphs/generators/labeled_binomial_graph.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import numpy as np
99
from networkx import MultiDiGraph, gnp_random_graph
1010
from numpy.random import RandomState
11+
from tqdm import tqdm
1112

1213
__all__ = ["labeled_binomial_graph"]
1314

@@ -17,6 +18,7 @@ def labeled_binomial_graph(
1718
edge_probability: float,
1819
seed: Union[int, RandomState, None] = None,
1920
edge_labels: Iterable[str] = "a",
21+
verbose: bool = True,
2022
) -> MultiDiGraph:
2123
"""Returns a $G_{n,p}$ random graph,
2224
also known as an Erdős-Rényi graph or
@@ -38,12 +40,17 @@ def labeled_binomial_graph(
3840
edge_labels: Iterable[str]
3941
Labels that will be used to mark the edges of the graph.
4042
43+
verbose : bool
44+
If true, a progress bar will be displayed.
45+
4146
Examples
4247
--------
4348
>>> import cfpq_data
44-
>>> g = cfpq_data.labeled_binomial_graph(42, 0.84, seed=42)
45-
>>> g.number_of_nodes(), g.number_of_edges()
46-
(42, 1453)
49+
>>> g = cfpq_data.labeled_binomial_graph(42, 0.84, seed=42, verbose=False)
50+
>>> g.number_of_nodes()
51+
42
52+
>>> g.number_of_edges()
53+
1453
4754
4855
Returns
4956
-------
@@ -70,7 +77,7 @@ def labeled_binomial_graph(
7077
random.seed(seed)
7178
np.random.seed(seed)
7279

73-
for edge in g.edges:
80+
for edge in tqdm(g.edges, disable=not verbose, desc="Generation..."):
7481
g.edges[edge]["label"] = np.random.choice(list(edge_labels))
7582

7683
return g

cfpq_data/graphs/generators/labeled_cycle_graph.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,15 @@
77
from typing import Union, Iterable, Any
88

99
from networkx import MultiDiGraph, cycle_graph
10+
from tqdm import tqdm
1011

1112
__all__ = ["labeled_cycle_graph"]
1213

1314

1415
def labeled_cycle_graph(
15-
number_of_nodes: Union[int, Iterable[Any]], edge_label: str = "a"
16+
number_of_nodes: Union[int, Iterable[Any]],
17+
edge_label: str = "a",
18+
verbose: bool = True,
1619
) -> MultiDiGraph:
1720
"""Returns a cycle graph $C_n$
1821
of cyclically connected nodes.
@@ -29,12 +32,17 @@ def labeled_cycle_graph(
2932
edge_label: str
3033
Label that will be used to mark the edges of the graph.
3134
35+
verbose : bool
36+
If true, a progress bar will be displayed.
37+
3238
Examples
3339
--------
3440
>>> import cfpq_data
35-
>>> g = cfpq_data.labeled_cycle_graph(42)
36-
>>> g.number_of_nodes(), g.number_of_edges()
37-
(42, 42)
41+
>>> g = cfpq_data.labeled_cycle_graph(42, verbose=False)
42+
>>> g.number_of_nodes()
43+
42
44+
>>> g.number_of_edges()
45+
42
3846
3947
Returns
4048
-------
@@ -43,7 +51,7 @@ def labeled_cycle_graph(
4351
"""
4452
g = cycle_graph(n=number_of_nodes, create_using=MultiDiGraph)
4553

46-
for edge in g.edges:
54+
for edge in tqdm(g.edges, disable=not verbose, desc="Generation..."):
4755
g.edges[edge]["label"] = edge_label
4856

4957
return g

cfpq_data/graphs/generators/labeled_scale_free_graph.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import numpy as np
88
from networkx import MultiDiGraph, scale_free_graph
99
from numpy.random import RandomState
10+
from tqdm import tqdm
1011

1112
__all__ = ["labeled_scale_free_graph"]
1213

@@ -20,6 +21,7 @@ def labeled_scale_free_graph(
2021
delta_out: float = 0,
2122
seed: Union[int, RandomState, None] = None,
2223
edge_labels: Iterable[str] = "abcd",
24+
verbose: bool = True,
2325
) -> MultiDiGraph:
2426
"""Returns a scale-free directed graph.
2527
With labeled edges.
@@ -55,12 +57,17 @@ def labeled_scale_free_graph(
5557
edge_labels: Iterable[str]
5658
Labels that will be used to mark the edges of the graph.
5759
60+
verbose : bool
61+
If true, a progress bar will be displayed.
62+
5863
Examples
5964
--------
6065
>>> import cfpq_data
61-
>>> g = cfpq_data.labeled_scale_free_graph(42, seed=42)
62-
>>> g.number_of_nodes(), g.number_of_edges()
63-
(42, 88)
66+
>>> g = cfpq_data.labeled_scale_free_graph(42, seed=42, verbose=False)
67+
>>> g.number_of_nodes()
68+
42
69+
>>> g.number_of_edges()
70+
88
6471
6572
Returns
6673
-------
@@ -93,7 +100,7 @@ def labeled_scale_free_graph(
93100
random.seed(seed)
94101
np.random.seed(seed)
95102

96-
for edge in g.edges:
103+
for edge in tqdm(g.edges, disable=not verbose, desc="Generation..."):
97104
label = np.random.choice(list(edge_labels))
98105
g.edges[edge]["label"] = label
99106

cfpq_data/graphs/generators/labeled_two_cycles_graph.py

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from typing import Union, Iterable, Any, Tuple
55

66
from networkx import MultiDiGraph, compose, path_graph
7+
from tqdm import tqdm
78

89
__all__ = ["labeled_two_cycles_graph"]
910

@@ -13,6 +14,7 @@ def labeled_two_cycles_graph(
1314
m: Union[int, Iterable[Any]],
1415
common: Union[int, Any] = 0,
1516
edge_labels: Tuple[str, str] = ("a", "b"),
17+
verbose: bool = True,
1618
) -> MultiDiGraph:
1719
"""Returns a graph with two cycles connected by one node.
1820
With labeled edges.
@@ -35,12 +37,17 @@ def labeled_two_cycles_graph(
3537
edge_labels: Tuple[str, str]
3638
Labels that will be used to mark the edges of the graph.
3739
40+
verbose : bool
41+
If true, a progress bar will be displayed.
42+
3843
Examples
3944
--------
4045
>>> import cfpq_data
41-
>>> g = cfpq_data.labeled_two_cycles_graph(42, 29)
42-
>>> g.number_of_nodes(), g.number_of_edges()
43-
(72, 73)
46+
>>> g = cfpq_data.labeled_two_cycles_graph(42, 29, verbose=False)
47+
>>> g.number_of_nodes()
48+
72
49+
>>> g.number_of_edges()
50+
73
4451
4552
Returns
4653
-------
@@ -67,10 +74,14 @@ def labeled_two_cycles_graph(
6774
tmp.add_edge(common, first_node)
6875
tmp.add_edge(last_node, common)
6976

70-
for edge in g1.edges:
77+
for edge in tqdm(
78+
g1.edges, disable=not verbose, desc="Generation of the first cycle..."
79+
):
7180
g1.edges[edge]["label"] = edge_labels[0]
7281

73-
for edge in g2.edges:
82+
for edge in tqdm(
83+
g2.edges, disable=not verbose, desc="Generation of the second cycle..."
84+
):
7485
g2.edges[edge]["label"] = edge_labels[1]
7586

7687
g = MultiDiGraph(compose(g1, g2))

0 commit comments

Comments
 (0)