Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ def __init__(
resolution: float = 1,
community: list | None = None,
use_weights: bool = True,
version: str = "Advantage_system5.4",
region: str = "eu-central-1",
version: str | None = None,
region: str | None = None,
Comment on lines +14 to +15
Copy link
Copy Markdown
Collaborator

@basiav basiav Nov 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here ok, but args "version" and "region" have gotten lost in Advantage in QHyper kacper3615/bug_fixing, they are not used there. Looks like a small mistake after refactoring. I added a comment in the PR in QHyper. Make sure nothing else got lost in Advantage after refactor ;)

num_reads: int = 100,
chain_strength: float | None = None,
use_clique_embedding: bool = False,
Expand All @@ -28,9 +28,19 @@ def __init__(
self.chain_strength = chain_strength
self.use_clique_embedding = use_clique_embedding
self._use_weights = use_weights

weight = "weight" if use_weights else None
network = Network(G, resolution=resolution, weight=weight, community=community)

if not hasattr(self, "_full_modularity_matrix"):
self._full_modularity_matrix = Network(
G, resolution=resolution, weight=weight, community=community
).calculate_full_modularity_matrix()
network = Network(
G,
resolution=resolution,
weight=weight,
community=community,
full_modularity_matrix=self._full_modularity_matrix,
)
Comment on lines +32 to +43
Copy link
Copy Markdown
Collaborator

@basiav basiav Nov 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool. However GurobiSampler needs it, as well. How about adding this code as a method to the abstract class (HierarchicalSampler)? As an optional method (without "@ abstractmethod") with default implementation?
obraz

By the way, I think self.weight can be saved as an attribute in AdvantageSampler and GurobiSampler, "community" would stay then as the only argument that isn't saved (cannot be) and is special. Self.weights can be saved I think.

problem = CommunityDetectionProblem(
network, communities=2, one_hot_encoding=False
)
Expand Down
2 changes: 1 addition & 1 deletion Qommunity/samplers/regular/dqm_sampler/dqm_sampler.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from QHyper.solvers.quantum_annealing.dqm import DQM
from QHyper.solvers.quantum_annealing.dwave.dqm import DQM
from QHyper.problems.community_detection import Network, CommunityDetectionProblem
import networkx as nx
from ..regular_sampler import RegularSampler
Expand Down
16 changes: 11 additions & 5 deletions Qommunity/searchers/hierarchical_searcher/hierarchical_searcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ def _hierarchical_search_recursion(
if not community:
community = [*range(self.sampler.G.number_of_nodes())]

if len(community) == 1:
if len(community) < 2:
return [community]

if level == 1 and division_tree == []:
Expand All @@ -153,10 +153,16 @@ def _hierarchical_search_recursion(
)
print("===========================================")

self.sampler.update_community(community)
sample = self.sampler.sample_qubo_to_dict()

c0, c1 = self._split_dict_to_lists(sample, community)
try:
self.sampler.update_community(community)
sample = self.sampler.sample_qubo_to_dict()
c0, c1 = self._split_dict_to_lists(sample, community)
except Exception as e:
if verbosity >= 1:
print(
f"[WARNING] Skipping community {community} at level {level} due to error: {e}"
)
return [community]

if verbosity >= 2:
print("Base community:", community, sep="\n")
Expand Down
Loading