Skip to content

Commit

Permalink
fix for networkx removal of random_tree
Browse files Browse the repository at this point in the history
  • Loading branch information
jcmgray committed Oct 28, 2024
1 parent ed35791 commit 9d86836
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
2 changes: 1 addition & 1 deletion quimb/tensor/geometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -542,7 +542,7 @@ def edges_3d_diamond_cubic(Lx, Ly, Lz, cyclic=False, cells=None):
def edges_tree_rand(n, max_degree=None, seed=None):
"""Return a random tree with ``n`` nodes. This a convenience function for
testing purposes and the trees generated are not guaranteed to be uniformly
random (for that see ``networkx.random_tree``).
random (for that see ``networkx.random_labeled_tree``).
Parameters
----------
Expand Down
12 changes: 8 additions & 4 deletions quimb/tensor/tensor_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@
from .tensor_3d import TensorNetwork3D, gen_3d_bonds, gen_3d_plaquettes
from .tensor_3d_tebd import LocalHam3D
from .tensor_arbgeom import (
create_lazy_edge_map,
TensorNetworkGen,
TensorNetworkGenOperator,
TensorNetworkGenVector,
create_lazy_edge_map,
)
from .tensor_core import (
COPY_tensor,
Expand Down Expand Up @@ -676,6 +676,7 @@ def TN_rand_tree(
n,
D,
phys_dim=None,
max_degree=None,
seed=None,
dtype="float64",
site_tag_id="I{}",
Expand All @@ -693,6 +694,10 @@ def TN_rand_tree(
phys_dim : int, optional
If not ``None``, give each tensor a 'physical', free index of this size
to mimic a wavefunction of ``n`` sites.
max_degree : int, optional
The maximum degree of any node in the tree, for example 3 means
that each tensor can connect to at most 3 other tensors - creating a
binary tree (1 parent and two children).
seed : int, optional
A random seed.
site_tag_id : str, optional
Expand All @@ -704,11 +709,10 @@ def TN_rand_tree(
-------
TensorNetworkGen, TensorNetworkGenVector or TensorNetworkGenOperator
"""
import networkx as nx
from .geometry import edges_tree_rand

G = nx.random_tree(n, seed=seed)
return TN_from_edges_rand(
G.edges,
edges=edges_tree_rand(n, max_degree=max_degree, seed=seed),
D=D,
phys_dim=phys_dim,
seed=seed,
Expand Down

0 comments on commit 9d86836

Please sign in to comment.