<｜begin▁of▁sentence｜>### Instruction:
A sociologist working on a network analysis project is interested in exploring the community structures within a social network that expands beyond regular community detection algorithms. The social network is comprised of 30 individuals, and the interactions between them vary in frequency and intensity, represented by weighted edges. The sociologist needs to identify not just the immediate community structures but also wants to explore potential sub-communities within larger communities, ensuring that the partition sizes do not exceed a certain threshold. The partitioning should provide community levels reflecting the hierarchical structure and indicate when there can be no further subdivision.
### Response:
import networkx as nx
from graspologic.partition import hierarchical_leiden
import numpy as np

# Step 1: Construct a synthetic social network graph
G = nx.Graph()
nodes = range(30)
# Create a graph with random weighted edges and some likelihood of edge creation
edges = [(i, j, {'weight': np.random.rand()}) for i in nodes for j in nodes if i < j and np.random.rand() > 0.6]
G.add_nodes_from(nodes)
G.add_edges_from(edges)

# Step 2: Use hierarchical Leiden algorithm to find communities
hierarchical_clusters = hierarchical_leiden(graph=G, max_cluster_size=10, random_seed=42)

# Print the community assignment for each node at each level
for hc in hierarchical_clusters:
  print(f'Node {hc.node_id}: Community {hc.cluster_id} at level {hc.level} - Final: {hc.is_final_cluster}')
<|EOT|>
