Skip to content

Commit

Permalink
chore: make allowed_intermediate states immutable
Browse files Browse the repository at this point in the history
Also fixes some of the naming: "particles" becomes "quantum_numbers"
  • Loading branch information
redeboer committed Mar 31, 2022
1 parent 7f9224d commit fa68acb
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/qrules/solving.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ def find_solutions(self, problem_set: QNProblemSet) -> QNResult:
def _merge_particle_candidates_with_solutions(
solutions: List[QuantumNumberSolution],
topology: Topology,
allowed_particles: List[GraphEdgePropertyMap],
allowed_quantum_numbers: Iterable[GraphEdgePropertyMap],
) -> List[QuantumNumberSolution]:
merged_solutions = []

Expand All @@ -257,7 +257,7 @@ def _merge_particle_candidates_with_solutions(
for int_edge_id in intermediate_edges:
particle_edges = __get_particle_candidates_for_state(
solution.states[int_edge_id],
allowed_particles,
allowed_quantum_numbers,
)
if len(particle_edges) == 0:
logging.debug("Did not find any particle candidates for")
Expand Down Expand Up @@ -287,11 +287,11 @@ def _merge_particle_candidates_with_solutions(

def __get_particle_candidates_for_state(
state: GraphEdgePropertyMap,
allowed_particles: List[GraphEdgePropertyMap],
allowed_quantum_numbers: Iterable[GraphEdgePropertyMap],
) -> List[GraphEdgePropertyMap]:
particle_edges = []

for particle_qns in allowed_particles:
for particle_qns in allowed_quantum_numbers:
if __is_sub_mapping(state, particle_qns):
particle_edges.append(particle_qns)

Expand Down Expand Up @@ -486,7 +486,7 @@ class CSPSolver(Solver):

# pylint: disable=too-many-instance-attributes
def __init__(
self, allowed_intermediate_particles: List[GraphEdgePropertyMap]
self, allowed_intermediate_states: Iterable[GraphEdgePropertyMap]
):
self.__variables: Set[
Union[_EdgeVariableInfo, _NodeVariableInfo]
Expand All @@ -503,7 +503,7 @@ def __init__(
int, Set[GraphElementRule]
] = defaultdict(set)
self.__problem = Problem(BacktrackingSolver(True))
self.__allowed_intermediate_particles = allowed_intermediate_particles
self.__allowed_intermediate_states = tuple(allowed_intermediate_states)
self.__scoresheet = Scoresheet()

def find_solutions(self, problem_set: QNProblemSet) -> QNResult:
Expand Down Expand Up @@ -541,7 +541,7 @@ def find_solutions(self, problem_set: QNProblemSet) -> QNResult:
_merge_particle_candidates_with_solutions(
solutions,
problem_set.topology,
self.__allowed_intermediate_particles,
self.__allowed_intermediate_states,
)
)
else:
Expand Down

0 comments on commit fa68acb

Please sign in to comment.