diff --git a/bench/recursive_animation.py b/bench/recursive_animation.py new file mode 100644 index 00000000..475466a7 --- /dev/null +++ b/bench/recursive_animation.py @@ -0,0 +1,329 @@ +import matplotlib.pyplot as plt, cmasher as cmr +import numpy as np, os, sys, networkx as nx, warnings +from plexsim import models +from imi import infcy +from plexsim.utils.rules import create_rule_full +warnings.simplefilter("ignore"); plt.style.use("fivethirtyeight spooky".split()) +from imi.utils.graph import ConnectedSimpleGraphs +from plexsim.utils.annealing import annealing +import time + +def check_doubles(path, results): + add = True + if path: + for r in results[0]: + if all([i in r for i in path]) or all([i[::-1] in r for i in path]): + add = False + break + if add and path: + results[0].append(path.copy()) + +def merge(results, n): + # attempt to merge branches + merged = [] + # go through all the combinations in the options + for idx, opti in enumerate(results[1]): + for jdx, optj in enumerate(results[1]): + # prevent self-comparison and double comparison + if idx < jdx: + # compare matched edges + idxs, vpi = opti + jdxs, vpj = optj + # if the overlap is zero then the branches are valid + # and should be merged + J = True + a = vpi + b = vpj + if len(vpi) > len(vpj): + a, b = b,a + for i in a: + # if the rule edge already exists + # ignore the option + if i in b or i[::-1] in b: + J = False + # add if no overlap is found + if J: + # merging + print(f"Merging {vpi} with {vpj}") + proposal = [idxs.copy(), vpi.copy()] + for x, y in zip(jdxs, vpj): + proposal[0].append(x) + proposal[1].append(y) + # copy + else: + # print('copying') + proposal = [idxs.copy(), vpi.copy()] + # check if its done + if len(proposal) == n: + # prevent double results + check_doubles(proposal, results) + # keep original branch + else: + merged.append(proposal) + # print(f"in merge and adding {merged} {results[1]}") + if merged: + results[1] = merged + +def check_endpoint(s, vp_path) -> bool: + # update paths + fail = True + for ss in m.rules.neighbors(s): + if m.rules[s][ss]['weight'] > 0: + if [s, ss] not in vp_path: + fail = False + # print(f"Failing {fail} {s} {list(m.rules.neighbors(s))} {vp_path}") + return fail + +def check_df(queue, n, m, path = [], vp_path = [], results = [], all_paths = [[], []], + verbose = True): + # print("Returning") + # for plotting ignore + if queue: + # get current node + from_node, current = queue.pop() + node = m.adj.rmapping[current] + results[1] = [] + s = m.states[current] + # check only if difference + if current != from_node: + path.append([current, from_node]) + vp_path.append([m.states[current], m.states[from_node]]) + if path: + all_paths[0].append(path.copy()) + + # logging + if verbose: + print(f"At {current}") + print(f"Path : {path}") + print(f"Vp_path : {vp_path}") + print(f"Options: {results[1]}") + print(f"Results: {results[0]}") + + + # check if no options left in rule graph + if check_endpoint(s, vp_path): + if verbose: + print("At an end point") + option = [[[from_node, current]], [[m.states[from_node], m.states[current]]]] + results[1].append(option) + return results + + # check neighbors + for neigh in m.graph.neighbors(node): + other = m.adj.mapping[neigh] + ss = m.states[other] + # prevent going back + if other == from_node: + if verbose: print("found node already in path (cycle)") + continue + # check if branch is valid + if m.rules[s][ss]['weight'] <= 0: + if verbose: print('negative weight') + continue + # construct proposals + e = [current, other] + ev = [s, ss] + + # step into branch + if e not in path and e[::-1] not in path: + if ev not in vp_path and ev[::-1] not in vp_path: + if verbose: + print(f"checking {e} at {current} with {other} at path {path}") + queue.append(e) + o = check_df(queue, n, m, path.copy(), vp_path.copy(), results.copy(), all_paths, verbose) + for r in o[1]: + results[1].append(r.copy()) + print(f"branch results {o}") + # move to next + else: + continue + # move to next + else: + continue + # attempt merge + merge(results, n) + # TODO self edges are ignore + if from_node != current: + this_option = [[from_node, current], + [m.states[from_node], m.states[current]]] + for idx, merged in enumerate(results[1]): + if verbose: + print(f"merging {merged}") + # they cannot be in the already present path + if this_option[1] not in merged[1] and this_option[1][::-1] not in merged[1]: + print(f"This option {this_option} with merge {merged}") + print(this_option[1] in merged[1]) + print(this_option[1][::-1] in merged[1]) + merged[0].append(this_option[0]) + merged[1].append(this_option[1]) + if len(merged[1]) == n: + # remove from option list + results[1].pop(idx) + check_doubles(merged[0].copy(), results) + check_doubles(merged[0].copy(), all_paths) + print(f'adding results {merged[0]} {n} vp = {merged[1]}') + # print(f"path {path} {vp_path}") + # terminate if number of edges is reached + if len(vp_path) == n: + check_doubles(path.copy(), results) + check_doubles(path.copy(), all_paths) + if verbose: print('added path', results) + return results + +# setup graph +r = nx.Graph() +r.add_edge(0, 1) +r.add_edge(1, 2) +r.add_edge(2, 3) +r.add_edge(0, 3) + + +# r.add_edge(1, 2) +# r.add_edge(1, 3) +# r.add_edge(3, 5) + +r = create_rule_full(r, self_weight=-1) + +# edge target +target = 0 +for k, v in nx.get_edge_attributes(r, 'weight').items(): + if v > 0: + target += 1 +print(f"TARGET {target}") + +g = nx.krackhardt_kite_graph() +#g = nx.cycle_graph(3) +s = np.arange(len(r)) + +m = models.ValueNetwork(g, r, agentStates = s, bounded_rational = 3) +# anneal the state +print("annealing") +m.states = annealing(m, theta = 1e-5, rate = 1e-4, reset = True) + + +#m.states = [1, 2, 0, 1] +print("assignment", m.states) +# setup all paths +all_paths = [[], []] +# get the results +start = [0] +start = [(0, 0)] +results, options = check_df(start, target, m, + path=[], vp_path=[], results=[[], []], + all_paths=all_paths, verbose = True) +print(len(results), len(all_paths[0])) +print("ALL_PATHS", len(all_paths[0])) +print("RESULTS", results) +print(len(results)) +print('done') +print(all_paths) +from plexsim.utils.visualisation import GraphAnimation +tmp = GraphAnimation(g, m.states.reshape(-1, 1).T, len(r)) +fig, ax = plt.subplots() +tmp.setup(ax = ax, rules = r, layout = nx.kamada_kawai_layout(g)) +fig.show() +fig.savefig("/home/casper/test.png") + + +# init figure +cmap = cmr.pride +p_colors = np.linspace(0, 1, len(results), 0) +c_ = np.linspace(0, 1, s.size, 0) +c = cmap(c_[m.states.astype(int)]) +fig, ax = plt.subplots(constrained_layout = 1, figsize = (10, 8)) +pos = nx.kamada_kawai_layout(g) +nx.draw(g, pos, ax = ax, node_color = c) +nx.draw_networkx_labels(g, pos, ax = ax, + font_color = 'white') +fig.show() + +R = np.arange(len(results)) +layout = np.zeros((len(results), 2), dtype = object) +layout[:] = -1 +layout[:, -1] = R + +fig = plt.figure(constrained_layout = 1, figsize = (10, 8)) +axes = fig.subplot_mosaic(layout.T) +for axi in axes.values(): + axi.axis('off') +ax = axes[-1] + +pos = nx.kamada_kawai_layout(g) +nx.draw(g, pos, ax = ax, node_color = c) +nx.draw_networkx_labels(g, pos, ax = ax, + font_color = 'white') +inax = ax.inset_axes((0, .2, .3, .3)) +inax.axis('equal') +inax.set_title("Target") +C = np.linspace(0, 1, len(r), 0) +C = cmap(C) +sg = [k for k, v in nx.get_edge_attributes(r, 'weight').items() if v > 0] +sg = nx.from_edgelist(sg) + +pos = nx.kamada_kawai_layout(sg) +nx.draw(sg, pos, ax = inax, node_color = C) +inax.margins(.5) + + +completed_colors = {} +completed_c = 0 +ignore = set() +for idx, r in enumerate(results): + print(r) +def update(idx): + cpath = all_paths[0][idx] + ecs = [] + edges = ax.collections[1] + # reset all edges to black + ECS = {k: 'lightgray' for k in g.edges()} + + for e in cpath: + e = tuple(e) + if e in ECS: + ECS[e] = 'red' + else: + ECS[e[::-1]] = 'red' + edges.set_colors(ECS.values()) + add = False + if len(cpath) == target: + if cpath in results: + add = True + + # add only new paths in results + if add: + # make mapping and add color + tmp = tuple((tuple(i) for i in cpath)) + completed_colors[tmp] = completed_colors.get(tmp, len(completed_colors)) + cidx = completed_colors[tmp] + # add new color + if cidx not in ignore: + ignore.add(cidx) + axi = axes.get(cidx) + jdx = [] + for e in cpath: + for ei in e: + if ei not in jdx: + jdx.append(ei) + sg = nx.from_edgelist(cpath) + pos = nx.kamada_kawai_layout(sg) + nx.draw(sg, pos, ax = axi, node_size = 80, + node_color = c[jdx]) + nx.draw_networkx_labels(sg, pos, ax = axi, + font_color = 'white') + axi.axis('equal') + axi.margins(.1) + ax.set_title(f"T = {idx}") + # return ax.collections + +ax.axis('equal') +from matplotlib import animation +N = int(len(all_paths[0]) * 4) +print(f"using {N} frames") +#N = 4 + +f = np.linspace(0, len(all_paths[0]), N, 0).astype(int) +ani = animation.FuncAnimation(fig, update, frames = f) +ani.save("/home/casper/crawling.mp4", + savefig_kwargs = dict(facecolor = 'gray'), + ) +fig.show() diff --git a/bench/test_conway.py b/bench/test_conway.py new file mode 100644 index 00000000..3bc87da9 --- /dev/null +++ b/bench/test_conway.py @@ -0,0 +1,48 @@ +from plexsim.models import Conway +import matplotlib.pyplot as plt, cmasher as cmr +import numpy as np, os, sys, networkx as nx, warnings +from plexsim import models +from imi import infcy + +warnings.simplefilter("ignore") +plt.style.use("fivethirtyeight spooky".split()) + +n = 65 + +g = nx.grid_graph((n, n), periodic=True) + +# for node in g.nodes(): +# for i in range(-1, 2): +# for j in range(-1, 2): +# x, y = node +# new = ((x + i) % n, (y + j) % n) +# if g.has_node(new): +# if not g.has_edge(node, new): +# g.add_edge(new, node) + +m = Conway(g) +# m.states = 0 +# m.states[:4] = 1 +# S = np.arange(10) +# m = models.Potts(g, agentStates=S) +fig, ax = plt.subplots() +from plexsim.utils.visualisation import GraphAnimation + +s = {0: {"states": m.states.reshape(1, -1)}} + +s = m.states.reshape(1, -1) +ga = GraphAnimation(m.graph, s, m.nStates + 1) +pos = {i: eval(i) for i in m.graph.nodes()} +ga.setup(ax, layout=pos, node_kwargs=dict(node_size=64)) +h = ax.collections[0] +print(h.set_color) + +# m.states = 0 +# m.states[:4] = 1 + +while True: + # s = m.updateState(m.sampleNodes(1)[0]).base + m.simulate(2) + c = ga.colors(m.states.astype(int)) + h.set_color(c) + plt.pause(1e-16) diff --git a/bench/test_particular.py b/bench/test_particular.py new file mode 100644 index 00000000..110741d3 --- /dev/null +++ b/bench/test_particular.py @@ -0,0 +1,30 @@ +import matplotlib.pyplot as plt, cmasher as cmr +import numpy as np, os, sys, networkx as nx, warnings +from plexsim import models +from plexsim.utils.rules import create_rule_full +from plexsim.models import ValueNetwork + +warnings.simplefilter("ignore") +plt.style.use("fivethirtyeight spooky".split()) + +graph = nx.star_graph(4) +graph.add_edge(1, 2) +r = create_rule_full(graph, self_weight=-1) +S = np.arange(len(r)) +m = ValueNetwork(graph, rules=r, agentStates=S) + +for node in range(m.nNodes): + m.states[node] = S[node] +print(m.states) +target = [[0, 0]] +paths, options = m.check_df(target, path=[], vp_path=[], results=[[], []], verbose=True) + +opts = {} +for option in options: + option = tuple((tuple(i) for i in option[0])) + opts[option] = opts.get(option, 0) + 1 +print(len(options)) +for k, v in opts.items(): + if v > 1: + print(k, v) + # print(k, v) diff --git a/bench/test_sandpile.py b/bench/test_sandpile.py new file mode 100644 index 00000000..b3bd4eb4 --- /dev/null +++ b/bench/test_sandpile.py @@ -0,0 +1,28 @@ +import matplotlib.pyplot as plt, cmasher as cmr +import numpy as np, os, sys, networkx as nx, warnings +from plexsim import models +from imi import infcy + +warnings.simplefilter("ignore") +plt.style.use("fivethirtyeight spooky".split()) + +from plexsim.models.sandpile import Sandpile + +m = Sandpile(sampleSize=1) +m.states = 0 + +output = np.zeros(m.nNodes) +z = 10 +for i in range(z): + r = m.sampleNodes(1) + r[0] = 0 + print(r.base) + m.updateState(r[0]) + output += m.states / z + print(m.states) + +fig, ax = plt.subplots() +h = ax.imshow(output.reshape(10, 10)) +fig.colorbar(h) +fig.show() +plt.show(block=True) diff --git a/bench/test_triangle.py b/bench/test_triangle.py new file mode 100644 index 00000000..8fc83378 --- /dev/null +++ b/bench/test_triangle.py @@ -0,0 +1,120 @@ +from plexsim.models.value_network import ValueNetwork +import matplotlib.pyplot as plt, cmasher as cmr +import numpy as np, os, sys, networkx as nx, warnings +from plexsim import models +from imi import infcy + +warnings.simplefilter("ignore") +plt.style.use("fivethirtyeight spooky".split()) +from test_valuenetwork import TestCrawl, visualize_graph +from plexsim.utils.rules import create_rule_full + + +def test_crawl_single(m, target, verbose=False, nodes=None): + if verbose: + print("-" * 32) + print(f"Testing graph of size {len(m.graph)}") + print("-" * 32) + + # time.sleep(1) + crawls = [] + tmp = [] + + # fig, ax = plt.subplots() + # nx.draw(m.graph, ax=ax, with_labels=1) + # fig.show() + # plt.show() + + if nodes: + to_check = ((m.adj.rmapping[node], node) for node in nodes) + else: + to_check = m.adj.mapping.items() + for node_label, node in to_check: + # node = 4 + # node_label = "4" + print(f"Checking {node=}") + crawl = m.check_df(node, verbose=verbose) + if verbose: + print(f"Solution: {crawl} {len(crawl)}") + assignment = len(crawl) == target + + if verbose: + print(f"Results ok? {assignment} for node {node} {node_label=}") + for a in crawl: + print(a) + print() + # print(m.states) + # break + + +def test_specific(graph: nx.Graph, nodes: list = None): + r = create_rule_full(graph, self_weight=-1) + S = np.arange(len(r)) + m = ValueNetwork(graph, rules=r, agentStates=S) + print(f"{m.bounded_rational=}") + m.states = S + test_crawl_single(m, target=1, verbose=1, nodes=nodes) + + +g = nx.complete_graph(4) + +# g = nx.path_graph(3) +# g = nx.star_graph(3) +# # g.add_edge(1, 2) + +# g = nx.cycle_graph(3) +# g = nx.path_graph(2) + + +from plexsim.utils.graph import ConnectedSimpleGraphs + +csg = ConnectedSimpleGraphs() + +# g = nx.complete_graph(4) +# g = nx.cycle_graph(3) +# test_specific(g) +# double_y() +# g = csg.rvs(7) + +# g = nx.path_graph(4) +# g.add_edge(1, 10) +# g.add_edge(10, 11) +# +g = nx.star_graph(10) +r = nx.path_graph(3) +A = np.arange(len(r)) +r = create_rule_full(r) +# print(A.shape) +m = ValueNetwork(g, rules=r, agentStates=A) + +# m.states = np.array([*A, *A]) +print(m.states) +fig, ax = plt.subplots() +ax.imshow(m.simulate(100)) +fig.show() +plt.show(block=1) + +# s = {0: 0, 1: 1, 2: 2, 3: 3, 4: 2, 5: 3} +# for k, v in s.items(): +# m.states[k] = v + +# print(m.states.shape) +# print(m.nNodes, m.states) +# visualize_graph(m) + +# # m.reset() +# # print(m.states) + +# plt.show(block=1) +# test_crawl_single(m, target=1, verbose=1) + +# # m.simulate(100) + +# # test_specific(g, nodes=[1]) +# print("-" * 32) +# print(f"{g.number_of_nodes()=}") +# print(f"{g.number_of_edges()=}") +# print("-" * 32) + +# print() +# # double_y() diff --git a/bench/test_vn_soc.py b/bench/test_vn_soc.py new file mode 100644 index 00000000..b28f02f4 --- /dev/null +++ b/bench/test_vn_soc.py @@ -0,0 +1,133 @@ +import matplotlib.pyplot as plt, cmasher as cmr +import numpy as np, os, sys, networkx as nx, warnings +from matplotlib.collections import LineCollection + +# from plexsim import models + +warnings.simplefilter("ignore") +plt.style.use("fivethirtyeight spooky".split()) + + +from plexsim.models.value_network_soc import VNSoc +from plexsim.models.value_network_crystal import VNCrystal + +# from plexsim.utils.visualisation import visualize_graph +from plexsim.utils.rules import create_rule_full + + +def get_graph(g: dict) -> nx.Graph or nx.DiGraph: + output = dict() + for k, v in g.items(): + output[k] = dict() + for kk, vv in v["neighbors"].items(): + output[k][kk] = dict(weight=vv) + return nx.from_dict_of_dicts(output) + + +def get_paths(g: nx.Graph) -> np.ndarray: + global pos + tmp = [] + for x, y in g.edges(): + tmp.append((pos[x], pos[y])) + tmp = np.array(tmp) + return tmp + + +def update(idx: int) -> list: + global colors, lc, pb, pos, labs + ax.relim() + + m.updateState(m.sampleNodes(1)[0]) + + print(m.completed_vns) + + # ci = m.states.astype(int) + # ci = colors[ci] + # scats.set_color(ci) + + g = get_graph(m.adj.adj) + pos = nx.spring_layout(g) + for k, v in pos.items(): + labs[k].set_position(v) + p = np.array([i for i in pos.values()]) + scats.set_offsets(p) + paths = get_paths(g) + lc.set_paths(paths) + ax.set_title(idx) + pb.update() + return [lc, scats] + + +def visualize_graph(m): + import cmasher as cmr + + cmap = cmr.guppy(np.linspace(0, 1, m.nStates, 0)) + colors = [cmap[int(i)] for i in m.states.astype(int)] + g = get_graph(m.adj.adj) + + fig, ax = plt.subplots() + nx.draw(g, ax=ax, with_labels=1, node_color=colors) + fig.show() + + +from matplotlib import animation +import pyprind as pr + +if __name__ == "__main__": + N = 300 + theta = 1 + graph = nx.empty_graph(n=N) + rules = create_rule_full( + nx.cycle_graph(3), + self_weight=-1, + ) + + s = np.arange(len(rules)) + print(s) + + settings = dict( + graph=graph, + rules=rules, + agentStates=s, + heuristic=theta, + ) + m = VNSoc(**settings) + m = VNCrystal(**settings) + + p = [0.9, 0.05, 0.05] + H = np.random.choice(s, size=m.nNodes, p=p) + # H = [*np.ones(10) * 0, *np.ones(10) * 1, *np.ones(10) * 2] + m.states = H + + g = get_graph(m.adj.adj) + pos = nx.circular_layout(g) + p = np.array([i for i in pos.values()]) + + cmap = cmr.guppy(np.linspace(0, 1, m.nStates, 0)) + colors = np.array([cmap[i] for i in m.states.astype(int)]) + + n = 100 + f = np.linspace(0, n, n, dtype=int) + pb = pr.ProgBar(f.size) + fig, ax = plt.subplots() + + labs = nx.draw_networkx_labels(g, pos, ax=ax) + scats = ax.scatter(p[:, 0], p[:, 1], c=colors, s=300) + # plt.show(block=1) + + paths = get_paths(g) + lc = LineCollection(paths, color="lightgray", zorder=0) + ax.add_collection(lc) + # ax.axis("equal") + + ax.axis("off") + fig.show() + z = 0 + update_speed = 1e-16 + while True: + update(z) + z += 1 + plt.pause(update_speed) + + ani = animation.FuncAnimation(fig, update, frames=f) + ani.save("./soc.mp4", fps=30) diff --git a/bench/vis_boid.py b/bench/vis_boid.py new file mode 100644 index 00000000..476af8de --- /dev/null +++ b/bench/vis_boid.py @@ -0,0 +1,213 @@ +import matplotlib.pyplot as plt, cmasher as cmr +import numpy as np, os, sys, networkx as nx, warnings +from plexsim import models +from plexsim.models import ValueNetwork +from plexsim.models import MagneticBoids + +# from imi import infcy +warnings.simplefilter("ignore") +plt.style.use("fivethirtyeight spooky".split()) + +from plexsim.utils.rules import create_rule_full + +r = nx.cycle_graph(3) +# r = nx.cycle_graph(3) +# r.add_edge(3, 0) +# r = nx.union(r, r, "r1", "r2") +# r = nx.path_graph(3) +# r = nx.krackhardt_kite_graph() +repulsion = -1 +br = r.number_of_edges() +r = create_rule_full(r, self_weight=repulsion, connection_weight_other=repulsion) +S = np.arange(len(r)) +n = 30 + + +graph = nx.empty_graph(n) +# m = ValueNetwork(graph = graph) +# m.simulate(2) +# assert 0 +bounds = np.array([0, 30.0]) +settings = dict( + coordinates=np.random.randn(n, 2) * max(bounds), + velocities=np.random.randn(n, 2), + graph=graph, + rules=r, + bounded_rational=br, + agentStates=S, + radius=3, + boid_radius=1.5, + t=1, + max_speed=0.5, + bounds=bounds, + exploration=0.1, + # memorySize=2, + dt=0.1, + H=np.ones(n) * np.inf, + heuristic=1, +) + +m = MagneticBoids(**settings) +# m.states = 0 +print(m.t) + +colors = cmr.pride(np.linspace(0, 1, len(r), 0)) +from matplotlib import animation +from matplotlib.collections import LineCollection +from matplotlib import patches + +theta = 0.1 + + +def update2(idx): + # ax.cla() + ax.relim() + m.updateState(m.sampleNodes(1)[0]) + print(m.velocities) + # print() + ci = m.states.astype(int) + ci = colors[ci] + + # pos = {idx: ci for idx, ci in enumerate(m.coordinates)} + adj = {k: v["neighbors"] for k, v in m.adj.adj.items()} + g = nx.from_dict_of_lists(adj) + tmp = np.array([[m.coordinates[x], m.coordinates[y]] for x, y in g.edges()]) + # lc.set_offsets(tmp) + lc.set_paths(tmp) + scats.set_color(ci) + + boundary = patches.Rectangle( + (m.bounds[0], m.bounds[0]), + m.bounds[1] - m.bounds[0], + m.bounds[1] - m.bounds[0], + facecolor="none", + alpha=0.1, + edgecolor="k", + lw=5, + zorder=1, + ) + # [ax.spines[i].set_visible(True) for i in "left top right bottom".split()] + # ax.add_patch(boundary) + scats.set_offsets(m.coordinates) + scatts_range.set_offsets(m.coordinates) + + # ax.annotate( + # f"t = {idx}", + # (0, 1), + # xycoords="axes fraction", + # va="bottom", + # ha="left", + # zorder=5, + # fontsize=30, + # ) + # ax.set_xlabel("x") + # ax.set_ylabel("y") + # nx.draw(g, pos=pos, ax=ax, node_color=ci, edge_color="lightgray", node_size=7) + # ax.tick_params(left=True, bottom=True, labelleft=True, labelbottom=True) + # ax.set_xlim(min(bounds) * 1 - theta, max(bounds) * (1 + theta)) + # ax.set_ylim(min(bounds) * 1 - theta, max(bounds) * (1 + theta)) + # ax.axis("equal") + # ax.axis("off") + + +# print(m.velocities[0], m.coordinates[0]) +# ax.axis("equal") +# ax.set_title(f"T={tidx}") + +debug = False +# debug = True + +fig, ax = plt.subplots( + 1, + 1, + facecolor="none", + constrained_layout=True, + figsize=(5, 5), + # gridspec_kw=dict(width_ratios=[1, 0.2]), +) +fig.show() + +# ri = [(i, j) for i, j, d in r.edges(data=True) if d["weight"] > 0] +# ri = nx.from_edgelist(ri) +# nx.draw( +# ri, +# pos=nx.kamada_kawai_layout(ri), +# ax=target, +# node_color=colors[np.arange(0, len(r))], +# ) +# +# target.axis("equal") +# target.margins(0.5) +# target.annotate( +# "Target value network", +# xy=(0.5, 0.75), +# xycoords="axes fraction", +# ha="center", +# va="bottom", +# fontsize=32, +# ) + +theta = 0.05 +ci = m.states.astype(int) +ci = colors[ci] +scats = ax.scatter( + *m.coordinates.T, c=ci, zorder=5, s=np.clip(settings["boid_radius"] * 20, 15, 30) +) +scatts_range = ax.scatter( + *m.coordinates.T, + c="none", + zorder=5, + s=np.clip( + settings["radius"] * 40, + 15, + 60, + ), + edgecolor="k", +) +tmp = np.array([[m.coordinates[x], m.coordinates[y]] for x, y in m.graph.edges()]) +lc = LineCollection( + tmp, + color="lightgray", + zorder=1, + alpha=0.7, + # theta1=0.2, + # theta2=0.1 + # connectionstyle="arc3,rad=0.3" +) +ax.add_collection(lc) +ax.set_xlim(min(bounds) * 1 - theta, max(bounds) * (1 + theta)) +ax.set_ylim(min(bounds) * 1 - theta, max(bounds) * (1 + theta)) +# ax.axis("equal") +# ax.set_xlabel("x") +# ax.set_ylabel("y") +ax.axis("off") + +import pyprind as pr + +pb = pr.ProgBar(n) + + +def prog(fn, n): + pb.update() + + +debug = 1 +if debug: + counter = 0 + while True: + counter += 1 + + # if counter == 100: + # fig.savefig("./sample.png") + + plt.pause(1e-2) + update2(counter) +else: + f = np.linspace(0, 100, 200, 0).astype(int) + ani = animation.FuncAnimation( + fig, + update2, + frames=f, + ) + ani.save("./flight_test.webm", fps=30, progress_callback=prog) + fig.show() diff --git a/plexsim.egg-info/PKG-INFO b/plexsim.egg-info/PKG-INFO index f8d8e4cd..1354dafd 100644 --- a/plexsim.egg-info/PKG-INFO +++ b/plexsim.egg-info/PKG-INFO @@ -1,12 +1,13 @@ Metadata-Version: 2.1 Name: plexsim -Version: 2.0 -Summary: UNKNOWN -Home-page: cvanelteren.githubio.io +Version: 3.0 +Summary: Fast general toolbox for simulating complex systems +Home-page: https://github.com/cvanelteren/plexsim Author: Casper van Elteren Author-email: caspervanelteren@gmail.com License: UNKNOWN -Download-URL: https://github.com/cvanelteren/PlexSim/archive/refs/tags/v2.5.tar.gz +Download-URL: https://github.com/cvanelteren/PlexSim/archive/refs/tags/v3.0.tar.gz +Keywords: Complex systems,Agent-based simulations,Statistical Physics Platform: UNKNOWN UNKNOWN diff --git a/plexsim.egg-info/requires.txt b/plexsim.egg-info/requires.txt index eea7a80b..d448d88c 100644 --- a/plexsim.egg-info/requires.txt +++ b/plexsim.egg-info/requires.txt @@ -1,3 +1,7 @@ -cython numpy networkx +scipy +cython==3.0a8 +scikit-learn +pyprind +sphinx==4.0.0 diff --git a/plexsim/models/base.cpp b/plexsim/models/base.cpp index 3f35fff2..9cf24ef2 100644 --- a/plexsim/models/base.cpp +++ b/plexsim/models/base.cpp @@ -1992,7 +1992,7 @@ struct __pyx_vtabstruct_7plexsim_6models_7sampler_MCMC { static struct __pyx_vtabstruct_7plexsim_6models_7sampler_MCMC *__pyx_vtabptr_7plexsim_6models_7sampler_MCMC; -/* "plexsim/models/base.pyx":30 +/* "plexsim/models/base.pyx":29 * * # cdef public class Model [object PyModel, type PyModel_t]: * cdef class Model: # <<<<<<<<<<<<<< @@ -5460,7 +5460,7 @@ static int __pyx_m_traverse(PyObject *m, visitproc visit, void *arg) { #endif /* #### Code section: module_code ### */ -/* "plexsim/models/base.pyx":66 +/* "plexsim/models/base.pyx":65 * """ * * def __init__(self,\ # <<<<<<<<<<<<<< @@ -5506,7 +5506,7 @@ static int __pyx_pw_7plexsim_6models_4base_5Model_1__init__(PyObject *__pyx_v_se values[3] = ((PyObject *)__pyx_n_s_async); values[4] = __pyx_k__3; - /* "plexsim/models/base.pyx":72 + /* "plexsim/models/base.pyx":71 * updateType = "async",\ * nudges = {},\ * seed = None,\ # <<<<<<<<<<<<<< @@ -5518,7 +5518,7 @@ static int __pyx_pw_7plexsim_6models_4base_5Model_1__init__(PyObject *__pyx_v_se values[7] = ((PyObject *)__pyx_int_1); values[8] = ((PyObject *)__pyx_int_0); - /* "plexsim/models/base.pyx":76 + /* "plexsim/models/base.pyx":75 * kNudges = 1,\ * memento = 0, * p_recomb = None,\ # <<<<<<<<<<<<<< @@ -5561,82 +5561,82 @@ static int __pyx_pw_7plexsim_6models_4base_5Model_1__init__(PyObject *__pyx_v_se if (kw_args > 0) { PyObject* value = __Pyx_GetKwValue_VARARGS(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_graph); if (value) { values[0] = value; kw_args--; } - else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 66, __pyx_L3_error) + else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 65, __pyx_L3_error) } CYTHON_FALLTHROUGH; case 1: if (kw_args > 0) { PyObject* value = __Pyx_GetKwValue_VARARGS(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_agentStates); if (value) { values[1] = value; kw_args--; } - else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 66, __pyx_L3_error) + else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 65, __pyx_L3_error) } CYTHON_FALLTHROUGH; case 2: if (kw_args > 0) { PyObject* value = __Pyx_GetKwValue_VARARGS(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_nudgeType); if (value) { values[2] = value; kw_args--; } - else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 66, __pyx_L3_error) + else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 65, __pyx_L3_error) } CYTHON_FALLTHROUGH; case 3: if (kw_args > 0) { PyObject* value = __Pyx_GetKwValue_VARARGS(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_updateType); if (value) { values[3] = value; kw_args--; } - else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 66, __pyx_L3_error) + else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 65, __pyx_L3_error) } CYTHON_FALLTHROUGH; case 4: if (kw_args > 0) { PyObject* value = __Pyx_GetKwValue_VARARGS(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_nudges); if (value) { values[4] = value; kw_args--; } - else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 66, __pyx_L3_error) + else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 65, __pyx_L3_error) } CYTHON_FALLTHROUGH; case 5: if (kw_args > 0) { PyObject* value = __Pyx_GetKwValue_VARARGS(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_seed); if (value) { values[5] = value; kw_args--; } - else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 66, __pyx_L3_error) + else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 65, __pyx_L3_error) } CYTHON_FALLTHROUGH; case 6: if (kw_args > 0) { PyObject* value = __Pyx_GetKwValue_VARARGS(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_memorySize); if (value) { values[6] = value; kw_args--; } - else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 66, __pyx_L3_error) + else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 65, __pyx_L3_error) } CYTHON_FALLTHROUGH; case 7: if (kw_args > 0) { PyObject* value = __Pyx_GetKwValue_VARARGS(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_kNudges); if (value) { values[7] = value; kw_args--; } - else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 66, __pyx_L3_error) + else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 65, __pyx_L3_error) } CYTHON_FALLTHROUGH; case 8: if (kw_args > 0) { PyObject* value = __Pyx_GetKwValue_VARARGS(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_memento); if (value) { values[8] = value; kw_args--; } - else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 66, __pyx_L3_error) + else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 65, __pyx_L3_error) } CYTHON_FALLTHROUGH; case 9: if (kw_args > 0) { PyObject* value = __Pyx_GetKwValue_VARARGS(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_p_recomb); if (value) { values[9] = value; kw_args--; } - else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 66, __pyx_L3_error) + else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 65, __pyx_L3_error) } CYTHON_FALLTHROUGH; case 10: if (kw_args > 0) { PyObject* value = __Pyx_GetKwValue_VARARGS(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_rules); if (value) { values[10] = value; kw_args--; } - else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 66, __pyx_L3_error) + else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 65, __pyx_L3_error) } } if (unlikely(kw_args > 0)) { const Py_ssize_t kwd_pos_args = __pyx_nargs; - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_kwvalues, __pyx_pyargnames, __pyx_v_kwargs, values + 0, kwd_pos_args, "__init__") < 0)) __PYX_ERR(0, 66, __pyx_L3_error) + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_kwvalues, __pyx_pyargnames, __pyx_v_kwargs, values + 0, kwd_pos_args, "__init__") < 0)) __PYX_ERR(0, 65, __pyx_L3_error) } } else { switch (__pyx_nargs) { @@ -5680,7 +5680,7 @@ static int __pyx_pw_7plexsim_6models_4base_5Model_1__init__(PyObject *__pyx_v_se } goto __pyx_L4_argument_unpacking_done; __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("__init__", 0, 0, 11, __pyx_nargs); __PYX_ERR(0, 66, __pyx_L3_error) + __Pyx_RaiseArgtupleInvalid("__init__", 0, 0, 11, __pyx_nargs); __PYX_ERR(0, 65, __pyx_L3_error) __pyx_L3_error:; __Pyx_DECREF(__pyx_v_kwargs); __pyx_v_kwargs = 0; __Pyx_AddTraceback("plexsim.models.base.Model.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename); @@ -5689,7 +5689,7 @@ static int __pyx_pw_7plexsim_6models_4base_5Model_1__init__(PyObject *__pyx_v_se __pyx_L4_argument_unpacking_done:; __pyx_r = __pyx_pf_7plexsim_6models_4base_5Model___init__(((struct __pyx_obj_7plexsim_6models_4base_Model *)__pyx_v_self), __pyx_v_graph, __pyx_v_agentStates, __pyx_v_nudgeType, __pyx_v_updateType, __pyx_v_nudges, __pyx_v_seed, __pyx_v_memorySize, __pyx_v_kNudges, __pyx_v_memento, __pyx_v_p_recomb, __pyx_v_rules, __pyx_v_kwargs); - /* "plexsim/models/base.pyx":66 + /* "plexsim/models/base.pyx":65 * """ * * def __init__(self,\ # <<<<<<<<<<<<<< @@ -5725,17 +5725,17 @@ static int __pyx_pf_7plexsim_6models_4base_5Model___init__(struct __pyx_obj_7ple int __pyx_clineno = 0; __Pyx_RefNannySetupContext("__init__", 0); - /* "plexsim/models/base.pyx":82 + /* "plexsim/models/base.pyx":81 * * # use current time as seed for rng * self._rng = RandomGenerator(seed = seed) # <<<<<<<<<<<<<< * * self._rules = Rules(rules) */ - __pyx_t_1 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 82, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 81, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_seed, __pyx_v_seed) < 0) __PYX_ERR(0, 82, __pyx_L1_error) - __pyx_t_2 = __Pyx_PyObject_Call(((PyObject *)__pyx_ptype_7plexsim_6models_7sampler_RandomGenerator), __pyx_empty_tuple, __pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 82, __pyx_L1_error) + if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_seed, __pyx_v_seed) < 0) __PYX_ERR(0, 81, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyObject_Call(((PyObject *)__pyx_ptype_7plexsim_6models_7sampler_RandomGenerator), __pyx_empty_tuple, __pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 81, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __Pyx_GIVEREF(__pyx_t_2); @@ -5744,14 +5744,14 @@ static int __pyx_pf_7plexsim_6models_4base_5Model___init__(struct __pyx_obj_7ple __pyx_v_self->_rng = ((struct __pyx_obj_7plexsim_6models_7sampler_RandomGenerator *)__pyx_t_2); __pyx_t_2 = 0; - /* "plexsim/models/base.pyx":84 + /* "plexsim/models/base.pyx":83 * self._rng = RandomGenerator(seed = seed) * * self._rules = Rules(rules) # <<<<<<<<<<<<<< * self.kNudges = kNudges * */ - __pyx_t_2 = __Pyx_PyObject_CallOneArg(((PyObject *)__pyx_ptype_7plexsim_6models_5rules_Rules), __pyx_v_rules); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 84, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyObject_CallOneArg(((PyObject *)__pyx_ptype_7plexsim_6models_5rules_Rules), __pyx_v_rules); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 83, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_GIVEREF(__pyx_t_2); __Pyx_GOTREF((PyObject *)__pyx_v_self->_rules); @@ -5759,47 +5759,47 @@ static int __pyx_pf_7plexsim_6models_4base_5Model___init__(struct __pyx_obj_7ple __pyx_v_self->_rules = ((struct __pyx_obj_7plexsim_6models_5rules_Rules *)__pyx_t_2); __pyx_t_2 = 0; - /* "plexsim/models/base.pyx":85 + /* "plexsim/models/base.pyx":84 * * self._rules = Rules(rules) * self.kNudges = kNudges # <<<<<<<<<<<<<< * * self._agentStates = np.asarray(agentStates, dtype = np.double).copy() */ - if (__Pyx_PyObject_SetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_kNudges, __pyx_v_kNudges) < 0) __PYX_ERR(0, 85, __pyx_L1_error) + if (__Pyx_PyObject_SetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_kNudges, __pyx_v_kNudges) < 0) __PYX_ERR(0, 84, __pyx_L1_error) - /* "plexsim/models/base.pyx":87 + /* "plexsim/models/base.pyx":86 * self.kNudges = kNudges * * self._agentStates = np.asarray(agentStates, dtype = np.double).copy() # <<<<<<<<<<<<<< * self._nStates = len(agentStates) * if isinstance(p_recomb, float): */ - __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_np); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 87, __pyx_L1_error) + __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_np); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 86, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_asarray); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 87, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_asarray); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 86, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 87, __pyx_L1_error) + __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 86, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_INCREF(__pyx_v_agentStates); __Pyx_GIVEREF(__pyx_v_agentStates); PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_agentStates); - __pyx_t_4 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 87, __pyx_L1_error) + __pyx_t_4 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 86, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); - __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_np); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 87, __pyx_L1_error) + __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_np); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 86, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); - __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_double); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 87, __pyx_L1_error) + __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_double); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 86, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - if (PyDict_SetItem(__pyx_t_4, __pyx_n_s_dtype, __pyx_t_6) < 0) __PYX_ERR(0, 87, __pyx_L1_error) + if (PyDict_SetItem(__pyx_t_4, __pyx_n_s_dtype, __pyx_t_6) < 0) __PYX_ERR(0, 86, __pyx_L1_error) __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - __pyx_t_6 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_1, __pyx_t_4); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 87, __pyx_L1_error) + __pyx_t_6 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_1, __pyx_t_4); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 86, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_copy); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 87, __pyx_L1_error) + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_copy); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 86, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; __pyx_t_6 = NULL; @@ -5818,28 +5818,28 @@ static int __pyx_pf_7plexsim_6models_4base_5Model___init__(struct __pyx_obj_7ple PyObject *__pyx_callargs[1] = {__pyx_t_6, }; __pyx_t_2 = __Pyx_PyObject_FastCall(__pyx_t_4, __pyx_callargs+1-__pyx_t_7, 0+__pyx_t_7); __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; - if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 87, __pyx_L1_error) + if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 86, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; } - __pyx_t_8 = __Pyx_PyObject_to_MemoryviewSlice_dc_nn___pyx_t_7plexsim_6models_5types_state_t(__pyx_t_2, PyBUF_WRITABLE); if (unlikely(!__pyx_t_8.memview)) __PYX_ERR(0, 87, __pyx_L1_error) + __pyx_t_8 = __Pyx_PyObject_to_MemoryviewSlice_dc_nn___pyx_t_7plexsim_6models_5types_state_t(__pyx_t_2, PyBUF_WRITABLE); if (unlikely(!__pyx_t_8.memview)) __PYX_ERR(0, 86, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __PYX_XCLEAR_MEMVIEW(&__pyx_v_self->_agentStates, 0); __pyx_v_self->_agentStates = __pyx_t_8; __pyx_t_8.memview = NULL; __pyx_t_8.data = NULL; - /* "plexsim/models/base.pyx":88 + /* "plexsim/models/base.pyx":87 * * self._agentStates = np.asarray(agentStates, dtype = np.double).copy() * self._nStates = len(agentStates) # <<<<<<<<<<<<<< * if isinstance(p_recomb, float): * self._mcmc = MCMC(self._rng, p_recomb) */ - __pyx_t_9 = PyObject_Length(__pyx_v_agentStates); if (unlikely(__pyx_t_9 == ((Py_ssize_t)-1))) __PYX_ERR(0, 88, __pyx_L1_error) + __pyx_t_9 = PyObject_Length(__pyx_v_agentStates); if (unlikely(__pyx_t_9 == ((Py_ssize_t)-1))) __PYX_ERR(0, 87, __pyx_L1_error) __pyx_v_self->_nStates = __pyx_t_9; - /* "plexsim/models/base.pyx":89 + /* "plexsim/models/base.pyx":88 * self._agentStates = np.asarray(agentStates, dtype = np.double).copy() * self._nStates = len(agentStates) * if isinstance(p_recomb, float): # <<<<<<<<<<<<<< @@ -5850,14 +5850,14 @@ static int __pyx_pf_7plexsim_6models_4base_5Model___init__(struct __pyx_obj_7ple __pyx_t_11 = (__pyx_t_10 != 0); if (__pyx_t_11) { - /* "plexsim/models/base.pyx":90 + /* "plexsim/models/base.pyx":89 * self._nStates = len(agentStates) * if isinstance(p_recomb, float): * self._mcmc = MCMC(self._rng, p_recomb) # <<<<<<<<<<<<<< * self._use_mcmc = True * else: */ - __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 90, __pyx_L1_error) + __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 89, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_INCREF((PyObject *)__pyx_v_self->_rng); __Pyx_GIVEREF((PyObject *)__pyx_v_self->_rng); @@ -5865,7 +5865,7 @@ static int __pyx_pf_7plexsim_6models_4base_5Model___init__(struct __pyx_obj_7ple __Pyx_INCREF(__pyx_v_p_recomb); __Pyx_GIVEREF(__pyx_v_p_recomb); PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_v_p_recomb); - __pyx_t_4 = __Pyx_PyObject_Call(((PyObject *)__pyx_ptype_7plexsim_6models_7sampler_MCMC), __pyx_t_2, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 90, __pyx_L1_error) + __pyx_t_4 = __Pyx_PyObject_Call(((PyObject *)__pyx_ptype_7plexsim_6models_7sampler_MCMC), __pyx_t_2, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 89, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_GIVEREF(__pyx_t_4); @@ -5874,7 +5874,7 @@ static int __pyx_pf_7plexsim_6models_4base_5Model___init__(struct __pyx_obj_7ple __pyx_v_self->_mcmc = ((struct __pyx_obj_7plexsim_6models_7sampler_MCMC *)__pyx_t_4); __pyx_t_4 = 0; - /* "plexsim/models/base.pyx":91 + /* "plexsim/models/base.pyx":90 * if isinstance(p_recomb, float): * self._mcmc = MCMC(self._rng, p_recomb) * self._use_mcmc = True # <<<<<<<<<<<<<< @@ -5883,7 +5883,7 @@ static int __pyx_pf_7plexsim_6models_4base_5Model___init__(struct __pyx_obj_7ple */ __pyx_v_self->_use_mcmc = 1; - /* "plexsim/models/base.pyx":89 + /* "plexsim/models/base.pyx":88 * self._agentStates = np.asarray(agentStates, dtype = np.double).copy() * self._nStates = len(agentStates) * if isinstance(p_recomb, float): # <<<<<<<<<<<<<< @@ -5893,7 +5893,7 @@ static int __pyx_pf_7plexsim_6models_4base_5Model___init__(struct __pyx_obj_7ple goto __pyx_L3; } - /* "plexsim/models/base.pyx":93 + /* "plexsim/models/base.pyx":92 * self._use_mcmc = True * else: * self._mcmc = MCMC(self._rng, 0) # <<<<<<<<<<<<<< @@ -5901,7 +5901,7 @@ static int __pyx_pf_7plexsim_6models_4base_5Model___init__(struct __pyx_obj_7ple * */ /*else*/ { - __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 93, __pyx_L1_error) + __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 92, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_INCREF((PyObject *)__pyx_v_self->_rng); __Pyx_GIVEREF((PyObject *)__pyx_v_self->_rng); @@ -5909,7 +5909,7 @@ static int __pyx_pf_7plexsim_6models_4base_5Model___init__(struct __pyx_obj_7ple __Pyx_INCREF(__pyx_int_0); __Pyx_GIVEREF(__pyx_int_0); PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_int_0); - __pyx_t_2 = __Pyx_PyObject_Call(((PyObject *)__pyx_ptype_7plexsim_6models_7sampler_MCMC), __pyx_t_4, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 93, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyObject_Call(((PyObject *)__pyx_ptype_7plexsim_6models_7sampler_MCMC), __pyx_t_4, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 92, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __Pyx_GIVEREF(__pyx_t_2); @@ -5918,7 +5918,7 @@ static int __pyx_pf_7plexsim_6models_4base_5Model___init__(struct __pyx_obj_7ple __pyx_v_self->_mcmc = ((struct __pyx_obj_7plexsim_6models_7sampler_MCMC *)__pyx_t_2); __pyx_t_2 = 0; - /* "plexsim/models/base.pyx":94 + /* "plexsim/models/base.pyx":93 * else: * self._mcmc = MCMC(self._rng, 0) * self._use_mcmc = False # <<<<<<<<<<<<<< @@ -5929,14 +5929,14 @@ static int __pyx_pf_7plexsim_6models_4base_5Model___init__(struct __pyx_obj_7ple } __pyx_L3:; - /* "plexsim/models/base.pyx":98 + /* "plexsim/models/base.pyx":97 * # create adj list * # if graph: * self.adj = Adjacency(graph) # <<<<<<<<<<<<<< * # set states if present * states = kwargs.get("states") */ - __pyx_t_2 = __Pyx_PyObject_CallOneArg(((PyObject *)__pyx_ptype_7plexsim_6models_9adjacency_Adjacency), __pyx_v_graph); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 98, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyObject_CallOneArg(((PyObject *)__pyx_ptype_7plexsim_6models_9adjacency_Adjacency), __pyx_v_graph); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 97, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_GIVEREF(__pyx_t_2); __Pyx_GOTREF((PyObject *)__pyx_v_self->adj); @@ -5944,19 +5944,19 @@ static int __pyx_pf_7plexsim_6models_4base_5Model___init__(struct __pyx_obj_7ple __pyx_v_self->adj = ((struct __pyx_obj_7plexsim_6models_9adjacency_Adjacency *)__pyx_t_2); __pyx_t_2 = 0; - /* "plexsim/models/base.pyx":100 + /* "plexsim/models/base.pyx":99 * self.adj = Adjacency(graph) * # set states if present * states = kwargs.get("states") # <<<<<<<<<<<<<< * if states is not None: * self.states = states.copy() */ - __pyx_t_2 = __Pyx_PyDict_GetItemDefault(__pyx_v_kwargs, __pyx_n_s_states, Py_None); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 100, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyDict_GetItemDefault(__pyx_v_kwargs, __pyx_n_s_states, Py_None); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 99, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_v_states = __pyx_t_2; __pyx_t_2 = 0; - /* "plexsim/models/base.pyx":101 + /* "plexsim/models/base.pyx":100 * # set states if present * states = kwargs.get("states") * if states is not None: # <<<<<<<<<<<<<< @@ -5967,14 +5967,14 @@ static int __pyx_pf_7plexsim_6models_4base_5Model___init__(struct __pyx_obj_7ple __pyx_t_10 = (__pyx_t_11 != 0); if (__pyx_t_10) { - /* "plexsim/models/base.pyx":102 + /* "plexsim/models/base.pyx":101 * states = kwargs.get("states") * if states is not None: * self.states = states.copy() # <<<<<<<<<<<<<< * else: * self.reset() */ - __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_states, __pyx_n_s_copy); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 102, __pyx_L1_error) + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_states, __pyx_n_s_copy); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 101, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_t_6 = NULL; __pyx_t_7 = 0; @@ -5992,14 +5992,14 @@ static int __pyx_pf_7plexsim_6models_4base_5Model___init__(struct __pyx_obj_7ple PyObject *__pyx_callargs[1] = {__pyx_t_6, }; __pyx_t_2 = __Pyx_PyObject_FastCall(__pyx_t_4, __pyx_callargs+1-__pyx_t_7, 0+__pyx_t_7); __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; - if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 102, __pyx_L1_error) + if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 101, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; } - if (__Pyx_PyObject_SetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_states, __pyx_t_2) < 0) __PYX_ERR(0, 102, __pyx_L1_error) + if (__Pyx_PyObject_SetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_states, __pyx_t_2) < 0) __PYX_ERR(0, 101, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - /* "plexsim/models/base.pyx":101 + /* "plexsim/models/base.pyx":100 * # set states if present * states = kwargs.get("states") * if states is not None: # <<<<<<<<<<<<<< @@ -6009,7 +6009,7 @@ static int __pyx_pf_7plexsim_6models_4base_5Model___init__(struct __pyx_obj_7ple goto __pyx_L4; } - /* "plexsim/models/base.pyx":104 + /* "plexsim/models/base.pyx":103 * self.states = states.copy() * else: * self.reset() # <<<<<<<<<<<<<< @@ -6021,57 +6021,57 @@ static int __pyx_pf_7plexsim_6models_4base_5Model___init__(struct __pyx_obj_7ple } __pyx_L4:; - /* "plexsim/models/base.pyx":107 + /* "plexsim/models/base.pyx":106 * * # create properties * self.nudgeType = nudgeType # <<<<<<<<<<<<<< * * # create memory */ - if (__Pyx_PyObject_SetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_nudgeType, __pyx_v_nudgeType) < 0) __PYX_ERR(0, 107, __pyx_L1_error) + if (__Pyx_PyObject_SetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_nudgeType, __pyx_v_nudgeType) < 0) __PYX_ERR(0, 106, __pyx_L1_error) - /* "plexsim/models/base.pyx":110 + /* "plexsim/models/base.pyx":109 * * # create memory * self.memorySize = memorySize # <<<<<<<<<<<<<< * self._memory = np.random.choice(self.agentStates, size = (self.memorySize, self.adj._nNodes)) * # weight factor of memory */ - __pyx_t_12 = __Pyx_PyInt_As_size_t(__pyx_v_memorySize); if (unlikely((__pyx_t_12 == (size_t)-1) && PyErr_Occurred())) __PYX_ERR(0, 110, __pyx_L1_error) - __pyx_t_2 = __Pyx_PyInt_FromSize_t(((size_t)__pyx_t_12)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 110, __pyx_L1_error) + __pyx_t_12 = __Pyx_PyInt_As_size_t(__pyx_v_memorySize); if (unlikely((__pyx_t_12 == (size_t)-1) && PyErr_Occurred())) __PYX_ERR(0, 109, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyInt_FromSize_t(((size_t)__pyx_t_12)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 109, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); - if (__Pyx_PyObject_SetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_memorySize, __pyx_t_2) < 0) __PYX_ERR(0, 110, __pyx_L1_error) + if (__Pyx_PyObject_SetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_memorySize, __pyx_t_2) < 0) __PYX_ERR(0, 109, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - /* "plexsim/models/base.pyx":111 + /* "plexsim/models/base.pyx":110 * # create memory * self.memorySize = memorySize * self._memory = np.random.choice(self.agentStates, size = (self.memorySize, self.adj._nNodes)) # <<<<<<<<<<<<<< * # weight factor of memory * self._memento = memento */ - __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_np); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 111, __pyx_L1_error) + __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_np); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 110, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); - __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_random); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 111, __pyx_L1_error) + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_random); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 110, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_choice); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 111, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_choice); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 110, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_agentStates); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 111, __pyx_L1_error) + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_agentStates); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 110, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); - __pyx_t_6 = PyTuple_New(1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 111, __pyx_L1_error) + __pyx_t_6 = PyTuple_New(1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 110, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __Pyx_GIVEREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_4); __pyx_t_4 = 0; - __pyx_t_4 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 111, __pyx_L1_error) + __pyx_t_4 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 110, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_memorySize); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 111, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_memorySize); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 110, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - __pyx_t_3 = __Pyx_PyInt_FromSize_t(__pyx_v_self->adj->_nNodes); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 111, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyInt_FromSize_t(__pyx_v_self->adj->_nNodes); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 110, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); - __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 111, __pyx_L1_error) + __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 110, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __Pyx_GIVEREF(__pyx_t_1); PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_1); @@ -6079,68 +6079,68 @@ static int __pyx_pf_7plexsim_6models_4base_5Model___init__(struct __pyx_obj_7ple PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_3); __pyx_t_1 = 0; __pyx_t_3 = 0; - if (PyDict_SetItem(__pyx_t_4, __pyx_n_s_size, __pyx_t_5) < 0) __PYX_ERR(0, 111, __pyx_L1_error) + if (PyDict_SetItem(__pyx_t_4, __pyx_n_s_size, __pyx_t_5) < 0) __PYX_ERR(0, 110, __pyx_L1_error) __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_6, __pyx_t_4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 111, __pyx_L1_error) + __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_6, __pyx_t_4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 110, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_t_13 = __Pyx_PyObject_to_MemoryviewSlice_d_dc_nn___pyx_t_7plexsim_6models_5types_state_t(__pyx_t_5, PyBUF_WRITABLE); if (unlikely(!__pyx_t_13.memview)) __PYX_ERR(0, 111, __pyx_L1_error) + __pyx_t_13 = __Pyx_PyObject_to_MemoryviewSlice_d_dc_nn___pyx_t_7plexsim_6models_5types_state_t(__pyx_t_5, PyBUF_WRITABLE); if (unlikely(!__pyx_t_13.memview)) __PYX_ERR(0, 110, __pyx_L1_error) __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; __PYX_XCLEAR_MEMVIEW(&__pyx_v_self->_memory, 0); __pyx_v_self->_memory = __pyx_t_13; __pyx_t_13.memview = NULL; __pyx_t_13.data = NULL; - /* "plexsim/models/base.pyx":113 + /* "plexsim/models/base.pyx":112 * self._memory = np.random.choice(self.agentStates, size = (self.memorySize, self.adj._nNodes)) * # weight factor of memory * self._memento = memento # <<<<<<<<<<<<<< * self.nudges = nudges * # n.b. sampleSize has to be set from no on */ - __pyx_t_12 = __Pyx_PyInt_As_size_t(__pyx_v_memento); if (unlikely((__pyx_t_12 == (size_t)-1) && PyErr_Occurred())) __PYX_ERR(0, 113, __pyx_L1_error) + __pyx_t_12 = __Pyx_PyInt_As_size_t(__pyx_v_memento); if (unlikely((__pyx_t_12 == (size_t)-1) && PyErr_Occurred())) __PYX_ERR(0, 112, __pyx_L1_error) __pyx_v_self->_memento = ((size_t)__pyx_t_12); - /* "plexsim/models/base.pyx":114 + /* "plexsim/models/base.pyx":113 * # weight factor of memory * self._memento = memento * self.nudges = nudges # <<<<<<<<<<<<<< * # n.b. sampleSize has to be set from no on * self.updateType = updateType */ - if (__Pyx_PyObject_SetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_nudges, __pyx_v_nudges) < 0) __PYX_ERR(0, 114, __pyx_L1_error) + if (__Pyx_PyObject_SetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_nudges, __pyx_v_nudges) < 0) __PYX_ERR(0, 113, __pyx_L1_error) - /* "plexsim/models/base.pyx":116 + /* "plexsim/models/base.pyx":115 * self.nudges = nudges * # n.b. sampleSize has to be set from no on * self.updateType = updateType # <<<<<<<<<<<<<< * self.sampleSize = kwargs.get("sampleSize", self.nNodes) * */ - if (__Pyx_PyObject_SetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_updateType, __pyx_v_updateType) < 0) __PYX_ERR(0, 116, __pyx_L1_error) + if (__Pyx_PyObject_SetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_updateType, __pyx_v_updateType) < 0) __PYX_ERR(0, 115, __pyx_L1_error) - /* "plexsim/models/base.pyx":117 + /* "plexsim/models/base.pyx":116 * # n.b. sampleSize has to be set from no on * self.updateType = updateType * self.sampleSize = kwargs.get("sampleSize", self.nNodes) # <<<<<<<<<<<<<< * * self._z = 1 / self._nStates */ - __pyx_t_5 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_nNodes); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 117, __pyx_L1_error) + __pyx_t_5 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_nNodes); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 116, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); - __pyx_t_4 = __Pyx_PyDict_GetItemDefault(__pyx_v_kwargs, __pyx_n_s_sampleSize, __pyx_t_5); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 117, __pyx_L1_error) + __pyx_t_4 = __Pyx_PyDict_GetItemDefault(__pyx_v_kwargs, __pyx_n_s_sampleSize, __pyx_t_5); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 116, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_t_12 = __Pyx_PyInt_As_size_t(__pyx_t_4); if (unlikely((__pyx_t_12 == (size_t)-1) && PyErr_Occurred())) __PYX_ERR(0, 117, __pyx_L1_error) + __pyx_t_12 = __Pyx_PyInt_As_size_t(__pyx_t_4); if (unlikely((__pyx_t_12 == (size_t)-1) && PyErr_Occurred())) __PYX_ERR(0, 116, __pyx_L1_error) __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_t_4 = __Pyx_PyInt_FromSize_t(((size_t)__pyx_t_12)); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 117, __pyx_L1_error) + __pyx_t_4 = __Pyx_PyInt_FromSize_t(((size_t)__pyx_t_12)); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 116, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); - if (__Pyx_PyObject_SetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_sampleSize, __pyx_t_4) < 0) __PYX_ERR(0, 117, __pyx_L1_error) + if (__Pyx_PyObject_SetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_sampleSize, __pyx_t_4) < 0) __PYX_ERR(0, 116, __pyx_L1_error) __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - /* "plexsim/models/base.pyx":119 + /* "plexsim/models/base.pyx":118 * self.sampleSize = kwargs.get("sampleSize", self.nNodes) * * self._z = 1 / self._nStates # <<<<<<<<<<<<<< @@ -6149,7 +6149,7 @@ static int __pyx_pf_7plexsim_6models_4base_5Model___init__(struct __pyx_obj_7ple */ __pyx_v_self->_z = (1.0 / ((double)__pyx_v_self->_nStates)); - /* "plexsim/models/base.pyx":122 + /* "plexsim/models/base.pyx":121 * * # create pointer * self.ptr = self # <<<<<<<<<<<<<< @@ -6158,7 +6158,7 @@ static int __pyx_pf_7plexsim_6models_4base_5Model___init__(struct __pyx_obj_7ple */ __pyx_v_self->ptr = ((PyObject *)__pyx_v_self); - /* "plexsim/models/base.pyx":66 + /* "plexsim/models/base.pyx":65 * """ * * def __init__(self,\ # <<<<<<<<<<<<<< @@ -6186,7 +6186,7 @@ static int __pyx_pf_7plexsim_6models_4base_5Model___init__(struct __pyx_obj_7ple return __pyx_r; } -/* "plexsim/models/base.pyx":125 +/* "plexsim/models/base.pyx":124 * * * cdef state_t[::1] _updateState(self, node_id_t[::1] nodesToUpdate) nogil: # <<<<<<<<<<<<<< @@ -6211,7 +6211,7 @@ static __Pyx_memviewslice __pyx_f_7plexsim_6models_4base_5Model__updateState(str PyGILState_STATE __pyx_gilstate_save; #endif - /* "plexsim/models/base.pyx":134 + /* "plexsim/models/base.pyx":133 * """ * * cdef NudgesBackup* backup = new NudgesBackup() # <<<<<<<<<<<<<< @@ -6228,11 +6228,11 @@ static __Pyx_memviewslice __pyx_f_7plexsim_6models_4base_5Model__updateState(str #ifdef WITH_THREAD __Pyx_PyGILState_Release(__pyx_gilstate_save); #endif - __PYX_ERR(0, 134, __pyx_L1_error) + __PYX_ERR(0, 133, __pyx_L1_error) } __pyx_v_backup = __pyx_t_1; - /* "plexsim/models/base.pyx":137 + /* "plexsim/models/base.pyx":136 * # updating nodes * cdef node_id_t node * if self._use_mcmc: # <<<<<<<<<<<<<< @@ -6242,7 +6242,7 @@ static __Pyx_memviewslice __pyx_f_7plexsim_6models_4base_5Model__updateState(str __pyx_t_2 = (__pyx_v_self->_use_mcmc != 0); if (__pyx_t_2) { - /* "plexsim/models/base.pyx":138 + /* "plexsim/models/base.pyx":137 * cdef node_id_t node * if self._use_mcmc: * self._mcmc.step(nodesToUpdate, self) # <<<<<<<<<<<<<< @@ -6251,7 +6251,7 @@ static __Pyx_memviewslice __pyx_f_7plexsim_6models_4base_5Model__updateState(str */ ((struct __pyx_vtabstruct_7plexsim_6models_7sampler_MCMC *)__pyx_v_self->_mcmc->__pyx_vtab)->step(__pyx_v_self->_mcmc, __pyx_v_nodesToUpdate, ((PyObject *)__pyx_v_self)); - /* "plexsim/models/base.pyx":137 + /* "plexsim/models/base.pyx":136 * # updating nodes * cdef node_id_t node * if self._use_mcmc: # <<<<<<<<<<<<<< @@ -6261,7 +6261,7 @@ static __Pyx_memviewslice __pyx_f_7plexsim_6models_4base_5Model__updateState(str goto __pyx_L3; } - /* "plexsim/models/base.pyx":140 + /* "plexsim/models/base.pyx":139 * self._mcmc.step(nodesToUpdate, self) * else: * for node in range(nodesToUpdate.shape[0]): # <<<<<<<<<<<<<< @@ -6274,7 +6274,7 @@ static __Pyx_memviewslice __pyx_f_7plexsim_6models_4base_5Model__updateState(str for (__pyx_t_5 = 0; __pyx_t_5 < __pyx_t_4; __pyx_t_5+=1) { __pyx_v_node = __pyx_t_5; - /* "plexsim/models/base.pyx":141 + /* "plexsim/models/base.pyx":140 * else: * for node in range(nodesToUpdate.shape[0]): * node = nodesToUpdate[node] # <<<<<<<<<<<<<< @@ -6284,7 +6284,7 @@ static __Pyx_memviewslice __pyx_f_7plexsim_6models_4base_5Model__updateState(str __pyx_t_6 = __pyx_v_node; __pyx_v_node = (*((__pyx_t_7plexsim_6models_5types_node_id_t *) ( /* dim=0 */ ((char *) (((__pyx_t_7plexsim_6models_5types_node_id_t *) __pyx_v_nodesToUpdate.data) + __pyx_t_6)) ))); - /* "plexsim/models/base.pyx":142 + /* "plexsim/models/base.pyx":141 * for node in range(nodesToUpdate.shape[0]): * node = nodesToUpdate[node] * self._apply_nudge(node, backup) # <<<<<<<<<<<<<< @@ -6293,7 +6293,7 @@ static __Pyx_memviewslice __pyx_f_7plexsim_6models_4base_5Model__updateState(str */ ((struct __pyx_vtabstruct_7plexsim_6models_4base_Model *)__pyx_v_self->__pyx_vtab)->_apply_nudge(__pyx_v_self, __pyx_v_node, __pyx_v_backup); - /* "plexsim/models/base.pyx":143 + /* "plexsim/models/base.pyx":142 * node = nodesToUpdate[node] * self._apply_nudge(node, backup) * self._step(node) # <<<<<<<<<<<<<< @@ -6302,7 +6302,7 @@ static __Pyx_memviewslice __pyx_f_7plexsim_6models_4base_5Model__updateState(str */ ((struct __pyx_vtabstruct_7plexsim_6models_4base_Model *)__pyx_v_self->__pyx_vtab)->_step(__pyx_v_self, __pyx_v_node); - /* "plexsim/models/base.pyx":144 + /* "plexsim/models/base.pyx":143 * self._apply_nudge(node, backup) * self._step(node) * self._remove_nudge(node, backup) # <<<<<<<<<<<<<< @@ -6314,7 +6314,7 @@ static __Pyx_memviewslice __pyx_f_7plexsim_6models_4base_5Model__updateState(str } __pyx_L3:; - /* "plexsim/models/base.pyx":147 + /* "plexsim/models/base.pyx":146 * * # clean up * free(backup) # <<<<<<<<<<<<<< @@ -6323,7 +6323,7 @@ static __Pyx_memviewslice __pyx_f_7plexsim_6models_4base_5Model__updateState(str */ free(__pyx_v_backup); - /* "plexsim/models/base.pyx":148 + /* "plexsim/models/base.pyx":147 * # clean up * free(backup) * self._swap_buffers() # <<<<<<<<<<<<<< @@ -6332,7 +6332,7 @@ static __Pyx_memviewslice __pyx_f_7plexsim_6models_4base_5Model__updateState(str */ ((struct __pyx_vtabstruct_7plexsim_6models_4base_Model *)__pyx_v_self->__pyx_vtab)->_swap_buffers(__pyx_v_self); - /* "plexsim/models/base.pyx":149 + /* "plexsim/models/base.pyx":148 * free(backup) * self._swap_buffers() * self._last_written = (self._last_written + 1) % 2 # <<<<<<<<<<<<<< @@ -6341,7 +6341,7 @@ static __Pyx_memviewslice __pyx_f_7plexsim_6models_4base_5Model__updateState(str */ __pyx_v_self->_last_written = ((__pyx_v_self->_last_written + 1) % 2); - /* "plexsim/models/base.pyx":151 + /* "plexsim/models/base.pyx":150 * self._last_written = (self._last_written + 1) % 2 * # return self.__newstates * if self._last_written == 1: # <<<<<<<<<<<<<< @@ -6351,7 +6351,7 @@ static __Pyx_memviewslice __pyx_f_7plexsim_6models_4base_5Model__updateState(str __pyx_t_2 = ((__pyx_v_self->_last_written == 1) != 0); if (__pyx_t_2) { - /* "plexsim/models/base.pyx":152 + /* "plexsim/models/base.pyx":151 * # return self.__newstates * if self._last_written == 1: * return self.__newstates # <<<<<<<<<<<<<< @@ -6362,7 +6362,7 @@ static __Pyx_memviewslice __pyx_f_7plexsim_6models_4base_5Model__updateState(str __pyx_r = __pyx_v_self->_Model__newstates; goto __pyx_L0; - /* "plexsim/models/base.pyx":151 + /* "plexsim/models/base.pyx":150 * self._last_written = (self._last_written + 1) % 2 * # return self.__newstates * if self._last_written == 1: # <<<<<<<<<<<<<< @@ -6371,7 +6371,7 @@ static __Pyx_memviewslice __pyx_f_7plexsim_6models_4base_5Model__updateState(str */ } - /* "plexsim/models/base.pyx":154 + /* "plexsim/models/base.pyx":153 * return self.__newstates * else: * return self.__states # <<<<<<<<<<<<<< @@ -6384,7 +6384,7 @@ static __Pyx_memviewslice __pyx_f_7plexsim_6models_4base_5Model__updateState(str goto __pyx_L0; } - /* "plexsim/models/base.pyx":125 + /* "plexsim/models/base.pyx":124 * * * cdef state_t[::1] _updateState(self, node_id_t[::1] nodesToUpdate) nogil: # <<<<<<<<<<<<<< @@ -6418,7 +6418,7 @@ static __Pyx_memviewslice __pyx_f_7plexsim_6models_4base_5Model__updateState(str return __pyx_r; } -/* "plexsim/models/base.pyx":157 +/* "plexsim/models/base.pyx":156 * * # TODO make this separate * cdef void _apply_nudge(self, node_id_t node,\ # <<<<<<<<<<<<<< @@ -6437,7 +6437,7 @@ static void __pyx_f_7plexsim_6models_4base_5Model__apply_nudge(struct __pyx_obj_ __pyx_t_7plexsim_6models_5types_node_id_t __pyx_t_2; __pyx_t_7plexsim_6models_5types_state_t __pyx_t_3; - /* "plexsim/models/base.pyx":161 + /* "plexsim/models/base.pyx":160 * * # check if it has neighbors * if self.adj._adj[node].neighbors.size() == 0: # <<<<<<<<<<<<<< @@ -6447,7 +6447,7 @@ static void __pyx_f_7plexsim_6models_4base_5Model__apply_nudge(struct __pyx_obj_ __pyx_t_1 = (((__pyx_v_self->adj->_adj[__pyx_v_node]).neighbors.size() == 0) != 0); if (__pyx_t_1) { - /* "plexsim/models/base.pyx":162 + /* "plexsim/models/base.pyx":161 * # check if it has neighbors * if self.adj._adj[node].neighbors.size() == 0: * return # <<<<<<<<<<<<<< @@ -6456,7 +6456,7 @@ static void __pyx_f_7plexsim_6models_4base_5Model__apply_nudge(struct __pyx_obj_ */ goto __pyx_L0; - /* "plexsim/models/base.pyx":161 + /* "plexsim/models/base.pyx":160 * * # check if it has neighbors * if self.adj._adj[node].neighbors.size() == 0: # <<<<<<<<<<<<<< @@ -6465,7 +6465,7 @@ static void __pyx_f_7plexsim_6models_4base_5Model__apply_nudge(struct __pyx_obj_ */ } - /* "plexsim/models/base.pyx":168 + /* "plexsim/models/base.pyx":167 * cdef NodeBackup tmp * cdef weight_t weight * cdef int jdx = 0 # <<<<<<<<<<<<<< @@ -6474,7 +6474,7 @@ static void __pyx_f_7plexsim_6models_4base_5Model__apply_nudge(struct __pyx_obj_ */ __pyx_v_jdx = 0; - /* "plexsim/models/base.pyx":173 + /* "plexsim/models/base.pyx":172 * * # check if there is a nudge * nudge = self._nudges.find(node) # <<<<<<<<<<<<<< @@ -6483,7 +6483,7 @@ static void __pyx_f_7plexsim_6models_4base_5Model__apply_nudge(struct __pyx_obj_ */ __pyx_v_nudge = __pyx_v_self->_nudges.find(__pyx_v_node); - /* "plexsim/models/base.pyx":174 + /* "plexsim/models/base.pyx":173 * # check if there is a nudge * nudge = self._nudges.find(node) * it = self.adj._adj[node].neighbors.begin() # <<<<<<<<<<<<<< @@ -6492,7 +6492,7 @@ static void __pyx_f_7plexsim_6models_4base_5Model__apply_nudge(struct __pyx_obj_ */ __pyx_v_it = (__pyx_v_self->adj->_adj[__pyx_v_node]).neighbors.begin(); - /* "plexsim/models/base.pyx":176 + /* "plexsim/models/base.pyx":175 * it = self.adj._adj[node].neighbors.begin() * cdef pair[node_id_t, weight_t] _nudge * if nudge != self._nudges.end(): # <<<<<<<<<<<<<< @@ -6502,7 +6502,7 @@ static void __pyx_f_7plexsim_6models_4base_5Model__apply_nudge(struct __pyx_obj_ __pyx_t_1 = ((__pyx_v_nudge != __pyx_v_self->_nudges.end()) != 0); if (__pyx_t_1) { - /* "plexsim/models/base.pyx":178 + /* "plexsim/models/base.pyx":177 * if nudge != self._nudges.end(): * # start nudge * target = deref(nudge).first # <<<<<<<<<<<<<< @@ -6512,7 +6512,7 @@ static void __pyx_f_7plexsim_6models_4base_5Model__apply_nudge(struct __pyx_obj_ __pyx_t_2 = (*__pyx_v_nudge).first; __pyx_v_target = __pyx_t_2; - /* "plexsim/models/base.pyx":179 + /* "plexsim/models/base.pyx":178 * # start nudge * target = deref(nudge).first * weight = deref(nudge).second # <<<<<<<<<<<<<< @@ -6522,7 +6522,7 @@ static void __pyx_f_7plexsim_6models_4base_5Model__apply_nudge(struct __pyx_obj_ __pyx_t_3 = (*__pyx_v_nudge).second; __pyx_v_weight = __pyx_t_3; - /* "plexsim/models/base.pyx":181 + /* "plexsim/models/base.pyx":180 * weight = deref(nudge).second * * _nudge.first = self.adj._nNodes + 1 # <<<<<<<<<<<<<< @@ -6531,7 +6531,7 @@ static void __pyx_f_7plexsim_6models_4base_5Model__apply_nudge(struct __pyx_obj_ */ __pyx_v__nudge.first = (__pyx_v_self->adj->_nNodes + 1); - /* "plexsim/models/base.pyx":182 + /* "plexsim/models/base.pyx":181 * * _nudge.first = self.adj._nNodes + 1 * _nudge.second = weight # <<<<<<<<<<<<<< @@ -6540,7 +6540,7 @@ static void __pyx_f_7plexsim_6models_4base_5Model__apply_nudge(struct __pyx_obj_ */ __pyx_v__nudge.second = __pyx_v_weight; - /* "plexsim/models/base.pyx":184 + /* "plexsim/models/base.pyx":183 * _nudge.second = weight * * self.adj._adj[target].neighbors.insert(_nudge) # <<<<<<<<<<<<<< @@ -6549,7 +6549,7 @@ static void __pyx_f_7plexsim_6models_4base_5Model__apply_nudge(struct __pyx_obj_ */ (void)((__pyx_v_self->adj->_adj[__pyx_v_target]).neighbors.insert(__pyx_v__nudge)); - /* "plexsim/models/base.pyx":176 + /* "plexsim/models/base.pyx":175 * it = self.adj._adj[node].neighbors.begin() * cdef pair[node_id_t, weight_t] _nudge * if nudge != self._nudges.end(): # <<<<<<<<<<<<<< @@ -6558,7 +6558,7 @@ static void __pyx_f_7plexsim_6models_4base_5Model__apply_nudge(struct __pyx_obj_ */ } - /* "plexsim/models/base.pyx":211 + /* "plexsim/models/base.pyx":210 * # self._states[node] = self._agentStates[idx] * * return # <<<<<<<<<<<<<< @@ -6567,7 +6567,7 @@ static void __pyx_f_7plexsim_6models_4base_5Model__apply_nudge(struct __pyx_obj_ */ goto __pyx_L0; - /* "plexsim/models/base.pyx":157 + /* "plexsim/models/base.pyx":156 * * # TODO make this separate * cdef void _apply_nudge(self, node_id_t node,\ # <<<<<<<<<<<<<< @@ -6579,7 +6579,7 @@ static void __pyx_f_7plexsim_6models_4base_5Model__apply_nudge(struct __pyx_obj_ __pyx_L0:; } -/* "plexsim/models/base.pyx":213 +/* "plexsim/models/base.pyx":212 * return * * cdef void _remove_nudge(self, node_id_t node,\ # <<<<<<<<<<<<<< @@ -6595,7 +6595,7 @@ static void __pyx_f_7plexsim_6models_4base_5Model__remove_nudge(struct __pyx_obj int __pyx_t_1; __pyx_t_7plexsim_6models_5types_node_id_t __pyx_t_2; - /* "plexsim/models/base.pyx":221 + /* "plexsim/models/base.pyx":220 * node_id_t neighbor * NodeBackup state * node_id_t nudge_id = self.adj._nNodes + 1 # <<<<<<<<<<<<<< @@ -6604,7 +6604,7 @@ static void __pyx_f_7plexsim_6models_4base_5Model__remove_nudge(struct __pyx_obj */ __pyx_v_nudge_id = (__pyx_v_self->adj->_nNodes + 1); - /* "plexsim/models/base.pyx":222 + /* "plexsim/models/base.pyx":221 * NodeBackup state * node_id_t nudge_id = self.adj._nNodes + 1 * it = deref(backup).begin() # <<<<<<<<<<<<<< @@ -6613,7 +6613,7 @@ static void __pyx_f_7plexsim_6models_4base_5Model__remove_nudge(struct __pyx_obj */ __pyx_v_it = (*__pyx_v_backup).begin(); - /* "plexsim/models/base.pyx":224 + /* "plexsim/models/base.pyx":223 * it = deref(backup).begin() * * while it != deref(backup).end(): # <<<<<<<<<<<<<< @@ -6624,7 +6624,7 @@ static void __pyx_f_7plexsim_6models_4base_5Model__remove_nudge(struct __pyx_obj __pyx_t_1 = ((__pyx_v_it != (*__pyx_v_backup).end()) != 0); if (!__pyx_t_1) break; - /* "plexsim/models/base.pyx":225 + /* "plexsim/models/base.pyx":224 * * while it != deref(backup).end(): * neighbor = deref(it).first # <<<<<<<<<<<<<< @@ -6634,7 +6634,7 @@ static void __pyx_f_7plexsim_6models_4base_5Model__remove_nudge(struct __pyx_obj __pyx_t_2 = (*__pyx_v_it).first; __pyx_v_neighbor = __pyx_t_2; - /* "plexsim/models/base.pyx":226 + /* "plexsim/models/base.pyx":225 * while it != deref(backup).end(): * neighbor = deref(it).first * jt = self.adj._adj[deref(it).first].neighbors.find(nudge_id) # <<<<<<<<<<<<<< @@ -6643,7 +6643,7 @@ static void __pyx_f_7plexsim_6models_4base_5Model__remove_nudge(struct __pyx_obj */ __pyx_v_jt = (__pyx_v_self->adj->_adj[(*__pyx_v_it).first]).neighbors.find(__pyx_v_nudge_id); - /* "plexsim/models/base.pyx":227 + /* "plexsim/models/base.pyx":226 * neighbor = deref(it).first * jt = self.adj._adj[deref(it).first].neighbors.find(nudge_id) * if jt != self.adj._adj[deref(it).first].neighbors.end(): # <<<<<<<<<<<<<< @@ -6653,7 +6653,7 @@ static void __pyx_f_7plexsim_6models_4base_5Model__remove_nudge(struct __pyx_obj __pyx_t_1 = ((__pyx_v_jt != (__pyx_v_self->adj->_adj[(*__pyx_v_it).first]).neighbors.end()) != 0); if (__pyx_t_1) { - /* "plexsim/models/base.pyx":228 + /* "plexsim/models/base.pyx":227 * jt = self.adj._adj[deref(it).first].neighbors.find(nudge_id) * if jt != self.adj._adj[deref(it).first].neighbors.end(): * self.adj._adj[deref(it).first].neighbors.erase(jt) # <<<<<<<<<<<<<< @@ -6662,7 +6662,7 @@ static void __pyx_f_7plexsim_6models_4base_5Model__remove_nudge(struct __pyx_obj */ (void)((__pyx_v_self->adj->_adj[(*__pyx_v_it).first]).neighbors.erase(__pyx_v_jt)); - /* "plexsim/models/base.pyx":227 + /* "plexsim/models/base.pyx":226 * neighbor = deref(it).first * jt = self.adj._adj[deref(it).first].neighbors.find(nudge_id) * if jt != self.adj._adj[deref(it).first].neighbors.end(): # <<<<<<<<<<<<<< @@ -6671,7 +6671,7 @@ static void __pyx_f_7plexsim_6models_4base_5Model__remove_nudge(struct __pyx_obj */ } - /* "plexsim/models/base.pyx":234 + /* "plexsim/models/base.pyx":233 * # self.adj._adj[node].neighbors[neighbor] = deref(it).second.weight * * post(it) # <<<<<<<<<<<<<< @@ -6681,7 +6681,7 @@ static void __pyx_f_7plexsim_6models_4base_5Model__remove_nudge(struct __pyx_obj (void)((__pyx_v_it++)); } - /* "plexsim/models/base.pyx":235 + /* "plexsim/models/base.pyx":234 * * post(it) * deref(backup).clear() # <<<<<<<<<<<<<< @@ -6690,7 +6690,7 @@ static void __pyx_f_7plexsim_6models_4base_5Model__remove_nudge(struct __pyx_obj */ (*__pyx_v_backup).clear(); - /* "plexsim/models/base.pyx":236 + /* "plexsim/models/base.pyx":235 * post(it) * deref(backup).clear() * return # <<<<<<<<<<<<<< @@ -6699,7 +6699,7 @@ static void __pyx_f_7plexsim_6models_4base_5Model__remove_nudge(struct __pyx_obj */ goto __pyx_L0; - /* "plexsim/models/base.pyx":213 + /* "plexsim/models/base.pyx":212 * return * * cdef void _remove_nudge(self, node_id_t node,\ # <<<<<<<<<<<<<< @@ -6711,7 +6711,7 @@ static void __pyx_f_7plexsim_6models_4base_5Model__remove_nudge(struct __pyx_obj __pyx_L0:; } -/* "plexsim/models/base.pyx":239 +/* "plexsim/models/base.pyx":238 * * * cdef vector[double] _nudgeShift(self, node_id_t node, vector[double] p ) nogil: # <<<<<<<<<<<<<< @@ -6739,7 +6739,7 @@ static std::vector __pyx_f_7plexsim_6models_4base_5Model__nudgeShift(st __Pyx_PyGILState_Release(__pyx_gilstate_save); #endif - /* "plexsim/models/base.pyx":241 + /* "plexsim/models/base.pyx":240 * cdef vector[double] _nudgeShift(self, node_id_t node, vector[double] p ) nogil: * # shift pmf by some nudge * _nudge = self._nudges.find(node) # <<<<<<<<<<<<<< @@ -6748,7 +6748,7 @@ static std::vector __pyx_f_7plexsim_6models_4base_5Model__nudgeShift(st */ __pyx_v__nudge = __pyx_v_self->_nudges.find(__pyx_v_node); - /* "plexsim/models/base.pyx":245 + /* "plexsim/models/base.pyx":244 * cdef double nudge * #TODO: normalize nudge pmf * if _nudge != self._nudges.end(): # <<<<<<<<<<<<<< @@ -6758,7 +6758,7 @@ static std::vector __pyx_f_7plexsim_6models_4base_5Model__nudgeShift(st __pyx_t_1 = ((__pyx_v__nudge != __pyx_v_self->_nudges.end()) != 0); if (__pyx_t_1) { - /* "plexsim/models/base.pyx":246 + /* "plexsim/models/base.pyx":245 * #TODO: normalize nudge pmf * if _nudge != self._nudges.end(): * nudge = deref(_nudge).second # <<<<<<<<<<<<<< @@ -6768,7 +6768,7 @@ static std::vector __pyx_f_7plexsim_6models_4base_5Model__nudgeShift(st __pyx_t_2 = (*__pyx_v__nudge).second; __pyx_v_nudge = __pyx_t_2; - /* "plexsim/models/base.pyx":247 + /* "plexsim/models/base.pyx":246 * if _nudge != self._nudges.end(): * nudge = deref(_nudge).second * with gil: # <<<<<<<<<<<<<< @@ -6781,7 +6781,7 @@ static std::vector __pyx_f_7plexsim_6models_4base_5Model__nudgeShift(st #endif /*try:*/ { - /* "plexsim/models/base.pyx":248 + /* "plexsim/models/base.pyx":247 * nudge = deref(_nudge).second * with gil: * for idx in range(p.size()) : # <<<<<<<<<<<<<< @@ -6793,7 +6793,7 @@ static std::vector __pyx_f_7plexsim_6models_4base_5Model__nudgeShift(st for (__pyx_t_5 = 0; __pyx_t_5 < __pyx_t_4; __pyx_t_5+=1) { __pyx_v_idx = __pyx_t_5; - /* "plexsim/models/base.pyx":249 + /* "plexsim/models/base.pyx":248 * with gil: * for idx in range(p.size()) : * p[idx] += nudge # <<<<<<<<<<<<<< @@ -6805,7 +6805,7 @@ static std::vector __pyx_f_7plexsim_6models_4base_5Model__nudgeShift(st } } - /* "plexsim/models/base.pyx":247 + /* "plexsim/models/base.pyx":246 * if _nudge != self._nudges.end(): * nudge = deref(_nudge).second * with gil: # <<<<<<<<<<<<<< @@ -6823,7 +6823,7 @@ static std::vector __pyx_f_7plexsim_6models_4base_5Model__nudgeShift(st } } - /* "plexsim/models/base.pyx":245 + /* "plexsim/models/base.pyx":244 * cdef double nudge * #TODO: normalize nudge pmf * if _nudge != self._nudges.end(): # <<<<<<<<<<<<<< @@ -6832,7 +6832,7 @@ static std::vector __pyx_f_7plexsim_6models_4base_5Model__nudgeShift(st */ } - /* "plexsim/models/base.pyx":250 + /* "plexsim/models/base.pyx":249 * for idx in range(p.size()) : * p[idx] += nudge * return p # <<<<<<<<<<<<<< @@ -6842,7 +6842,7 @@ static std::vector __pyx_f_7plexsim_6models_4base_5Model__nudgeShift(st __pyx_r = __pyx_v_p; goto __pyx_L0; - /* "plexsim/models/base.pyx":239 + /* "plexsim/models/base.pyx":238 * * * cdef vector[double] _nudgeShift(self, node_id_t node, vector[double] p ) nogil: # <<<<<<<<<<<<<< @@ -6856,7 +6856,7 @@ static std::vector __pyx_f_7plexsim_6models_4base_5Model__nudgeShift(st return __pyx_r; } -/* "plexsim/models/base.pyx":251 +/* "plexsim/models/base.pyx":250 * p[idx] += nudge * return p * cdef void _swap_memory(self) nogil: # <<<<<<<<<<<<<< @@ -6885,7 +6885,7 @@ static void __pyx_f_7plexsim_6models_4base_5Model__swap_memory(struct __pyx_obj_ PyGILState_STATE __pyx_gilstate_save; #endif - /* "plexsim/models/base.pyx":254 + /* "plexsim/models/base.pyx":253 * # use swapped states * cdef size_t mi, node * for mi in range(0, self._memorySize): # <<<<<<<<<<<<<< @@ -6897,7 +6897,7 @@ static void __pyx_f_7plexsim_6models_4base_5Model__swap_memory(struct __pyx_obj_ for (__pyx_t_3 = 0; __pyx_t_3 < __pyx_t_2; __pyx_t_3+=1) { __pyx_v_mi = __pyx_t_3; - /* "plexsim/models/base.pyx":255 + /* "plexsim/models/base.pyx":254 * cdef size_t mi, node * for mi in range(0, self._memorySize): * if mi == 0: # <<<<<<<<<<<<<< @@ -6907,7 +6907,7 @@ static void __pyx_f_7plexsim_6models_4base_5Model__swap_memory(struct __pyx_obj_ __pyx_t_4 = ((__pyx_v_mi == 0) != 0); if (__pyx_t_4) { - /* "plexsim/models/base.pyx":256 + /* "plexsim/models/base.pyx":255 * for mi in range(0, self._memorySize): * if mi == 0: * for node in range(self.adj._nNodes): # <<<<<<<<<<<<<< @@ -6919,7 +6919,7 @@ static void __pyx_f_7plexsim_6models_4base_5Model__swap_memory(struct __pyx_obj_ for (__pyx_t_7 = 0; __pyx_t_7 < __pyx_t_6; __pyx_t_7+=1) { __pyx_v_node = __pyx_t_7; - /* "plexsim/models/base.pyx":257 + /* "plexsim/models/base.pyx":256 * if mi == 0: * for node in range(self.adj._nNodes): * self._memory[mi, node] = self._states[node] # <<<<<<<<<<<<<< @@ -6931,7 +6931,7 @@ static void __pyx_f_7plexsim_6models_4base_5Model__swap_memory(struct __pyx_obj_ *((__pyx_t_7plexsim_6models_5types_state_t *) ( /* dim=1 */ ((char *) (((__pyx_t_7plexsim_6models_5types_state_t *) ( /* dim=0 */ (__pyx_v_self->_memory.data + __pyx_t_8 * __pyx_v_self->_memory.strides[0]) )) + __pyx_t_9)) )) = (__pyx_v_self->_states[__pyx_v_node]); } - /* "plexsim/models/base.pyx":255 + /* "plexsim/models/base.pyx":254 * cdef size_t mi, node * for mi in range(0, self._memorySize): * if mi == 0: # <<<<<<<<<<<<<< @@ -6941,7 +6941,7 @@ static void __pyx_f_7plexsim_6models_4base_5Model__swap_memory(struct __pyx_obj_ goto __pyx_L5; } - /* "plexsim/models/base.pyx":259 + /* "plexsim/models/base.pyx":258 * self._memory[mi, node] = self._states[node] * else: * self._memory[mi] = self._memory[mi - 1] # <<<<<<<<<<<<<< @@ -6981,7 +6981,7 @@ __pyx_t_11.shape[0] = __pyx_v_self->_memory.shape[1]; __pyx_t_11.strides[0] = __pyx_v_self->_memory.strides[1]; __pyx_t_11.suboffsets[0] = -1; -if (unlikely((__pyx_memoryview_copy_contents(__pyx_t_10, __pyx_t_11, 1, 1, 0) < 0))) __PYX_ERR(0, 259, __pyx_L1_error) +if (unlikely((__pyx_memoryview_copy_contents(__pyx_t_10, __pyx_t_11, 1, 1, 0) < 0))) __PYX_ERR(0, 258, __pyx_L1_error) __PYX_XCLEAR_MEMVIEW(&__pyx_t_11, 0); __pyx_t_11.memview = NULL; __pyx_t_11.data = NULL; __PYX_XCLEAR_MEMVIEW(&__pyx_t_10, 0); @@ -6990,7 +6990,7 @@ if (unlikely((__pyx_memoryview_copy_contents(__pyx_t_10, __pyx_t_11, 1, 1, 0) < __pyx_L5:; } - /* "plexsim/models/base.pyx":260 + /* "plexsim/models/base.pyx":259 * else: * self._memory[mi] = self._memory[mi - 1] * return # <<<<<<<<<<<<<< @@ -6999,7 +6999,7 @@ if (unlikely((__pyx_memoryview_copy_contents(__pyx_t_10, __pyx_t_11, 1, 1, 0) < */ goto __pyx_L0; - /* "plexsim/models/base.pyx":251 + /* "plexsim/models/base.pyx":250 * p[idx] += nudge * return p * cdef void _swap_memory(self) nogil: # <<<<<<<<<<<<<< @@ -7021,7 +7021,7 @@ if (unlikely((__pyx_memoryview_copy_contents(__pyx_t_10, __pyx_t_11, 1, 1, 0) < __pyx_L0:; } -/* "plexsim/models/base.pyx":263 +/* "plexsim/models/base.pyx":262 * * * cdef void _swap_buffers(self) nogil: # <<<<<<<<<<<<<< @@ -7031,7 +7031,7 @@ if (unlikely((__pyx_memoryview_copy_contents(__pyx_t_10, __pyx_t_11, 1, 1, 0) < static void __pyx_f_7plexsim_6models_4base_5Model__swap_buffers(struct __pyx_obj_7plexsim_6models_4base_Model *__pyx_v_self) { - /* "plexsim/models/base.pyx":268 + /* "plexsim/models/base.pyx":267 * This function is intended to allow for custom buffers update * """ * swap(self._states, self._newstates) # <<<<<<<<<<<<<< @@ -7040,7 +7040,7 @@ static void __pyx_f_7plexsim_6models_4base_5Model__swap_buffers(struct __pyx_obj */ std::swap<__pyx_t_7plexsim_6models_5types_state_t *>(__pyx_v_self->_states, __pyx_v_self->_newstates); - /* "plexsim/models/base.pyx":270 + /* "plexsim/models/base.pyx":269 * swap(self._states, self._newstates) * # default also swap the memory buffer if exists * self._swap_memory() # <<<<<<<<<<<<<< @@ -7049,7 +7049,7 @@ static void __pyx_f_7plexsim_6models_4base_5Model__swap_buffers(struct __pyx_obj */ ((struct __pyx_vtabstruct_7plexsim_6models_4base_Model *)__pyx_v_self->__pyx_vtab)->_swap_memory(__pyx_v_self); - /* "plexsim/models/base.pyx":271 + /* "plexsim/models/base.pyx":270 * # default also swap the memory buffer if exists * self._swap_memory() * return # <<<<<<<<<<<<<< @@ -7058,7 +7058,7 @@ static void __pyx_f_7plexsim_6models_4base_5Model__swap_buffers(struct __pyx_obj */ goto __pyx_L0; - /* "plexsim/models/base.pyx":263 + /* "plexsim/models/base.pyx":262 * * * cdef void _swap_buffers(self) nogil: # <<<<<<<<<<<<<< @@ -7070,7 +7070,7 @@ static void __pyx_f_7plexsim_6models_4base_5Model__swap_buffers(struct __pyx_obj __pyx_L0:; } -/* "plexsim/models/base.pyx":273 +/* "plexsim/models/base.pyx":272 * return * * cpdef public state_t[::1] updateState(self, node_id_t[::1] nodesToUpdate): # <<<<<<<<<<<<<< @@ -7108,7 +7108,7 @@ static __Pyx_memviewslice __pyx_f_7plexsim_6models_4base_5Model_updateState(stru if (unlikely(!__Pyx_object_dict_version_matches(((PyObject *)__pyx_v_self), __pyx_tp_dict_version, __pyx_obj_dict_version))) { PY_UINT64_T __pyx_typedict_guard = __Pyx_get_tp_dict_version(((PyObject *)__pyx_v_self)); #endif - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_updateState); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 273, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_updateState); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 272, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); #ifdef __Pyx_CyFunction_USED if (!__Pyx_IsCyOrPyCFunction(__pyx_t_1) @@ -7116,7 +7116,7 @@ static __Pyx_memviewslice __pyx_f_7plexsim_6models_4base_5Model_updateState(stru if (!PyCFunction_Check(__pyx_t_1) #endif || (PyCFunction_GET_FUNCTION(__pyx_t_1) != (PyCFunction)(void*)__pyx_pw_7plexsim_6models_4base_5Model_3updateState)) { - __pyx_t_3 = __pyx_memoryview_fromslice(__pyx_v_nodesToUpdate, 1, (PyObject *(*)(char *)) __pyx_memview_get_nn___pyx_t_7plexsim_6models_5types_node_id_t, (int (*)(char *, PyObject *)) __pyx_memview_set_nn___pyx_t_7plexsim_6models_5types_node_id_t, 0);; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 273, __pyx_L1_error) + __pyx_t_3 = __pyx_memoryview_fromslice(__pyx_v_nodesToUpdate, 1, (PyObject *(*)(char *)) __pyx_memview_get_nn___pyx_t_7plexsim_6models_5types_node_id_t, (int (*)(char *, PyObject *)) __pyx_memview_set_nn___pyx_t_7plexsim_6models_5types_node_id_t, 0);; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 272, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_INCREF(__pyx_t_1); __pyx_t_4 = __pyx_t_1; __pyx_t_5 = NULL; @@ -7136,11 +7136,11 @@ static __Pyx_memviewslice __pyx_f_7plexsim_6models_4base_5Model_updateState(stru __pyx_t_2 = __Pyx_PyObject_FastCall(__pyx_t_4, __pyx_callargs+1-__pyx_t_6, 1+__pyx_t_6); __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 273, __pyx_L1_error) + if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 272, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; } - __pyx_t_7 = __Pyx_PyObject_to_MemoryviewSlice_dc_nn___pyx_t_7plexsim_6models_5types_state_t(__pyx_t_2, PyBUF_WRITABLE); if (unlikely(!__pyx_t_7.memview)) __PYX_ERR(0, 273, __pyx_L1_error) + __pyx_t_7 = __Pyx_PyObject_to_MemoryviewSlice_dc_nn___pyx_t_7plexsim_6models_5types_state_t(__pyx_t_2, PyBUF_WRITABLE); if (unlikely(!__pyx_t_7.memview)) __PYX_ERR(0, 272, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_r = __pyx_t_7; __pyx_t_7.memview = NULL; @@ -7161,20 +7161,20 @@ static __Pyx_memviewslice __pyx_f_7plexsim_6models_4base_5Model_updateState(stru #endif } - /* "plexsim/models/base.pyx":277 + /* "plexsim/models/base.pyx":276 * General state updater wrapper * """ * return self._updateState(nodesToUpdate) # <<<<<<<<<<<<<< * * cdef public void _step(self, node_id_t node) nogil: */ - __pyx_t_7 = ((struct __pyx_vtabstruct_7plexsim_6models_4base_Model *)__pyx_v_self->__pyx_vtab)->_updateState(__pyx_v_self, __pyx_v_nodesToUpdate); if (unlikely(!__pyx_t_7.memview)) __PYX_ERR(0, 277, __pyx_L1_error) + __pyx_t_7 = ((struct __pyx_vtabstruct_7plexsim_6models_4base_Model *)__pyx_v_self->__pyx_vtab)->_updateState(__pyx_v_self, __pyx_v_nodesToUpdate); if (unlikely(!__pyx_t_7.memview)) __PYX_ERR(0, 276, __pyx_L1_error) __pyx_r = __pyx_t_7; __pyx_t_7.memview = NULL; __pyx_t_7.data = NULL; goto __pyx_L0; - /* "plexsim/models/base.pyx":273 + /* "plexsim/models/base.pyx":272 * return * * cpdef public state_t[::1] updateState(self, node_id_t[::1] nodesToUpdate): # <<<<<<<<<<<<<< @@ -7250,23 +7250,23 @@ PyObject *__pyx_args, PyObject *__pyx_kwds switch (__pyx_nargs) { case 0: if (likely((values[0] = __Pyx_GetKwValue_FASTCALL(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_nodesToUpdate)) != 0)) kw_args--; - else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 273, __pyx_L3_error) + else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 272, __pyx_L3_error) else goto __pyx_L5_argtuple_error; } if (unlikely(kw_args > 0)) { const Py_ssize_t kwd_pos_args = __pyx_nargs; - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_kwvalues, __pyx_pyargnames, 0, values + 0, kwd_pos_args, "updateState") < 0)) __PYX_ERR(0, 273, __pyx_L3_error) + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_kwvalues, __pyx_pyargnames, 0, values + 0, kwd_pos_args, "updateState") < 0)) __PYX_ERR(0, 272, __pyx_L3_error) } } else if (unlikely(__pyx_nargs != 1)) { goto __pyx_L5_argtuple_error; } else { values[0] = __Pyx_Arg_FASTCALL(__pyx_args, 0); } - __pyx_v_nodesToUpdate = __Pyx_PyObject_to_MemoryviewSlice_dc_nn___pyx_t_7plexsim_6models_5types_node_id_t(values[0], PyBUF_WRITABLE); if (unlikely(!__pyx_v_nodesToUpdate.memview)) __PYX_ERR(0, 273, __pyx_L3_error) + __pyx_v_nodesToUpdate = __Pyx_PyObject_to_MemoryviewSlice_dc_nn___pyx_t_7plexsim_6models_5types_node_id_t(values[0], PyBUF_WRITABLE); if (unlikely(!__pyx_v_nodesToUpdate.memview)) __PYX_ERR(0, 272, __pyx_L3_error) } goto __pyx_L4_argument_unpacking_done; __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("updateState", 1, 1, 1, __pyx_nargs); __PYX_ERR(0, 273, __pyx_L3_error) + __Pyx_RaiseArgtupleInvalid("updateState", 1, 1, 1, __pyx_nargs); __PYX_ERR(0, 272, __pyx_L3_error) __pyx_L3_error:; __Pyx_AddTraceback("plexsim.models.base.Model.updateState", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); @@ -7289,8 +7289,8 @@ static PyObject *__pyx_pf_7plexsim_6models_4base_5Model_2updateState(struct __py int __pyx_clineno = 0; __Pyx_RefNannySetupContext("updateState", 0); __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = __pyx_f_7plexsim_6models_4base_5Model_updateState(__pyx_v_self, __pyx_v_nodesToUpdate, 1); if (unlikely(!__pyx_t_1.memview)) __PYX_ERR(0, 273, __pyx_L1_error) - __pyx_t_2 = __pyx_memoryview_fromslice(__pyx_t_1, 1, (PyObject *(*)(char *)) __pyx_memview_get_nn___pyx_t_7plexsim_6models_5types_state_t, (int (*)(char *, PyObject *)) __pyx_memview_set_nn___pyx_t_7plexsim_6models_5types_state_t, 0);; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 273, __pyx_L1_error) + __pyx_t_1 = __pyx_f_7plexsim_6models_4base_5Model_updateState(__pyx_v_self, __pyx_v_nodesToUpdate, 1); if (unlikely(!__pyx_t_1.memview)) __PYX_ERR(0, 272, __pyx_L1_error) + __pyx_t_2 = __pyx_memoryview_fromslice(__pyx_t_1, 1, (PyObject *(*)(char *)) __pyx_memview_get_nn___pyx_t_7plexsim_6models_5types_state_t, (int (*)(char *, PyObject *)) __pyx_memview_set_nn___pyx_t_7plexsim_6models_5types_state_t, 0);; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 272, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __PYX_XCLEAR_MEMVIEW(&__pyx_t_1, 1); __pyx_t_1.memview = NULL; __pyx_t_1.data = NULL; @@ -7311,7 +7311,7 @@ static PyObject *__pyx_pf_7plexsim_6models_4base_5Model_2updateState(struct __py return __pyx_r; } -/* "plexsim/models/base.pyx":279 +/* "plexsim/models/base.pyx":278 * return self._updateState(nodesToUpdate) * * cdef public void _step(self, node_id_t node) nogil: # <<<<<<<<<<<<<< @@ -7321,16 +7321,16 @@ static PyObject *__pyx_pf_7plexsim_6models_4base_5Model_2updateState(struct __py static void __pyx_f_7plexsim_6models_4base_5Model__step(CYTHON_UNUSED struct __pyx_obj_7plexsim_6models_4base_Model *__pyx_v_self, CYTHON_UNUSED __pyx_t_7plexsim_6models_5types_node_id_t __pyx_v_node) { - /* "plexsim/models/base.pyx":280 + /* "plexsim/models/base.pyx":279 * * cdef public void _step(self, node_id_t node) nogil: * return # <<<<<<<<<<<<<< * - * cpdef node_id_t[:, ::1] sampleNodes(self, size_t nSamples): + * */ goto __pyx_L0; - /* "plexsim/models/base.pyx":279 + /* "plexsim/models/base.pyx":278 * return self._updateState(nodesToUpdate) * * cdef public void _step(self, node_id_t node) nogil: # <<<<<<<<<<<<<< @@ -7343,7 +7343,7 @@ static void __pyx_f_7plexsim_6models_4base_5Model__step(CYTHON_UNUSED struct __p } /* "plexsim/models/base.pyx":282 - * return + * * * cpdef node_id_t[:, ::1] sampleNodes(self, size_t nSamples): # <<<<<<<<<<<<<< * return self._sampleNodes(nSamples) @@ -7447,7 +7447,7 @@ static __Pyx_memviewslice __pyx_f_7plexsim_6models_4base_5Model_sampleNodes(stru goto __pyx_L0; /* "plexsim/models/base.pyx":282 - * return + * * * cpdef node_id_t[:, ::1] sampleNodes(self, size_t nSamples): # <<<<<<<<<<<<<< * return self._sampleNodes(nSamples) @@ -31770,7 +31770,7 @@ static __Pyx_StringTabEntry __pyx_string_tab[] = { }; /* #### Code section: cached_builtins ### */ static CYTHON_SMALL_CODE int __Pyx_InitCachedBuiltins(void) { - __pyx_builtin_range = __Pyx_GetBuiltinName(__pyx_n_s_range); if (!__pyx_builtin_range) __PYX_ERR(0, 140, __pyx_L1_error) + __pyx_builtin_range = __Pyx_GetBuiltinName(__pyx_n_s_range); if (!__pyx_builtin_range) __PYX_ERR(0, 139, __pyx_L1_error) __pyx_builtin_AssertionError = __Pyx_GetBuiltinName(__pyx_n_s_AssertionError); if (!__pyx_builtin_AssertionError) __PYX_ERR(0, 450, __pyx_L1_error) __pyx_builtin_ValueError = __Pyx_GetBuiltinName(__pyx_n_s_ValueError); if (!__pyx_builtin_ValueError) __PYX_ERR(0, 652, __pyx_L1_error) __pyx_builtin_id = __Pyx_GetBuiltinName(__pyx_n_s_id); if (!__pyx_builtin_id) __PYX_ERR(0, 661, __pyx_L1_error) @@ -31873,31 +31873,31 @@ static CYTHON_SMALL_CODE int __Pyx_InitCachedConstants(void) { __Pyx_GOTREF(__pyx_slice__19); __Pyx_GIVEREF(__pyx_slice__19); - /* "plexsim/models/base.pyx":67 + /* "plexsim/models/base.pyx":66 * * def __init__(self,\ * graph = nx.path_graph(1),\ # <<<<<<<<<<<<<< * agentStates = np.array([0], dtype = np.int),\ * nudgeType = "constant",\ */ - __pyx_tuple__22 = PyTuple_Pack(1, __pyx_int_1); if (unlikely(!__pyx_tuple__22)) __PYX_ERR(0, 67, __pyx_L1_error) + __pyx_tuple__22 = PyTuple_Pack(1, __pyx_int_1); if (unlikely(!__pyx_tuple__22)) __PYX_ERR(0, 66, __pyx_L1_error) __Pyx_GOTREF(__pyx_tuple__22); __Pyx_GIVEREF(__pyx_tuple__22); - /* "plexsim/models/base.pyx":273 + /* "plexsim/models/base.pyx":272 * return * * cpdef public state_t[::1] updateState(self, node_id_t[::1] nodesToUpdate): # <<<<<<<<<<<<<< * """ * General state updater wrapper */ - __pyx_tuple__23 = PyTuple_Pack(2, __pyx_n_s_self, __pyx_n_s_nodesToUpdate); if (unlikely(!__pyx_tuple__23)) __PYX_ERR(0, 273, __pyx_L1_error) + __pyx_tuple__23 = PyTuple_Pack(2, __pyx_n_s_self, __pyx_n_s_nodesToUpdate); if (unlikely(!__pyx_tuple__23)) __PYX_ERR(0, 272, __pyx_L1_error) __Pyx_GOTREF(__pyx_tuple__23); __Pyx_GIVEREF(__pyx_tuple__23); - __pyx_codeobj__24 = (PyObject*)__Pyx_PyCode_New(2, 0, 0, 2, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__23, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_plexsim_models_base_pyx, __pyx_n_s_updateState, 273, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__24)) __PYX_ERR(0, 273, __pyx_L1_error) + __pyx_codeobj__24 = (PyObject*)__Pyx_PyCode_New(2, 0, 0, 2, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__23, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_plexsim_models_base_pyx, __pyx_n_s_updateState, 272, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__24)) __PYX_ERR(0, 272, __pyx_L1_error) /* "plexsim/models/base.pyx":282 - * return + * * * cpdef node_id_t[:, ::1] sampleNodes(self, size_t nSamples): # <<<<<<<<<<<<<< * return self._sampleNodes(nSamples) @@ -32104,7 +32104,7 @@ if (unlikely(_import_array() == -1)) { PyErr_SetString(PyExc_ImportError, "numpy.core.multiarray failed to import " "(auto-generated because you didn't call 'numpy.import_array()' after cimporting numpy; " "use 'numpy._import_array' to disable if you are certain you don't need it)."); - __PYX_ERR(0, 5, __pyx_L1_error); + __PYX_ERR(0, 4, __pyx_L1_error); } #endif #endif @@ -32412,22 +32412,22 @@ static int __Pyx_modinit_type_init_code(void) { __pyx_vtable_7plexsim_6models_4base_Model._sample_proposal = (__pyx_t_7plexsim_6models_5types_state_t (*)(struct __pyx_obj_7plexsim_6models_4base_Model *))__pyx_f_7plexsim_6models_4base_5Model__sample_proposal; __pyx_vtable_7plexsim_6models_4base_Model.probability = (double (*)(struct __pyx_obj_7plexsim_6models_4base_Model *, __pyx_t_7plexsim_6models_5types_state_t, __pyx_t_7plexsim_6models_5types_node_id_t))__pyx_f_7plexsim_6models_4base_5Model_probability; #if CYTHON_USE_TYPE_SPECS - __pyx_ptype_7plexsim_6models_4base_Model = (PyTypeObject *) __Pyx_PyType_FromModuleAndSpec(__pyx_m, &__pyx_type_7plexsim_6models_4base_Model_spec, NULL); if (unlikely(!__pyx_ptype_7plexsim_6models_4base_Model)) __PYX_ERR(0, 30, __pyx_L1_error) - if (__Pyx_fix_up_extension_type_from_spec(&__pyx_type_7plexsim_6models_4base_Model_spec, __pyx_ptype_7plexsim_6models_4base_Model) < 0) __PYX_ERR(0, 30, __pyx_L1_error) + __pyx_ptype_7plexsim_6models_4base_Model = (PyTypeObject *) __Pyx_PyType_FromModuleAndSpec(__pyx_m, &__pyx_type_7plexsim_6models_4base_Model_spec, NULL); if (unlikely(!__pyx_ptype_7plexsim_6models_4base_Model)) __PYX_ERR(0, 29, __pyx_L1_error) + if (__Pyx_fix_up_extension_type_from_spec(&__pyx_type_7plexsim_6models_4base_Model_spec, __pyx_ptype_7plexsim_6models_4base_Model) < 0) __PYX_ERR(0, 29, __pyx_L1_error) #else __pyx_ptype_7plexsim_6models_4base_Model = &__pyx_type_7plexsim_6models_4base_Model; #endif #if !CYTHON_COMPILING_IN_LIMITED_API #endif #if !CYTHON_USE_TYPE_SPECS - if (__Pyx_PyType_Ready(__pyx_ptype_7plexsim_6models_4base_Model) < 0) __PYX_ERR(0, 30, __pyx_L1_error) + if (__Pyx_PyType_Ready(__pyx_ptype_7plexsim_6models_4base_Model) < 0) __PYX_ERR(0, 29, __pyx_L1_error) #endif #if PY_MAJOR_VERSION < 3 __pyx_ptype_7plexsim_6models_4base_Model->tp_print = 0; #endif #if CYTHON_COMPILING_IN_CPYTHON { - PyObject *wrapper = PyObject_GetAttrString((PyObject *)__pyx_ptype_7plexsim_6models_4base_Model, "__eq__"); if (unlikely(!wrapper)) __PYX_ERR(0, 30, __pyx_L1_error) + PyObject *wrapper = PyObject_GetAttrString((PyObject *)__pyx_ptype_7plexsim_6models_4base_Model, "__eq__"); if (unlikely(!wrapper)) __PYX_ERR(0, 29, __pyx_L1_error) if (__Pyx_IS_TYPE(wrapper, &PyWrapperDescr_Type)) { __pyx_wrapperbase_7plexsim_6models_4base_5Model_22__eq__ = *((PyWrapperDescrObject *)wrapper)->d_base; __pyx_wrapperbase_7plexsim_6models_4base_5Model_22__eq__.doc = __pyx_doc_7plexsim_6models_4base_5Model_22__eq__; @@ -32435,11 +32435,11 @@ static int __Pyx_modinit_type_init_code(void) { } } #endif - if (__Pyx_SetVtable(__pyx_ptype_7plexsim_6models_4base_Model, __pyx_vtabptr_7plexsim_6models_4base_Model) < 0) __PYX_ERR(0, 30, __pyx_L1_error) + if (__Pyx_SetVtable(__pyx_ptype_7plexsim_6models_4base_Model, __pyx_vtabptr_7plexsim_6models_4base_Model) < 0) __PYX_ERR(0, 29, __pyx_L1_error) #if !CYTHON_COMPILING_IN_LIMITED_API - if (__Pyx_MergeVtables(__pyx_ptype_7plexsim_6models_4base_Model) < 0) __PYX_ERR(0, 30, __pyx_L1_error) + if (__Pyx_MergeVtables(__pyx_ptype_7plexsim_6models_4base_Model) < 0) __PYX_ERR(0, 29, __pyx_L1_error) #endif - if (PyObject_SetAttr(__pyx_m, __pyx_n_s_Model, (PyObject *) __pyx_ptype_7plexsim_6models_4base_Model) < 0) __PYX_ERR(0, 30, __pyx_L1_error) + if (PyObject_SetAttr(__pyx_m, __pyx_n_s_Model, (PyObject *) __pyx_ptype_7plexsim_6models_4base_Model) < 0) __PYX_ERR(0, 29, __pyx_L1_error) __pyx_vtabptr_7plexsim_6models_4base_ModelMC = &__pyx_vtable_7plexsim_6models_4base_ModelMC; __pyx_vtable_7plexsim_6models_4base_ModelMC.__pyx_base = *__pyx_vtabptr_7plexsim_6models_4base_Model; #if CYTHON_USE_TYPE_SPECS @@ -32988,137 +32988,135 @@ if (!__Pyx_RefNanny) { if (__Pyx_patch_abc() < 0) __PYX_ERR(0, 1, __pyx_L1_error) #endif - /* "plexsim/models/base.pyx":2 - * #distutils: language=c++ + /* "plexsim/models/base.pyx":1 * import networkx as nx, functools, time, copy, sys, os # <<<<<<<<<<<<<< * import numpy as np, networkx as nx * from pyprind import ProgBar */ - __pyx_t_1 = __Pyx_ImportDottedModule(__pyx_n_s_networkx, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2, __pyx_L1_error) + __pyx_t_1 = __Pyx_ImportDottedModule(__pyx_n_s_networkx, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - if (PyDict_SetItem(__pyx_d, __pyx_n_s_nx, __pyx_t_1) < 0) __PYX_ERR(0, 2, __pyx_L1_error) + if (PyDict_SetItem(__pyx_d, __pyx_n_s_nx, __pyx_t_1) < 0) __PYX_ERR(0, 1, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = __Pyx_ImportDottedModule(__pyx_n_s_functools, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2, __pyx_L1_error) + __pyx_t_1 = __Pyx_ImportDottedModule(__pyx_n_s_functools, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - if (PyDict_SetItem(__pyx_d, __pyx_n_s_functools, __pyx_t_1) < 0) __PYX_ERR(0, 2, __pyx_L1_error) + if (PyDict_SetItem(__pyx_d, __pyx_n_s_functools, __pyx_t_1) < 0) __PYX_ERR(0, 1, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = __Pyx_ImportDottedModule(__pyx_n_s_time, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2, __pyx_L1_error) + __pyx_t_1 = __Pyx_ImportDottedModule(__pyx_n_s_time, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - if (PyDict_SetItem(__pyx_d, __pyx_n_s_time, __pyx_t_1) < 0) __PYX_ERR(0, 2, __pyx_L1_error) + if (PyDict_SetItem(__pyx_d, __pyx_n_s_time, __pyx_t_1) < 0) __PYX_ERR(0, 1, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = __Pyx_ImportDottedModule(__pyx_n_s_copy, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2, __pyx_L1_error) + __pyx_t_1 = __Pyx_ImportDottedModule(__pyx_n_s_copy, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - if (PyDict_SetItem(__pyx_d, __pyx_n_s_copy, __pyx_t_1) < 0) __PYX_ERR(0, 2, __pyx_L1_error) + if (PyDict_SetItem(__pyx_d, __pyx_n_s_copy, __pyx_t_1) < 0) __PYX_ERR(0, 1, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = __Pyx_ImportDottedModule(__pyx_n_s_sys, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2, __pyx_L1_error) + __pyx_t_1 = __Pyx_ImportDottedModule(__pyx_n_s_sys, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - if (PyDict_SetItem(__pyx_d, __pyx_n_s_sys, __pyx_t_1) < 0) __PYX_ERR(0, 2, __pyx_L1_error) + if (PyDict_SetItem(__pyx_d, __pyx_n_s_sys, __pyx_t_1) < 0) __PYX_ERR(0, 1, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = __Pyx_ImportDottedModule(__pyx_n_s_os, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2, __pyx_L1_error) + __pyx_t_1 = __Pyx_ImportDottedModule(__pyx_n_s_os, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - if (PyDict_SetItem(__pyx_d, __pyx_n_s_os, __pyx_t_1) < 0) __PYX_ERR(0, 2, __pyx_L1_error) + if (PyDict_SetItem(__pyx_d, __pyx_n_s_os, __pyx_t_1) < 0) __PYX_ERR(0, 1, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - /* "plexsim/models/base.pyx":3 - * #distutils: language=c++ + /* "plexsim/models/base.pyx":2 * import networkx as nx, functools, time, copy, sys, os * import numpy as np, networkx as nx # <<<<<<<<<<<<<< * from pyprind import ProgBar * cimport numpy as np, cython, openmp */ - __pyx_t_1 = __Pyx_ImportDottedModule(__pyx_n_s_numpy, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3, __pyx_L1_error) + __pyx_t_1 = __Pyx_ImportDottedModule(__pyx_n_s_numpy, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - if (PyDict_SetItem(__pyx_d, __pyx_n_s_np, __pyx_t_1) < 0) __PYX_ERR(0, 3, __pyx_L1_error) + if (PyDict_SetItem(__pyx_d, __pyx_n_s_np, __pyx_t_1) < 0) __PYX_ERR(0, 2, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = __Pyx_ImportDottedModule(__pyx_n_s_networkx, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3, __pyx_L1_error) + __pyx_t_1 = __Pyx_ImportDottedModule(__pyx_n_s_networkx, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - if (PyDict_SetItem(__pyx_d, __pyx_n_s_nx, __pyx_t_1) < 0) __PYX_ERR(0, 3, __pyx_L1_error) + if (PyDict_SetItem(__pyx_d, __pyx_n_s_nx, __pyx_t_1) < 0) __PYX_ERR(0, 2, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - /* "plexsim/models/base.pyx":4 + /* "plexsim/models/base.pyx":3 * import networkx as nx, functools, time, copy, sys, os * import numpy as np, networkx as nx * from pyprind import ProgBar # <<<<<<<<<<<<<< * cimport numpy as np, cython, openmp * */ - __pyx_t_1 = PyList_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 4, __pyx_L1_error) + __pyx_t_1 = PyList_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_INCREF(__pyx_n_s_ProgBar); __Pyx_GIVEREF(__pyx_n_s_ProgBar); PyList_SET_ITEM(__pyx_t_1, 0, __pyx_n_s_ProgBar); - __pyx_t_2 = __Pyx_Import(__pyx_n_s_pyprind, __pyx_t_1, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4, __pyx_L1_error) + __pyx_t_2 = __Pyx_Import(__pyx_n_s_pyprind, __pyx_t_1, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = __Pyx_ImportFrom(__pyx_t_2, __pyx_n_s_ProgBar); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 4, __pyx_L1_error) + __pyx_t_1 = __Pyx_ImportFrom(__pyx_t_2, __pyx_n_s_ProgBar); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - if (PyDict_SetItem(__pyx_d, __pyx_n_s_ProgBar, __pyx_t_1) < 0) __PYX_ERR(0, 4, __pyx_L1_error) + if (PyDict_SetItem(__pyx_d, __pyx_n_s_ProgBar, __pyx_t_1) < 0) __PYX_ERR(0, 3, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - /* "plexsim/models/base.pyx":22 + /* "plexsim/models/base.pyx":21 * from libc.math cimport exp, log, cos, pi, lround, fabs, isnan, signbit * #from alive_progress import alive_bar * import multiprocessing as mp # <<<<<<<<<<<<<< * * from posix.time cimport clock_gettime, timespec, CLOCK_REALTIME */ - __pyx_t_2 = __Pyx_ImportDottedModule(__pyx_n_s_multiprocessing, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 22, __pyx_L1_error) + __pyx_t_2 = __Pyx_ImportDottedModule(__pyx_n_s_multiprocessing, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 21, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); - if (PyDict_SetItem(__pyx_d, __pyx_n_s_mp, __pyx_t_2) < 0) __PYX_ERR(0, 22, __pyx_L1_error) + if (PyDict_SetItem(__pyx_d, __pyx_n_s_mp, __pyx_t_2) < 0) __PYX_ERR(0, 21, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - /* "plexsim/models/base.pyx":67 + /* "plexsim/models/base.pyx":66 * * def __init__(self,\ * graph = nx.path_graph(1),\ # <<<<<<<<<<<<<< * agentStates = np.array([0], dtype = np.int),\ * nudgeType = "constant",\ */ - __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_nx); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 67, __pyx_L1_error) + __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_nx); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 66, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_path_graph); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 67, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_path_graph); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 66, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_tuple__22, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 67, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_tuple__22, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 66, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_k_ = __pyx_t_2; __Pyx_GIVEREF(__pyx_t_2); __pyx_t_2 = 0; - /* "plexsim/models/base.pyx":68 + /* "plexsim/models/base.pyx":67 * def __init__(self,\ * graph = nx.path_graph(1),\ * agentStates = np.array([0], dtype = np.int),\ # <<<<<<<<<<<<<< * nudgeType = "constant",\ * updateType = "async",\ */ - __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_np); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 68, __pyx_L1_error) + __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_np); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 67, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_array); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 68, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_array); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 67, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = PyList_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 68, __pyx_L1_error) + __pyx_t_2 = PyList_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 67, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_INCREF(__pyx_int_0); __Pyx_GIVEREF(__pyx_int_0); PyList_SET_ITEM(__pyx_t_2, 0, __pyx_int_0); - __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 68, __pyx_L1_error) + __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 67, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_GIVEREF(__pyx_t_2); PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 68, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 67, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); - __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_np); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 68, __pyx_L1_error) + __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_np); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 67, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); - __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_int); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 68, __pyx_L1_error) + __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_int); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 67, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_dtype, __pyx_t_5) < 0) __PYX_ERR(0, 68, __pyx_L1_error) + if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_dtype, __pyx_t_5) < 0) __PYX_ERR(0, 67, __pyx_L1_error) __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_3, __pyx_t_2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 68, __pyx_L1_error) + __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_3, __pyx_t_2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 67, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; @@ -33127,53 +33125,53 @@ if (!__Pyx_RefNanny) { __Pyx_GIVEREF(__pyx_t_5); __pyx_t_5 = 0; - /* "plexsim/models/base.pyx":71 + /* "plexsim/models/base.pyx":70 * nudgeType = "constant",\ * updateType = "async",\ * nudges = {},\ # <<<<<<<<<<<<<< * seed = None,\ * memorySize = 0,\ */ - __pyx_t_5 = __Pyx_PyDict_NewPresized(0); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 71, __pyx_L1_error) + __pyx_t_5 = __Pyx_PyDict_NewPresized(0); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 70, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __pyx_k__3 = __pyx_t_5; __Pyx_GIVEREF(__pyx_t_5); __pyx_t_5 = 0; - /* "plexsim/models/base.pyx":77 + /* "plexsim/models/base.pyx":76 * memento = 0, * p_recomb = None,\ * rules = nx.Graph(),\ # <<<<<<<<<<<<<< * **kwargs,\ * ): */ - __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_nx); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 77, __pyx_L1_error) + __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_nx); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 76, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_Graph); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 77, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_Graph); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 76, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_t_5 = __Pyx_PyObject_CallNoArg(__pyx_t_2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 77, __pyx_L1_error) + __pyx_t_5 = __Pyx_PyObject_CallNoArg(__pyx_t_2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 76, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_k__4 = __pyx_t_5; __Pyx_GIVEREF(__pyx_t_5); __pyx_t_5 = 0; - /* "plexsim/models/base.pyx":273 + /* "plexsim/models/base.pyx":272 * return * * cpdef public state_t[::1] updateState(self, node_id_t[::1] nodesToUpdate): # <<<<<<<<<<<<<< * """ * General state updater wrapper */ - __pyx_t_5 = __Pyx_CyFunction_New(&__pyx_mdef_7plexsim_6models_4base_5Model_3updateState, __Pyx_CYFUNCTION_CCLASS, __pyx_n_s_Model_updateState, NULL, __pyx_n_s_plexsim_models_base, __pyx_d, ((PyObject *)__pyx_codeobj__24)); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 273, __pyx_L1_error) + __pyx_t_5 = __Pyx_CyFunction_New(&__pyx_mdef_7plexsim_6models_4base_5Model_3updateState, __Pyx_CYFUNCTION_CCLASS, __pyx_n_s_Model_updateState, NULL, __pyx_n_s_plexsim_models_base, __pyx_d, ((PyObject *)__pyx_codeobj__24)); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 272, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); - if (PyDict_SetItem((PyObject *)__pyx_ptype_7plexsim_6models_4base_Model->tp_dict, __pyx_n_s_updateState, __pyx_t_5) < 0) __PYX_ERR(0, 273, __pyx_L1_error) + if (PyDict_SetItem((PyObject *)__pyx_ptype_7plexsim_6models_4base_Model->tp_dict, __pyx_n_s_updateState, __pyx_t_5) < 0) __PYX_ERR(0, 272, __pyx_L1_error) __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; PyType_Modified(__pyx_ptype_7plexsim_6models_4base_Model); /* "plexsim/models/base.pyx":282 - * return + * * * cpdef node_id_t[:, ::1] sampleNodes(self, size_t nSamples): # <<<<<<<<<<<<<< * return self._sampleNodes(nSamples) @@ -33351,9 +33349,9 @@ if (!__Pyx_RefNanny) { __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; /* "plexsim/models/base.pyx":1 - * #distutils: language=c++ # <<<<<<<<<<<<<< - * import networkx as nx, functools, time, copy, sys, os + * import networkx as nx, functools, time, copy, sys, os # <<<<<<<<<<<<<< * import numpy as np, networkx as nx + * from pyprind import ProgBar */ __pyx_t_3 = __Pyx_PyDict_NewPresized(0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); diff --git a/plexsim/models/base.pyx b/plexsim/models/base.pyx index a6df6b0f..19f77a38 100644 --- a/plexsim/models/base.pyx +++ b/plexsim/models/base.pyx @@ -1,4 +1,3 @@ -#distutils: language=c++ import networkx as nx, functools, time, copy, sys, os import numpy as np, networkx as nx from pyprind import ProgBar @@ -279,6 +278,7 @@ cdef class Model: cdef public void _step(self, node_id_t node) nogil: return + cpdef node_id_t[:, ::1] sampleNodes(self, size_t nSamples): return self._sampleNodes(nSamples) diff --git a/plexsim/models/value_network_soc.cpp b/plexsim/models/value_network_soc.cpp index fdc0ae4d..fa509d84 100644 --- a/plexsim/models/value_network_soc.cpp +++ b/plexsim/models/value_network_soc.cpp @@ -5434,7 +5434,8 @@ static void __pyx_f_7plexsim_6models_17value_network_soc_5VNSoc__step(struct __p std::unordered_map<__pyx_t_7plexsim_6models_5types_node_id_t,__pyx_t_7plexsim_6models_5types_weight_t> ::iterator __pyx_v_it; int __pyx_t_1; Crawler *__pyx_t_2; - struct __pyx_opt_args_7plexsim_6models_9adjacency_9Adjacency__add_edge __pyx_t_3; + __pyx_t_7plexsim_6models_5types_node_id_t __pyx_t_3; + struct __pyx_opt_args_7plexsim_6models_9adjacency_9Adjacency__add_edge __pyx_t_4; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; @@ -5445,11 +5446,11 @@ static void __pyx_f_7plexsim_6models_17value_network_soc_5VNSoc__step(struct __p /* "plexsim/models/value_network_soc.pyx":80 * cdef Crawler *crawler * - * cdef size_t behavior = self._rng._rand() * 3 # <<<<<<<<<<<<<< + * cdef size_t behavior = (self._rng._rand() * 3) # <<<<<<<<<<<<<< * * # isolate */ - __pyx_v_behavior = (((size_t)((struct __pyx_vtabstruct_7plexsim_6models_7sampler_RandomGenerator *)__pyx_v_self->__pyx_base.__pyx_base.__pyx_base._rng->__pyx_vtab)->_rand(__pyx_v_self->__pyx_base.__pyx_base.__pyx_base._rng)) * 3); + __pyx_v_behavior = ((size_t)(((struct __pyx_vtabstruct_7plexsim_6models_7sampler_RandomGenerator *)__pyx_v_self->__pyx_base.__pyx_base.__pyx_base._rng->__pyx_vtab)->_rand(__pyx_v_self->__pyx_base.__pyx_base.__pyx_base._rng) * 3.0)); /* "plexsim/models/value_network_soc.pyx":83 * @@ -5550,8 +5551,8 @@ static void __pyx_f_7plexsim_6models_17value_network_soc_5VNSoc__step(struct __p * # made the if else separte to share the expensive crawler step * # shared code for next two steps * crawler = new Crawler(node, # <<<<<<<<<<<<<< - * self._states[node], - * self._bounded_rational, + * self._states[node], + * self._bounded_rational, */ try { __pyx_t_2 = new Crawler(__pyx_v_node, (__pyx_v_self->__pyx_base.__pyx_base.__pyx_base._states[__pyx_v_node]), __pyx_v_self->__pyx_base._bounded_rational, __pyx_v_self->__pyx_base._heuristic, 0); @@ -5568,33 +5569,43 @@ static void __pyx_f_7plexsim_6models_17value_network_soc_5VNSoc__step(struct __p __pyx_v_crawler = __pyx_t_2; /* "plexsim/models/value_network_soc.pyx":99 - * self._heuristic, - * False) + * self._heuristic, + * False) * self._check_df(crawler) # <<<<<<<<<<<<<< * completed_vns = crawler.results.size() - * del crawler + * self._completed_vns[node] = completed_vns */ (void)(((struct __pyx_vtabstruct_7plexsim_6models_17value_network_soc_VNSoc *)__pyx_v_self->__pyx_base.__pyx_base.__pyx_base.__pyx_vtab)->__pyx_base._check_df(((struct __pyx_obj_7plexsim_6models_13value_network_ValueNetwork *)__pyx_v_self), __pyx_v_crawler)); /* "plexsim/models/value_network_soc.pyx":100 - * False) + * False) * self._check_df(crawler) * completed_vns = crawler.results.size() # <<<<<<<<<<<<<< + * self._completed_vns[node] = completed_vns * del crawler - * */ __pyx_v_completed_vns = __pyx_v_crawler->results.size(); /* "plexsim/models/value_network_soc.pyx":101 * self._check_df(crawler) * completed_vns = crawler.results.size() + * self._completed_vns[node] = completed_vns # <<<<<<<<<<<<<< + * del crawler + * + */ + __pyx_t_3 = __pyx_v_node; + *((double *) ( /* dim=0 */ ((char *) (((double *) __pyx_v_self->_completed_vns.data) + __pyx_t_3)) )) = __pyx_v_completed_vns; + + /* "plexsim/models/value_network_soc.pyx":102 + * completed_vns = crawler.results.size() + * self._completed_vns[node] = completed_vns * del crawler # <<<<<<<<<<<<<< * * # explore */ delete __pyx_v_crawler; - /* "plexsim/models/value_network_soc.pyx":104 + /* "plexsim/models/value_network_soc.pyx":105 * * # explore * if behavior == 1: # <<<<<<<<<<<<<< @@ -5604,7 +5615,7 @@ static void __pyx_f_7plexsim_6models_17value_network_soc_5VNSoc__step(struct __p __pyx_t_1 = ((__pyx_v_behavior == 1) != 0); if (__pyx_t_1) { - /* "plexsim/models/value_network_soc.pyx":105 + /* "plexsim/models/value_network_soc.pyx":106 * # explore * if behavior == 1: * p_explore = exp(- self._explore_rate * completed_vns) # <<<<<<<<<<<<<< @@ -5613,7 +5624,7 @@ static void __pyx_f_7plexsim_6models_17value_network_soc_5VNSoc__step(struct __p */ __pyx_v_p_explore = exp(((-__pyx_v_self->_explore_rate) * __pyx_v_completed_vns)); - /* "plexsim/models/value_network_soc.pyx":106 + /* "plexsim/models/value_network_soc.pyx":107 * if behavior == 1: * p_explore = exp(- self._explore_rate * completed_vns) * if self._rng._rand() < p_explore: # <<<<<<<<<<<<<< @@ -5623,7 +5634,7 @@ static void __pyx_f_7plexsim_6models_17value_network_soc_5VNSoc__step(struct __p __pyx_t_1 = ((((struct __pyx_vtabstruct_7plexsim_6models_7sampler_RandomGenerator *)__pyx_v_self->__pyx_base.__pyx_base.__pyx_base._rng->__pyx_vtab)->_rand(__pyx_v_self->__pyx_base.__pyx_base.__pyx_base._rng) < __pyx_v_p_explore) != 0); if (__pyx_t_1) { - /* "plexsim/models/value_network_soc.pyx":107 + /* "plexsim/models/value_network_soc.pyx":108 * p_explore = exp(- self._explore_rate * completed_vns) * if self._rng._rand() < p_explore: * idx = (self._rng._rand() * self.adj._nNodes) # <<<<<<<<<<<<<< @@ -5632,18 +5643,18 @@ static void __pyx_f_7plexsim_6models_17value_network_soc_5VNSoc__step(struct __p */ __pyx_v_idx = ((__pyx_t_7plexsim_6models_5types_node_id_t)(((struct __pyx_vtabstruct_7plexsim_6models_7sampler_RandomGenerator *)__pyx_v_self->__pyx_base.__pyx_base.__pyx_base._rng->__pyx_vtab)->_rand(__pyx_v_self->__pyx_base.__pyx_base.__pyx_base._rng) * __pyx_v_self->__pyx_base.__pyx_base.__pyx_base.adj->_nNodes)); - /* "plexsim/models/value_network_soc.pyx":108 + /* "plexsim/models/value_network_soc.pyx":109 * if self._rng._rand() < p_explore: * idx = (self._rng._rand() * self.adj._nNodes) * self.adj._add_edge(node, idx, weight = self._w0) # <<<<<<<<<<<<<< * return * */ - __pyx_t_3.__pyx_n = 1; - __pyx_t_3.weight = __pyx_v_self->_w0; - ((struct __pyx_vtabstruct_7plexsim_6models_9adjacency_Adjacency *)__pyx_v_self->__pyx_base.__pyx_base.__pyx_base.adj->__pyx_vtab)->_add_edge(__pyx_v_self->__pyx_base.__pyx_base.__pyx_base.adj, __pyx_v_node, __pyx_v_idx, &__pyx_t_3); + __pyx_t_4.__pyx_n = 1; + __pyx_t_4.weight = __pyx_v_self->_w0; + ((struct __pyx_vtabstruct_7plexsim_6models_9adjacency_Adjacency *)__pyx_v_self->__pyx_base.__pyx_base.__pyx_base.adj->__pyx_vtab)->_add_edge(__pyx_v_self->__pyx_base.__pyx_base.__pyx_base.adj, __pyx_v_node, __pyx_v_idx, &__pyx_t_4); - /* "plexsim/models/value_network_soc.pyx":106 + /* "plexsim/models/value_network_soc.pyx":107 * if behavior == 1: * p_explore = exp(- self._explore_rate * completed_vns) * if self._rng._rand() < p_explore: # <<<<<<<<<<<<<< @@ -5652,7 +5663,7 @@ static void __pyx_f_7plexsim_6models_17value_network_soc_5VNSoc__step(struct __p */ } - /* "plexsim/models/value_network_soc.pyx":109 + /* "plexsim/models/value_network_soc.pyx":110 * idx = (self._rng._rand() * self.adj._nNodes) * self.adj._add_edge(node, idx, weight = self._w0) * return # <<<<<<<<<<<<<< @@ -5661,7 +5672,7 @@ static void __pyx_f_7plexsim_6models_17value_network_soc_5VNSoc__step(struct __p */ goto __pyx_L0; - /* "plexsim/models/value_network_soc.pyx":104 + /* "plexsim/models/value_network_soc.pyx":105 * * # explore * if behavior == 1: # <<<<<<<<<<<<<< @@ -5670,7 +5681,7 @@ static void __pyx_f_7plexsim_6models_17value_network_soc_5VNSoc__step(struct __p */ } - /* "plexsim/models/value_network_soc.pyx":112 + /* "plexsim/models/value_network_soc.pyx":113 * * # local search * if behavior == 2: # <<<<<<<<<<<<<< @@ -5680,7 +5691,7 @@ static void __pyx_f_7plexsim_6models_17value_network_soc_5VNSoc__step(struct __p __pyx_t_1 = ((__pyx_v_behavior == 2) != 0); if (__pyx_t_1) { - /* "plexsim/models/value_network_soc.pyx":113 + /* "plexsim/models/value_network_soc.pyx":114 * # local search * if behavior == 2: * p_local_search = completed_vns / self._theta # <<<<<<<<<<<<<< @@ -5689,7 +5700,7 @@ static void __pyx_f_7plexsim_6models_17value_network_soc_5VNSoc__step(struct __p */ __pyx_v_p_local_search = (((double)__pyx_v_completed_vns) / __pyx_v_self->_theta); - /* "plexsim/models/value_network_soc.pyx":114 + /* "plexsim/models/value_network_soc.pyx":115 * if behavior == 2: * p_local_search = completed_vns / self._theta * if self._rng._rand() < p_local_search: # <<<<<<<<<<<<<< @@ -5699,7 +5710,7 @@ static void __pyx_f_7plexsim_6models_17value_network_soc_5VNSoc__step(struct __p __pyx_t_1 = ((((struct __pyx_vtabstruct_7plexsim_6models_7sampler_RandomGenerator *)__pyx_v_self->__pyx_base.__pyx_base.__pyx_base._rng->__pyx_vtab)->_rand(__pyx_v_self->__pyx_base.__pyx_base.__pyx_base._rng) < __pyx_v_p_local_search) != 0); if (__pyx_t_1) { - /* "plexsim/models/value_network_soc.pyx":115 + /* "plexsim/models/value_network_soc.pyx":116 * p_local_search = completed_vns / self._theta * if self._rng._rand() < p_local_search: * self.adj._add_edge(node, self._local_search(node)) # <<<<<<<<<<<<<< @@ -5708,7 +5719,7 @@ static void __pyx_f_7plexsim_6models_17value_network_soc_5VNSoc__step(struct __p */ ((struct __pyx_vtabstruct_7plexsim_6models_9adjacency_Adjacency *)__pyx_v_self->__pyx_base.__pyx_base.__pyx_base.adj->__pyx_vtab)->_add_edge(__pyx_v_self->__pyx_base.__pyx_base.__pyx_base.adj, __pyx_v_node, ((struct __pyx_vtabstruct_7plexsim_6models_17value_network_soc_VNSoc *)__pyx_v_self->__pyx_base.__pyx_base.__pyx_base.__pyx_vtab)->_local_search(__pyx_v_self, __pyx_v_node), NULL); - /* "plexsim/models/value_network_soc.pyx":114 + /* "plexsim/models/value_network_soc.pyx":115 * if behavior == 2: * p_local_search = completed_vns / self._theta * if self._rng._rand() < p_local_search: # <<<<<<<<<<<<<< @@ -5717,7 +5728,7 @@ static void __pyx_f_7plexsim_6models_17value_network_soc_5VNSoc__step(struct __p */ } - /* "plexsim/models/value_network_soc.pyx":116 + /* "plexsim/models/value_network_soc.pyx":117 * if self._rng._rand() < p_local_search: * self.adj._add_edge(node, self._local_search(node)) * return # <<<<<<<<<<<<<< @@ -5726,7 +5737,7 @@ static void __pyx_f_7plexsim_6models_17value_network_soc_5VNSoc__step(struct __p */ goto __pyx_L0; - /* "plexsim/models/value_network_soc.pyx":112 + /* "plexsim/models/value_network_soc.pyx":113 * * # local search * if behavior == 2: # <<<<<<<<<<<<<< @@ -5756,7 +5767,7 @@ static void __pyx_f_7plexsim_6models_17value_network_soc_5VNSoc__step(struct __p __pyx_L0:; } -/* "plexsim/models/value_network_soc.pyx":118 +/* "plexsim/models/value_network_soc.pyx":119 * return * * cdef node_id_t _local_search(self, node_id_t node) nogil: # <<<<<<<<<<<<<< @@ -5773,7 +5784,7 @@ static __pyx_t_7plexsim_6models_5types_node_id_t __pyx_f_7plexsim_6models_17valu struct __pyx_opt_args_7plexsim_6models_17value_network_soc_5VNSoc__get_random_neighbor __pyx_t_2; int __pyx_t_3; - /* "plexsim/models/value_network_soc.pyx":119 + /* "plexsim/models/value_network_soc.pyx":120 * * cdef node_id_t _local_search(self, node_id_t node) nogil: * cdef node_id_t neighbor = self._get_random_neighbor(node, use_weight = True) # <<<<<<<<<<<<<< @@ -5785,7 +5796,7 @@ static __pyx_t_7plexsim_6models_5types_node_id_t __pyx_f_7plexsim_6models_17valu __pyx_t_1 = ((struct __pyx_vtabstruct_7plexsim_6models_17value_network_soc_VNSoc *)__pyx_v_self->__pyx_base.__pyx_base.__pyx_base.__pyx_vtab)->_get_random_neighbor(__pyx_v_self, __pyx_v_node, &__pyx_t_2); __pyx_v_neighbor = __pyx_t_1; - /* "plexsim/models/value_network_soc.pyx":120 + /* "plexsim/models/value_network_soc.pyx":121 * cdef node_id_t _local_search(self, node_id_t node) nogil: * cdef node_id_t neighbor = self._get_random_neighbor(node, use_weight = True) * cdef size_t idx = (self._rng._rand() * self.adj._adj[neighbor].neighbors.size()) # <<<<<<<<<<<<<< @@ -5794,7 +5805,7 @@ static __pyx_t_7plexsim_6models_5types_node_id_t __pyx_f_7plexsim_6models_17valu */ __pyx_v_idx = ((size_t)(((struct __pyx_vtabstruct_7plexsim_6models_7sampler_RandomGenerator *)__pyx_v_self->__pyx_base.__pyx_base.__pyx_base._rng->__pyx_vtab)->_rand(__pyx_v_self->__pyx_base.__pyx_base.__pyx_base._rng) * (__pyx_v_self->__pyx_base.__pyx_base.__pyx_base.adj->_adj[__pyx_v_neighbor]).neighbors.size())); - /* "plexsim/models/value_network_soc.pyx":121 + /* "plexsim/models/value_network_soc.pyx":122 * cdef node_id_t neighbor = self._get_random_neighbor(node, use_weight = True) * cdef size_t idx = (self._rng._rand() * self.adj._adj[neighbor].neighbors.size()) * it = self.adj._adj[neighbor].neighbors.begin() # <<<<<<<<<<<<<< @@ -5803,7 +5814,7 @@ static __pyx_t_7plexsim_6models_5types_node_id_t __pyx_f_7plexsim_6models_17valu */ __pyx_v_it = (__pyx_v_self->__pyx_base.__pyx_base.__pyx_base.adj->_adj[__pyx_v_neighbor]).neighbors.begin(); - /* "plexsim/models/value_network_soc.pyx":122 + /* "plexsim/models/value_network_soc.pyx":123 * cdef size_t idx = (self._rng._rand() * self.adj._adj[neighbor].neighbors.size()) * it = self.adj._adj[neighbor].neighbors.begin() * while idx > 0: # <<<<<<<<<<<<<< @@ -5814,7 +5825,7 @@ static __pyx_t_7plexsim_6models_5types_node_id_t __pyx_f_7plexsim_6models_17valu __pyx_t_3 = ((__pyx_v_idx > 0) != 0); if (!__pyx_t_3) break; - /* "plexsim/models/value_network_soc.pyx":123 + /* "plexsim/models/value_network_soc.pyx":124 * it = self.adj._adj[neighbor].neighbors.begin() * while idx > 0: * post(it) # <<<<<<<<<<<<<< @@ -5823,7 +5834,7 @@ static __pyx_t_7plexsim_6models_5types_node_id_t __pyx_f_7plexsim_6models_17valu */ (void)((__pyx_v_it++)); - /* "plexsim/models/value_network_soc.pyx":124 + /* "plexsim/models/value_network_soc.pyx":125 * while idx > 0: * post(it) * idx -= 1 # <<<<<<<<<<<<<< @@ -5833,7 +5844,7 @@ static __pyx_t_7plexsim_6models_5types_node_id_t __pyx_f_7plexsim_6models_17valu __pyx_v_idx = (__pyx_v_idx - 1); } - /* "plexsim/models/value_network_soc.pyx":125 + /* "plexsim/models/value_network_soc.pyx":126 * post(it) * idx -= 1 * return deref(it).first # <<<<<<<<<<<<<< @@ -5843,7 +5854,7 @@ static __pyx_t_7plexsim_6models_5types_node_id_t __pyx_f_7plexsim_6models_17valu __pyx_r = (*__pyx_v_it).first; goto __pyx_L0; - /* "plexsim/models/value_network_soc.pyx":118 + /* "plexsim/models/value_network_soc.pyx":119 * return * * cdef node_id_t _local_search(self, node_id_t node) nogil: # <<<<<<<<<<<<<< @@ -5856,7 +5867,7 @@ static __pyx_t_7plexsim_6models_5types_node_id_t __pyx_f_7plexsim_6models_17valu return __pyx_r; } -/* "plexsim/models/value_network_soc.pyx":127 +/* "plexsim/models/value_network_soc.pyx":128 * return deref(it).first * * cdef node_id_t _get_random_neighbor(self, # <<<<<<<<<<<<<< @@ -5866,7 +5877,7 @@ static __pyx_t_7plexsim_6models_5types_node_id_t __pyx_f_7plexsim_6models_17valu static __pyx_t_7plexsim_6models_5types_node_id_t __pyx_f_7plexsim_6models_17value_network_soc_5VNSoc__get_random_neighbor(struct __pyx_obj_7plexsim_6models_17value_network_soc_VNSoc *__pyx_v_self, __pyx_t_7plexsim_6models_5types_node_id_t __pyx_v_node, struct __pyx_opt_args_7plexsim_6models_17value_network_soc_5VNSoc__get_random_neighbor *__pyx_optional_args) { - /* "plexsim/models/value_network_soc.pyx":129 + /* "plexsim/models/value_network_soc.pyx":130 * cdef node_id_t _get_random_neighbor(self, * node_id_t node, * bint use_weight = True) nogil: # <<<<<<<<<<<<<< @@ -5898,7 +5909,7 @@ static __pyx_t_7plexsim_6models_5types_node_id_t __pyx_f_7plexsim_6models_17valu } } - /* "plexsim/models/value_network_soc.pyx":132 + /* "plexsim/models/value_network_soc.pyx":133 * cdef node_id_t idx * cdef vector[double] weight * cdef double z = 0 # <<<<<<<<<<<<<< @@ -5907,7 +5918,7 @@ static __pyx_t_7plexsim_6models_5types_node_id_t __pyx_f_7plexsim_6models_17valu */ __pyx_v_z = 0.0; - /* "plexsim/models/value_network_soc.pyx":134 + /* "plexsim/models/value_network_soc.pyx":135 * cdef double z = 0 * cdef double p, left_side, right_side * if use_weight: # <<<<<<<<<<<<<< @@ -5917,7 +5928,7 @@ static __pyx_t_7plexsim_6models_5types_node_id_t __pyx_f_7plexsim_6models_17valu __pyx_t_1 = (__pyx_v_use_weight != 0); if (__pyx_t_1) { - /* "plexsim/models/value_network_soc.pyx":136 + /* "plexsim/models/value_network_soc.pyx":137 * if use_weight: * # get edge weights * it = self.adj._adj[node].neighbors.begin() # <<<<<<<<<<<<<< @@ -5926,7 +5937,7 @@ static __pyx_t_7plexsim_6models_5types_node_id_t __pyx_f_7plexsim_6models_17valu */ __pyx_v_it = (__pyx_v_self->__pyx_base.__pyx_base.__pyx_base.adj->_adj[__pyx_v_node]).neighbors.begin(); - /* "plexsim/models/value_network_soc.pyx":137 + /* "plexsim/models/value_network_soc.pyx":138 * # get edge weights * it = self.adj._adj[node].neighbors.begin() * while it != self.adj._adj[node].neighbors.end(): # <<<<<<<<<<<<<< @@ -5937,7 +5948,7 @@ static __pyx_t_7plexsim_6models_5types_node_id_t __pyx_f_7plexsim_6models_17valu __pyx_t_1 = ((__pyx_v_it != (__pyx_v_self->__pyx_base.__pyx_base.__pyx_base.adj->_adj[__pyx_v_node]).neighbors.end()) != 0); if (!__pyx_t_1) break; - /* "plexsim/models/value_network_soc.pyx":138 + /* "plexsim/models/value_network_soc.pyx":139 * it = self.adj._adj[node].neighbors.begin() * while it != self.adj._adj[node].neighbors.end(): * weight.push_back(deref(it).second) # <<<<<<<<<<<<<< @@ -5954,10 +5965,10 @@ static __pyx_t_7plexsim_6models_5types_node_id_t __pyx_f_7plexsim_6models_17valu #ifdef WITH_THREAD __Pyx_PyGILState_Release(__pyx_gilstate_save); #endif - __PYX_ERR(0, 138, __pyx_L1_error) + __PYX_ERR(0, 139, __pyx_L1_error) } - /* "plexsim/models/value_network_soc.pyx":139 + /* "plexsim/models/value_network_soc.pyx":140 * while it != self.adj._adj[node].neighbors.end(): * weight.push_back(deref(it).second) * z += deref(it).second # <<<<<<<<<<<<<< @@ -5966,7 +5977,7 @@ static __pyx_t_7plexsim_6models_5types_node_id_t __pyx_f_7plexsim_6models_17valu */ __pyx_v_z = (__pyx_v_z + (*__pyx_v_it).second); - /* "plexsim/models/value_network_soc.pyx":140 + /* "plexsim/models/value_network_soc.pyx":141 * weight.push_back(deref(it).second) * z += deref(it).second * post(it) # <<<<<<<<<<<<<< @@ -5976,7 +5987,7 @@ static __pyx_t_7plexsim_6models_5types_node_id_t __pyx_f_7plexsim_6models_17valu (void)((__pyx_v_it++)); } - /* "plexsim/models/value_network_soc.pyx":143 + /* "plexsim/models/value_network_soc.pyx":144 * * * it = self.adj._adj[node].neighbors.begin() # <<<<<<<<<<<<<< @@ -5985,7 +5996,7 @@ static __pyx_t_7plexsim_6models_5types_node_id_t __pyx_f_7plexsim_6models_17valu */ __pyx_v_it = (__pyx_v_self->__pyx_base.__pyx_base.__pyx_base.adj->_adj[__pyx_v_node]).neighbors.begin(); - /* "plexsim/models/value_network_soc.pyx":144 + /* "plexsim/models/value_network_soc.pyx":145 * * it = self.adj._adj[node].neighbors.begin() * jt = weight.begin() # <<<<<<<<<<<<<< @@ -5994,7 +6005,7 @@ static __pyx_t_7plexsim_6models_5types_node_id_t __pyx_f_7plexsim_6models_17valu */ __pyx_v_jt = __pyx_v_weight.begin(); - /* "plexsim/models/value_network_soc.pyx":147 + /* "plexsim/models/value_network_soc.pyx":148 * * # create bin sides for cumulative * left_side = 0 # <<<<<<<<<<<<<< @@ -6003,7 +6014,7 @@ static __pyx_t_7plexsim_6models_5types_node_id_t __pyx_f_7plexsim_6models_17valu */ __pyx_v_left_side = 0.0; - /* "plexsim/models/value_network_soc.pyx":148 + /* "plexsim/models/value_network_soc.pyx":149 * # create bin sides for cumulative * left_side = 0 * right_side = 0 # <<<<<<<<<<<<<< @@ -6012,7 +6023,7 @@ static __pyx_t_7plexsim_6models_5types_node_id_t __pyx_f_7plexsim_6models_17valu */ __pyx_v_right_side = 0.0; - /* "plexsim/models/value_network_soc.pyx":149 + /* "plexsim/models/value_network_soc.pyx":150 * left_side = 0 * right_side = 0 * p = self._rng._rand() # draw rng # <<<<<<<<<<<<<< @@ -6021,7 +6032,7 @@ static __pyx_t_7plexsim_6models_5types_node_id_t __pyx_f_7plexsim_6models_17valu */ __pyx_v_p = ((struct __pyx_vtabstruct_7plexsim_6models_7sampler_RandomGenerator *)__pyx_v_self->__pyx_base.__pyx_base.__pyx_base._rng->__pyx_vtab)->_rand(__pyx_v_self->__pyx_base.__pyx_base.__pyx_base._rng); - /* "plexsim/models/value_network_soc.pyx":150 + /* "plexsim/models/value_network_soc.pyx":151 * right_side = 0 * p = self._rng._rand() # draw rng * while jt != weight.end(): # <<<<<<<<<<<<<< @@ -6032,7 +6043,7 @@ static __pyx_t_7plexsim_6models_5types_node_id_t __pyx_f_7plexsim_6models_17valu __pyx_t_1 = ((__pyx_v_jt != __pyx_v_weight.end()) != 0); if (!__pyx_t_1) break; - /* "plexsim/models/value_network_soc.pyx":151 + /* "plexsim/models/value_network_soc.pyx":152 * p = self._rng._rand() # draw rng * while jt != weight.end(): * right_side += deref(jt) # <<<<<<<<<<<<<< @@ -6041,7 +6052,7 @@ static __pyx_t_7plexsim_6models_5types_node_id_t __pyx_f_7plexsim_6models_17valu */ __pyx_v_right_side = (__pyx_v_right_side + (*__pyx_v_jt)); - /* "plexsim/models/value_network_soc.pyx":152 + /* "plexsim/models/value_network_soc.pyx":153 * while jt != weight.end(): * right_side += deref(jt) * if left_side < p < right_side: # <<<<<<<<<<<<<< @@ -6055,7 +6066,7 @@ static __pyx_t_7plexsim_6models_5types_node_id_t __pyx_f_7plexsim_6models_17valu __pyx_t_2 = (__pyx_t_1 != 0); if (__pyx_t_2) { - /* "plexsim/models/value_network_soc.pyx":153 + /* "plexsim/models/value_network_soc.pyx":154 * right_side += deref(jt) * if left_side < p < right_side: * break # <<<<<<<<<<<<<< @@ -6064,7 +6075,7 @@ static __pyx_t_7plexsim_6models_5types_node_id_t __pyx_f_7plexsim_6models_17valu */ goto __pyx_L7_break; - /* "plexsim/models/value_network_soc.pyx":152 + /* "plexsim/models/value_network_soc.pyx":153 * while jt != weight.end(): * right_side += deref(jt) * if left_side < p < right_side: # <<<<<<<<<<<<<< @@ -6073,7 +6084,7 @@ static __pyx_t_7plexsim_6models_5types_node_id_t __pyx_f_7plexsim_6models_17valu */ } - /* "plexsim/models/value_network_soc.pyx":154 + /* "plexsim/models/value_network_soc.pyx":155 * if left_side < p < right_side: * break * left_side += right_side # <<<<<<<<<<<<<< @@ -6082,7 +6093,7 @@ static __pyx_t_7plexsim_6models_5types_node_id_t __pyx_f_7plexsim_6models_17valu */ __pyx_v_left_side = (__pyx_v_left_side + __pyx_v_right_side); - /* "plexsim/models/value_network_soc.pyx":156 + /* "plexsim/models/value_network_soc.pyx":157 * left_side += right_side * # advance * post(it) # <<<<<<<<<<<<<< @@ -6091,7 +6102,7 @@ static __pyx_t_7plexsim_6models_5types_node_id_t __pyx_f_7plexsim_6models_17valu */ (void)((__pyx_v_it++)); - /* "plexsim/models/value_network_soc.pyx":157 + /* "plexsim/models/value_network_soc.pyx":158 * # advance * post(it) * post(jt) # <<<<<<<<<<<<<< @@ -6102,7 +6113,7 @@ static __pyx_t_7plexsim_6models_5types_node_id_t __pyx_f_7plexsim_6models_17valu } __pyx_L7_break:; - /* "plexsim/models/value_network_soc.pyx":158 + /* "plexsim/models/value_network_soc.pyx":159 * post(it) * post(jt) * idx = deref(it).first # <<<<<<<<<<<<<< @@ -6112,7 +6123,7 @@ static __pyx_t_7plexsim_6models_5types_node_id_t __pyx_f_7plexsim_6models_17valu __pyx_t_3 = (*__pyx_v_it).first; __pyx_v_idx = __pyx_t_3; - /* "plexsim/models/value_network_soc.pyx":134 + /* "plexsim/models/value_network_soc.pyx":135 * cdef double z = 0 * cdef double p, left_side, right_side * if use_weight: # <<<<<<<<<<<<<< @@ -6122,7 +6133,7 @@ static __pyx_t_7plexsim_6models_5types_node_id_t __pyx_f_7plexsim_6models_17valu goto __pyx_L3; } - /* "plexsim/models/value_network_soc.pyx":160 + /* "plexsim/models/value_network_soc.pyx":161 * idx = deref(it).first * else: * idx = (self._rng._rand() * self.adj._adj[node].neighbors.size()) # <<<<<<<<<<<<<< @@ -6132,7 +6143,7 @@ static __pyx_t_7plexsim_6models_5types_node_id_t __pyx_f_7plexsim_6models_17valu /*else*/ { __pyx_v_idx = ((__pyx_t_7plexsim_6models_5types_node_id_t)(((struct __pyx_vtabstruct_7plexsim_6models_7sampler_RandomGenerator *)__pyx_v_self->__pyx_base.__pyx_base.__pyx_base._rng->__pyx_vtab)->_rand(__pyx_v_self->__pyx_base.__pyx_base.__pyx_base._rng) * (__pyx_v_self->__pyx_base.__pyx_base.__pyx_base.adj->_adj[__pyx_v_node]).neighbors.size())); - /* "plexsim/models/value_network_soc.pyx":161 + /* "plexsim/models/value_network_soc.pyx":162 * else: * idx = (self._rng._rand() * self.adj._adj[node].neighbors.size()) * it = self.adj._adj[node].neighbors.begin() # <<<<<<<<<<<<<< @@ -6141,7 +6152,7 @@ static __pyx_t_7plexsim_6models_5types_node_id_t __pyx_f_7plexsim_6models_17valu */ __pyx_v_it = (__pyx_v_self->__pyx_base.__pyx_base.__pyx_base.adj->_adj[__pyx_v_node]).neighbors.begin(); - /* "plexsim/models/value_network_soc.pyx":162 + /* "plexsim/models/value_network_soc.pyx":163 * idx = (self._rng._rand() * self.adj._adj[node].neighbors.size()) * it = self.adj._adj[node].neighbors.begin() * while idx > 0: # <<<<<<<<<<<<<< @@ -6152,7 +6163,7 @@ static __pyx_t_7plexsim_6models_5types_node_id_t __pyx_f_7plexsim_6models_17valu __pyx_t_2 = ((__pyx_v_idx > 0) != 0); if (!__pyx_t_2) break; - /* "plexsim/models/value_network_soc.pyx":163 + /* "plexsim/models/value_network_soc.pyx":164 * it = self.adj._adj[node].neighbors.begin() * while idx > 0: * post(it) # <<<<<<<<<<<<<< @@ -6161,7 +6172,7 @@ static __pyx_t_7plexsim_6models_5types_node_id_t __pyx_f_7plexsim_6models_17valu */ (void)((__pyx_v_it++)); - /* "plexsim/models/value_network_soc.pyx":164 + /* "plexsim/models/value_network_soc.pyx":165 * while idx > 0: * post(it) * idx -= 1 # <<<<<<<<<<<<<< @@ -6171,7 +6182,7 @@ static __pyx_t_7plexsim_6models_5types_node_id_t __pyx_f_7plexsim_6models_17valu __pyx_v_idx = (__pyx_v_idx - 1); } - /* "plexsim/models/value_network_soc.pyx":165 + /* "plexsim/models/value_network_soc.pyx":166 * post(it) * idx -= 1 * idx = deref(it).first # <<<<<<<<<<<<<< @@ -6183,7 +6194,7 @@ static __pyx_t_7plexsim_6models_5types_node_id_t __pyx_f_7plexsim_6models_17valu } __pyx_L3:; - /* "plexsim/models/value_network_soc.pyx":166 + /* "plexsim/models/value_network_soc.pyx":167 * idx -= 1 * idx = deref(it).first * return idx # <<<<<<<<<<<<<< @@ -6193,7 +6204,7 @@ static __pyx_t_7plexsim_6models_5types_node_id_t __pyx_f_7plexsim_6models_17valu __pyx_r = __pyx_v_idx; goto __pyx_L0; - /* "plexsim/models/value_network_soc.pyx":127 + /* "plexsim/models/value_network_soc.pyx":128 * return deref(it).first * * cdef node_id_t _get_random_neighbor(self, # <<<<<<<<<<<<<< @@ -6215,7 +6226,7 @@ static __pyx_t_7plexsim_6models_5types_node_id_t __pyx_f_7plexsim_6models_17valu return __pyx_r; } -/* "plexsim/models/value_network_soc.pyx":169 +/* "plexsim/models/value_network_soc.pyx":170 * * # test functions * cpdef node_id_t local_search(self, node_id_t node): # <<<<<<<<<<<<<< @@ -6253,7 +6264,7 @@ static __pyx_t_7plexsim_6models_5types_node_id_t __pyx_f_7plexsim_6models_17valu if (unlikely(!__Pyx_object_dict_version_matches(((PyObject *)__pyx_v_self), __pyx_tp_dict_version, __pyx_obj_dict_version))) { PY_UINT64_T __pyx_typedict_guard = __Pyx_get_tp_dict_version(((PyObject *)__pyx_v_self)); #endif - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_local_search); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 169, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_local_search); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 170, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); #ifdef __Pyx_CyFunction_USED if (!__Pyx_IsCyOrPyCFunction(__pyx_t_1) @@ -6261,7 +6272,7 @@ static __pyx_t_7plexsim_6models_5types_node_id_t __pyx_f_7plexsim_6models_17valu if (!PyCFunction_Check(__pyx_t_1) #endif || (PyCFunction_GET_FUNCTION(__pyx_t_1) != (PyCFunction)(void*)__pyx_pw_7plexsim_6models_17value_network_soc_5VNSoc_3local_search)) { - __pyx_t_3 = __Pyx_PyInt_FromSize_t(__pyx_v_node); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 169, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyInt_FromSize_t(__pyx_v_node); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 170, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_INCREF(__pyx_t_1); __pyx_t_4 = __pyx_t_1; __pyx_t_5 = NULL; @@ -6281,11 +6292,11 @@ static __pyx_t_7plexsim_6models_5types_node_id_t __pyx_f_7plexsim_6models_17valu __pyx_t_2 = __Pyx_PyObject_FastCall(__pyx_t_4, __pyx_callargs+1-__pyx_t_6, 1+__pyx_t_6); __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 169, __pyx_L1_error) + if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 170, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; } - __pyx_t_7 = __Pyx_PyInt_As_size_t(__pyx_t_2); if (unlikely((__pyx_t_7 == (size_t)-1) && PyErr_Occurred())) __PYX_ERR(0, 169, __pyx_L1_error) + __pyx_t_7 = __Pyx_PyInt_As_size_t(__pyx_t_2); if (unlikely((__pyx_t_7 == (size_t)-1) && PyErr_Occurred())) __PYX_ERR(0, 170, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_r = __pyx_t_7; __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; @@ -6304,7 +6315,7 @@ static __pyx_t_7plexsim_6models_5types_node_id_t __pyx_f_7plexsim_6models_17valu #endif } - /* "plexsim/models/value_network_soc.pyx":170 + /* "plexsim/models/value_network_soc.pyx":171 * # test functions * cpdef node_id_t local_search(self, node_id_t node): * return self._local_search(node) # <<<<<<<<<<<<<< @@ -6314,7 +6325,7 @@ static __pyx_t_7plexsim_6models_5types_node_id_t __pyx_f_7plexsim_6models_17valu __pyx_r = ((struct __pyx_vtabstruct_7plexsim_6models_17value_network_soc_VNSoc *)__pyx_v_self->__pyx_base.__pyx_base.__pyx_base.__pyx_vtab)->_local_search(__pyx_v_self, __pyx_v_node); goto __pyx_L0; - /* "plexsim/models/value_network_soc.pyx":169 + /* "plexsim/models/value_network_soc.pyx":170 * * # test functions * cpdef node_id_t local_search(self, node_id_t node): # <<<<<<<<<<<<<< @@ -6383,23 +6394,23 @@ PyObject *__pyx_args, PyObject *__pyx_kwds switch (__pyx_nargs) { case 0: if (likely((values[0] = __Pyx_GetKwValue_FASTCALL(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_node)) != 0)) kw_args--; - else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 169, __pyx_L3_error) + else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 170, __pyx_L3_error) else goto __pyx_L5_argtuple_error; } if (unlikely(kw_args > 0)) { const Py_ssize_t kwd_pos_args = __pyx_nargs; - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_kwvalues, __pyx_pyargnames, 0, values + 0, kwd_pos_args, "local_search") < 0)) __PYX_ERR(0, 169, __pyx_L3_error) + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_kwvalues, __pyx_pyargnames, 0, values + 0, kwd_pos_args, "local_search") < 0)) __PYX_ERR(0, 170, __pyx_L3_error) } } else if (unlikely(__pyx_nargs != 1)) { goto __pyx_L5_argtuple_error; } else { values[0] = __Pyx_Arg_FASTCALL(__pyx_args, 0); } - __pyx_v_node = __Pyx_PyInt_As_size_t(values[0]); if (unlikely((__pyx_v_node == (size_t)-1) && PyErr_Occurred())) __PYX_ERR(0, 169, __pyx_L3_error) + __pyx_v_node = __Pyx_PyInt_As_size_t(values[0]); if (unlikely((__pyx_v_node == (size_t)-1) && PyErr_Occurred())) __PYX_ERR(0, 170, __pyx_L3_error) } goto __pyx_L4_argument_unpacking_done; __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("local_search", 1, 1, 1, __pyx_nargs); __PYX_ERR(0, 169, __pyx_L3_error) + __Pyx_RaiseArgtupleInvalid("local_search", 1, 1, 1, __pyx_nargs); __PYX_ERR(0, 170, __pyx_L3_error) __pyx_L3_error:; __Pyx_AddTraceback("plexsim.models.value_network_soc.VNSoc.local_search", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); @@ -6421,7 +6432,7 @@ static PyObject *__pyx_pf_7plexsim_6models_17value_network_soc_5VNSoc_2local_sea int __pyx_clineno = 0; __Pyx_RefNannySetupContext("local_search", 0); __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = __Pyx_PyInt_FromSize_t(__pyx_f_7plexsim_6models_17value_network_soc_5VNSoc_local_search(__pyx_v_self, __pyx_v_node, 1)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 169, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyInt_FromSize_t(__pyx_f_7plexsim_6models_17value_network_soc_5VNSoc_local_search(__pyx_v_self, __pyx_v_node, 1)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 170, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; @@ -6438,7 +6449,7 @@ static PyObject *__pyx_pf_7plexsim_6models_17value_network_soc_5VNSoc_2local_sea return __pyx_r; } -/* "plexsim/models/value_network_soc.pyx":172 +/* "plexsim/models/value_network_soc.pyx":173 * return self._local_search(node) * * cpdef node_id_t get_random_neighbor(self, node_id_t node, bint use_weight = False): # <<<<<<<<<<<<<< @@ -6483,7 +6494,7 @@ static __pyx_t_7plexsim_6models_5types_node_id_t __pyx_f_7plexsim_6models_17valu if (unlikely(!__Pyx_object_dict_version_matches(((PyObject *)__pyx_v_self), __pyx_tp_dict_version, __pyx_obj_dict_version))) { PY_UINT64_T __pyx_typedict_guard = __Pyx_get_tp_dict_version(((PyObject *)__pyx_v_self)); #endif - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_get_random_neighbor); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 172, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_get_random_neighbor); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 173, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); #ifdef __Pyx_CyFunction_USED if (!__Pyx_IsCyOrPyCFunction(__pyx_t_1) @@ -6491,9 +6502,9 @@ static __pyx_t_7plexsim_6models_5types_node_id_t __pyx_f_7plexsim_6models_17valu if (!PyCFunction_Check(__pyx_t_1) #endif || (PyCFunction_GET_FUNCTION(__pyx_t_1) != (PyCFunction)(void*)__pyx_pw_7plexsim_6models_17value_network_soc_5VNSoc_5get_random_neighbor)) { - __pyx_t_3 = __Pyx_PyInt_FromSize_t(__pyx_v_node); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 172, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyInt_FromSize_t(__pyx_v_node); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 173, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); - __pyx_t_4 = __Pyx_PyBool_FromLong(__pyx_v_use_weight); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 172, __pyx_L1_error) + __pyx_t_4 = __Pyx_PyBool_FromLong(__pyx_v_use_weight); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 173, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_INCREF(__pyx_t_1); __pyx_t_5 = __pyx_t_1; __pyx_t_6 = NULL; @@ -6514,11 +6525,11 @@ static __pyx_t_7plexsim_6models_5types_node_id_t __pyx_f_7plexsim_6models_17valu __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 172, __pyx_L1_error) + if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 173, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; } - __pyx_t_8 = __Pyx_PyInt_As_size_t(__pyx_t_2); if (unlikely((__pyx_t_8 == (size_t)-1) && PyErr_Occurred())) __PYX_ERR(0, 172, __pyx_L1_error) + __pyx_t_8 = __Pyx_PyInt_As_size_t(__pyx_t_2); if (unlikely((__pyx_t_8 == (size_t)-1) && PyErr_Occurred())) __PYX_ERR(0, 173, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_r = __pyx_t_8; __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; @@ -6537,7 +6548,7 @@ static __pyx_t_7plexsim_6models_5types_node_id_t __pyx_f_7plexsim_6models_17valu #endif } - /* "plexsim/models/value_network_soc.pyx":173 + /* "plexsim/models/value_network_soc.pyx":174 * * cpdef node_id_t get_random_neighbor(self, node_id_t node, bint use_weight = False): * return self._get_random_neighbor(node, use_weight) # <<<<<<<<<<<<<< @@ -6548,7 +6559,7 @@ static __pyx_t_7plexsim_6models_5types_node_id_t __pyx_f_7plexsim_6models_17valu __pyx_r = __pyx_t_8; goto __pyx_L0; - /* "plexsim/models/value_network_soc.pyx":172 + /* "plexsim/models/value_network_soc.pyx":173 * return self._local_search(node) * * cpdef node_id_t get_random_neighbor(self, node_id_t node, bint use_weight = False): # <<<<<<<<<<<<<< @@ -6620,19 +6631,19 @@ PyObject *__pyx_args, PyObject *__pyx_kwds switch (__pyx_nargs) { case 0: if (likely((values[0] = __Pyx_GetKwValue_FASTCALL(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_node)) != 0)) kw_args--; - else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 172, __pyx_L3_error) + else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 173, __pyx_L3_error) else goto __pyx_L5_argtuple_error; CYTHON_FALLTHROUGH; case 1: if (kw_args > 0) { PyObject* value = __Pyx_GetKwValue_FASTCALL(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_use_weight); if (value) { values[1] = value; kw_args--; } - else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 172, __pyx_L3_error) + else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 173, __pyx_L3_error) } } if (unlikely(kw_args > 0)) { const Py_ssize_t kwd_pos_args = __pyx_nargs; - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_kwvalues, __pyx_pyargnames, 0, values + 0, kwd_pos_args, "get_random_neighbor") < 0)) __PYX_ERR(0, 172, __pyx_L3_error) + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_kwvalues, __pyx_pyargnames, 0, values + 0, kwd_pos_args, "get_random_neighbor") < 0)) __PYX_ERR(0, 173, __pyx_L3_error) } } else { switch (__pyx_nargs) { @@ -6643,16 +6654,16 @@ PyObject *__pyx_args, PyObject *__pyx_kwds default: goto __pyx_L5_argtuple_error; } } - __pyx_v_node = __Pyx_PyInt_As_size_t(values[0]); if (unlikely((__pyx_v_node == (size_t)-1) && PyErr_Occurred())) __PYX_ERR(0, 172, __pyx_L3_error) + __pyx_v_node = __Pyx_PyInt_As_size_t(values[0]); if (unlikely((__pyx_v_node == (size_t)-1) && PyErr_Occurred())) __PYX_ERR(0, 173, __pyx_L3_error) if (values[1]) { - __pyx_v_use_weight = __Pyx_PyObject_IsTrue(values[1]); if (unlikely((__pyx_v_use_weight == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 172, __pyx_L3_error) + __pyx_v_use_weight = __Pyx_PyObject_IsTrue(values[1]); if (unlikely((__pyx_v_use_weight == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 173, __pyx_L3_error) } else { __pyx_v_use_weight = ((int)0); } } goto __pyx_L4_argument_unpacking_done; __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("get_random_neighbor", 0, 1, 2, __pyx_nargs); __PYX_ERR(0, 172, __pyx_L3_error) + __Pyx_RaiseArgtupleInvalid("get_random_neighbor", 0, 1, 2, __pyx_nargs); __PYX_ERR(0, 173, __pyx_L3_error) __pyx_L3_error:; __Pyx_AddTraceback("plexsim.models.value_network_soc.VNSoc.get_random_neighbor", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); @@ -6679,7 +6690,7 @@ static PyObject *__pyx_pf_7plexsim_6models_17value_network_soc_5VNSoc_4get_rando __pyx_t_2.__pyx_n = 1; __pyx_t_2.use_weight = __pyx_v_use_weight; __pyx_t_1 = __pyx_vtabptr_7plexsim_6models_17value_network_soc_VNSoc->get_random_neighbor(__pyx_v_self, __pyx_v_node, 1, &__pyx_t_2); - __pyx_t_3 = __Pyx_PyInt_FromSize_t(__pyx_t_1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 172, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyInt_FromSize_t(__pyx_t_1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 173, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_r = __pyx_t_3; __pyx_t_3 = 0; @@ -23291,29 +23302,29 @@ static CYTHON_SMALL_CODE int __Pyx_InitCachedConstants(void) { __Pyx_GOTREF(__pyx_tuple__11); __Pyx_GIVEREF(__pyx_tuple__11); - /* "plexsim/models/value_network_soc.pyx":169 + /* "plexsim/models/value_network_soc.pyx":170 * * # test functions * cpdef node_id_t local_search(self, node_id_t node): # <<<<<<<<<<<<<< * return self._local_search(node) * */ - __pyx_tuple__12 = PyTuple_Pack(2, __pyx_n_s_self, __pyx_n_s_node); if (unlikely(!__pyx_tuple__12)) __PYX_ERR(0, 169, __pyx_L1_error) + __pyx_tuple__12 = PyTuple_Pack(2, __pyx_n_s_self, __pyx_n_s_node); if (unlikely(!__pyx_tuple__12)) __PYX_ERR(0, 170, __pyx_L1_error) __Pyx_GOTREF(__pyx_tuple__12); __Pyx_GIVEREF(__pyx_tuple__12); - __pyx_codeobj__13 = (PyObject*)__Pyx_PyCode_New(2, 0, 0, 2, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__12, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_plexsim_models_value_network_soc, __pyx_n_s_local_search, 169, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__13)) __PYX_ERR(0, 169, __pyx_L1_error) + __pyx_codeobj__13 = (PyObject*)__Pyx_PyCode_New(2, 0, 0, 2, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__12, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_plexsim_models_value_network_soc, __pyx_n_s_local_search, 170, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__13)) __PYX_ERR(0, 170, __pyx_L1_error) - /* "plexsim/models/value_network_soc.pyx":172 + /* "plexsim/models/value_network_soc.pyx":173 * return self._local_search(node) * * cpdef node_id_t get_random_neighbor(self, node_id_t node, bint use_weight = False): # <<<<<<<<<<<<<< * return self._get_random_neighbor(node, use_weight) */ - __pyx_tuple__14 = PyTuple_Pack(3, __pyx_n_s_self, __pyx_n_s_node, __pyx_n_s_use_weight); if (unlikely(!__pyx_tuple__14)) __PYX_ERR(0, 172, __pyx_L1_error) + __pyx_tuple__14 = PyTuple_Pack(3, __pyx_n_s_self, __pyx_n_s_node, __pyx_n_s_use_weight); if (unlikely(!__pyx_tuple__14)) __PYX_ERR(0, 173, __pyx_L1_error) __Pyx_GOTREF(__pyx_tuple__14); __Pyx_GIVEREF(__pyx_tuple__14); - __pyx_codeobj__15 = (PyObject*)__Pyx_PyCode_New(3, 0, 0, 3, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__14, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_plexsim_models_value_network_soc, __pyx_n_s_get_random_neighbor, 172, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__15)) __PYX_ERR(0, 172, __pyx_L1_error) - __pyx_tuple__16 = PyTuple_Pack(1, Py_False); if (unlikely(!__pyx_tuple__16)) __PYX_ERR(0, 172, __pyx_L1_error) + __pyx_codeobj__15 = (PyObject*)__Pyx_PyCode_New(3, 0, 0, 3, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__14, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_plexsim_models_value_network_soc, __pyx_n_s_get_random_neighbor, 173, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__15)) __PYX_ERR(0, 173, __pyx_L1_error) + __pyx_tuple__16 = PyTuple_Pack(1, Py_False); if (unlikely(!__pyx_tuple__16)) __PYX_ERR(0, 173, __pyx_L1_error) __Pyx_GOTREF(__pyx_tuple__16); __Pyx_GIVEREF(__pyx_tuple__16); @@ -24252,29 +24263,29 @@ if (!__Pyx_RefNanny) { __Pyx_GIVEREF(__pyx_t_4); __pyx_t_4 = 0; - /* "plexsim/models/value_network_soc.pyx":169 + /* "plexsim/models/value_network_soc.pyx":170 * * # test functions * cpdef node_id_t local_search(self, node_id_t node): # <<<<<<<<<<<<<< * return self._local_search(node) * */ - __pyx_t_4 = __Pyx_CyFunction_New(&__pyx_mdef_7plexsim_6models_17value_network_soc_5VNSoc_3local_search, __Pyx_CYFUNCTION_CCLASS, __pyx_n_s_VNSoc_local_search, NULL, __pyx_n_s_plexsim_models_value_network_soc_2, __pyx_d, ((PyObject *)__pyx_codeobj__13)); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 169, __pyx_L1_error) + __pyx_t_4 = __Pyx_CyFunction_New(&__pyx_mdef_7plexsim_6models_17value_network_soc_5VNSoc_3local_search, __Pyx_CYFUNCTION_CCLASS, __pyx_n_s_VNSoc_local_search, NULL, __pyx_n_s_plexsim_models_value_network_soc_2, __pyx_d, ((PyObject *)__pyx_codeobj__13)); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 170, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); - if (PyDict_SetItem((PyObject *)__pyx_ptype_7plexsim_6models_17value_network_soc_VNSoc->tp_dict, __pyx_n_s_local_search, __pyx_t_4) < 0) __PYX_ERR(0, 169, __pyx_L1_error) + if (PyDict_SetItem((PyObject *)__pyx_ptype_7plexsim_6models_17value_network_soc_VNSoc->tp_dict, __pyx_n_s_local_search, __pyx_t_4) < 0) __PYX_ERR(0, 170, __pyx_L1_error) __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; PyType_Modified(__pyx_ptype_7plexsim_6models_17value_network_soc_VNSoc); - /* "plexsim/models/value_network_soc.pyx":172 + /* "plexsim/models/value_network_soc.pyx":173 * return self._local_search(node) * * cpdef node_id_t get_random_neighbor(self, node_id_t node, bint use_weight = False): # <<<<<<<<<<<<<< * return self._get_random_neighbor(node, use_weight) */ - __pyx_t_4 = __Pyx_CyFunction_New(&__pyx_mdef_7plexsim_6models_17value_network_soc_5VNSoc_5get_random_neighbor, __Pyx_CYFUNCTION_CCLASS, __pyx_n_s_VNSoc_get_random_neighbor, NULL, __pyx_n_s_plexsim_models_value_network_soc_2, __pyx_d, ((PyObject *)__pyx_codeobj__15)); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 172, __pyx_L1_error) + __pyx_t_4 = __Pyx_CyFunction_New(&__pyx_mdef_7plexsim_6models_17value_network_soc_5VNSoc_5get_random_neighbor, __Pyx_CYFUNCTION_CCLASS, __pyx_n_s_VNSoc_get_random_neighbor, NULL, __pyx_n_s_plexsim_models_value_network_soc_2, __pyx_d, ((PyObject *)__pyx_codeobj__15)); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 173, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_CyFunction_SetDefaultsTuple(__pyx_t_4, __pyx_tuple__16); - if (PyDict_SetItem((PyObject *)__pyx_ptype_7plexsim_6models_17value_network_soc_VNSoc->tp_dict, __pyx_n_s_get_random_neighbor, __pyx_t_4) < 0) __PYX_ERR(0, 172, __pyx_L1_error) + if (PyDict_SetItem((PyObject *)__pyx_ptype_7plexsim_6models_17value_network_soc_VNSoc->tp_dict, __pyx_n_s_get_random_neighbor, __pyx_t_4) < 0) __PYX_ERR(0, 173, __pyx_L1_error) __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; PyType_Modified(__pyx_ptype_7plexsim_6models_17value_network_soc_VNSoc); diff --git a/plexsim/utils/bundling.py b/plexsim/utils/bundling.py deleted file mode 100644 index 3fb2ed5f..00000000 --- a/plexsim/utils/bundling.py +++ /dev/null @@ -1,182 +0,0 @@ -# from datashader.bundling -# copied here as datashader was broken -class hammer_bundle(connect_edges): - """ - Iteratively group edges and return as paths suitable for datashading. - - Breaks each edge into a path with multiple line segments, and - iteratively curves this path to bundle edges into groups. - """ - - initial_bandwidth = param.Number( - default=0.05, - bounds=(0.0, None), - doc=""" - Initial value of the bandwidth....""", - ) - - decay = param.Number( - default=0.7, - bounds=(0.0, 1.0), - doc=""" - Rate of decay in the bandwidth value, with 1.0 indicating no decay.""", - ) - - iterations = param.Integer( - default=4, - bounds=(1, None), - doc=""" - Number of passes for the smoothing algorithm""", - ) - - batch_size = param.Integer( - default=20000, - bounds=(1, None), - doc=""" - Number of edges to process together""", - ) - - tension = param.Number( - default=0.3, - bounds=(0, None), - precedence=-0.5, - doc=""" - Exponential smoothing factor to use when smoothing""", - ) - - accuracy = param.Integer( - default=500, - bounds=(1, None), - precedence=-0.5, - doc=""" - Number of entries in table for...""", - ) - - advect_iterations = param.Integer( - default=50, - bounds=(0, None), - precedence=-0.5, - doc=""" - Number of iterations to move edges along gradients""", - ) - - min_segment_length = param.Number( - default=0.008, - bounds=(0, None), - precedence=-0.5, - doc=""" - Minimum length (in data space?) for an edge segment""", - ) - - max_segment_length = param.Number( - default=0.016, - bounds=(0, None), - precedence=-0.5, - doc=""" - Maximum length (in data space?) for an edge segment""", - ) - - weight = param.String( - default="weight", - allow_None=True, - doc=""" - Column name for each edge weight. If None, weights are ignored.""", - ) - - def __call__(self, nodes, edges, **params): - if skimage is None: - raise ImportError( - "hammer_bundle operation requires scikit-image. " - "Ensure you install the dependency before applying " - "bundling." - ) - - p = param.ParamOverrides(self, params) - - # Calculate min/max for coordinates - xmin, xmax = np.min(nodes[p.x]), np.max(nodes[p.x]) - ymin, ymax = np.min(nodes[p.y]), np.max(nodes[p.y]) - - # Normalize coordinates - nodes = nodes.copy() - nodes[p.x] = minmax_normalize(nodes[p.x], xmin, xmax) - nodes[p.y] = minmax_normalize(nodes[p.y], ymin, ymax) - - # Convert graph into list of edge segments - edges, segment_class = _convert_graph_to_edge_segments(nodes, edges, p) - - # This is simply to let the work split out over multiple cores - edge_batches = list(batches(edges, p.batch_size)) - - # This gets the edges split into lots of small segments - # Doing this inside a delayed function lowers the transmission overhead - edge_segments = [ - resample_edges( - batch, p.min_segment_length, p.max_segment_length, segment_class.ndims - ) - for batch in edge_batches - ] - - for i in range(p.iterations): - # Each step, the size of the 'blur' shrinks - bandwidth = p.initial_bandwidth * p.decay ** (i + 1) * p.accuracy - - # If it's this small, there won't be a change anyway - if bandwidth < 2: - break - - # Draw the density maps and combine them - images = [ - draw_to_surface( - segment, bandwidth, p.accuracy, segment_class.accumulate - ) - for segment in edge_segments - ] - overall_image = sum(images) - - gradients = get_gradients(overall_image) - - # Move edges along the gradients and resample when necessary - # This could include smoothing to adjust the amount a graph can change - edge_segments = [ - advect_resample_all( - gradients, - segment, - p.advect_iterations, - p.accuracy, - p.min_segment_length, - p.max_segment_length, - segment_class, - ) - for segment in edge_segments - ] - - # Do a final resample to a smaller size for nicer rendering - edge_segments = [ - resample_edges( - segment, p.min_segment_length, p.max_segment_length, segment_class.ndims - ) - for segment in edge_segments - ] - - # Finally things can be sent for computation - edge_segments = compute(*edge_segments) - - # Smooth out the graph - for i in range(10): - for batch in edge_segments: - smooth(batch, p.tension, segment_class.idx, segment_class.idy) - - # Flatten things - new_segs = [] - for batch in edge_segments: - new_segs.extend(batch) - - # Convert list of edge segments to Pandas dataframe - df = _convert_edge_segments_to_dataframe(new_segs, segment_class, p) - - # Denormalize coordinates - df[p.x] = minmax_denormalize(df[p.x], xmin, xmax) - df[p.y] = minmax_denormalize(df[p.y], ymin, ymax) - - return df diff --git a/requirements.txt b/requirements.txt index d448d88c..531b5dc8 100644 --- a/requirements.txt +++ b/requirements.txt @@ -4,4 +4,4 @@ scipy cython==3.0a8 scikit-learn pyprind -sphinx==4.0.0 +sphinx>=4.0.0 diff --git a/setup.py b/setup.py index 08e054b7..cffe712e 100644 --- a/setup.py +++ b/setup.py @@ -139,10 +139,12 @@ def TestSuite(): from sphinx.setup_command import BuildDoc name = "plexsim" -version = "2.0" +version = "3.0" packages = find_packages(include=["plexsim", "plexsim.*"], exclude=["bk/*", "bk"]) -print(packages) + +with open("requirements.txt", "r") as f: + required_packages = [i.rstrip() for i in f.readlines()] sphinx = dict( project=("setup.py", name), @@ -157,8 +159,12 @@ def TestSuite(): name=name, author="Casper van Elteren", author_email="caspervanelteren@gmail.com", - url="cvanelteren.githubio.io", - download_url="https://github.com/cvanelteren/PlexSim/archive/refs/tags/v2.5.tar.gz", + url="https://github.com/cvanelteren/plexsim", + keywords="Complex systems\tAgent-based simulations\tStatistical Physics".split( + "\t" + ), + description="Fast general toolbox for simulating complex systems", + download_url="https://github.com/cvanelteren/PlexSim/archive/refs/tags/v3.0.tar.gz", version=version, zip_safe=False, # package_dir = {"" : "plexsim"}, @@ -170,7 +176,7 @@ def TestSuite(): # data_files=data_files, data_files=package_data, packages=packages, - install_requires="cython numpy networkx".split(), + install_requires=required_packages, cmdclass=dict(build_sphinx=BuildDoc), command_options=dict(build_sphinx=sphinx), test_suite="tests",