-
Notifications
You must be signed in to change notification settings - Fork 5
FEAT: implement quantum problem set filter #278
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
f190b2f
Added '*.swp' (temporary vim-files) to .gitignore
grayson-helmholz 67b6747
Added test-skeleton for Issue#272
grayson-helmholz 631f692
created QNP-setter and its test
grayson-helmholz c18d411
inlined fixture-arguments, function-renaming
grayson-helmholz 5a997d0
iss272: faulty filters for QNProblemSet
grayson-helmholz ad5ea05
FIX: stabilize test fixture
redeboer 6fbf83b
added pid&spin_projection -> non-zero results
grayson-helmholz 557ec57
cleanup of test_solving.py
grayson-helmholz e54289e
changed tuple to set in test-case
grayson-helmholz b99bcdc
Merge branch 'main' into filter_quantum_numbers
grayson-helmholz 99a594d
got the test_solving.py from old branch: remove_spin-proj[...]
grayson-helmholz 559b2f4
moved Edge/NodeQuantumNumberTypes to quantum_numbers.py
grayson-helmholz 2808ed7
domain-keys now have specific type
grayson-helmholz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,6 +37,7 @@ oryx-build-commands.txt | |
prof/ | ||
tags | ||
TAGS | ||
*.swp | ||
|
||
# Virtual environments | ||
*venv/ | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,160 @@ | ||
from __future__ import annotations | ||
|
||
from typing import TYPE_CHECKING, Iterable | ||
|
||
import attrs | ||
import pytest | ||
|
||
import qrules.particle | ||
import qrules.quantum_numbers | ||
import qrules.system_control | ||
import qrules.transition | ||
from qrules.conservation_rules import ( | ||
GraphElementRule, | ||
c_parity_conservation, | ||
parity_conservation, | ||
spin_magnitude_conservation, | ||
spin_validity, | ||
) | ||
from qrules.quantum_numbers import ( | ||
EdgeQuantumNumbers, | ||
EdgeQuantumNumberTypes, | ||
NodeQuantumNumbers, | ||
NodeQuantumNumberTypes, | ||
) | ||
from qrules.solving import CSPSolver, EdgeSettings, NodeSettings, QNProblemSet | ||
from qrules.topology import MutableTransition | ||
|
||
if TYPE_CHECKING: | ||
from qrules.argument_handling import Rule | ||
|
||
|
||
def test_solve( | ||
all_particles: qrules.particle.ParticleCollection, | ||
quantum_number_problem_set: QNProblemSet, | ||
) -> None: | ||
solver = CSPSolver(all_particles) | ||
result = solver.find_solutions(quantum_number_problem_set) | ||
assert len(result.solutions) == 19 | ||
|
||
|
||
def test_solve_with_filtered_quantum_number_problem_set( | ||
all_particles: qrules.particle.ParticleCollection, | ||
quantum_number_problem_set: QNProblemSet, | ||
) -> None: | ||
solver = CSPSolver(all_particles) | ||
redeboer marked this conversation as resolved.
Show resolved
Hide resolved
|
||
new_quantum_number_problem_set = filter_quantum_number_problem_set( | ||
quantum_number_problem_set, | ||
edge_rules={spin_validity}, | ||
node_rules={ | ||
spin_magnitude_conservation, | ||
parity_conservation, | ||
c_parity_conservation, | ||
}, | ||
edge_properties_and_domains={ | ||
EdgeQuantumNumbers.pid, # had to be added for c_parity_conservation to work | ||
EdgeQuantumNumbers.spin_magnitude, | ||
# EdgeQuantumNumbers.spin_projection, # can be left out to reduce the number of solutions | ||
EdgeQuantumNumbers.parity, | ||
EdgeQuantumNumbers.c_parity, | ||
}, | ||
node_properties_and_domains=( | ||
NodeQuantumNumbers.l_magnitude, | ||
NodeQuantumNumbers.s_magnitude, | ||
), | ||
) | ||
result = solver.find_solutions(new_quantum_number_problem_set) | ||
|
||
assert len(result.solutions) != 0 | ||
redeboer marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
|
||
def filter_quantum_number_problem_set( | ||
quantum_number_problem_set: QNProblemSet, | ||
edge_rules: set[GraphElementRule], | ||
node_rules: set[Rule], | ||
edge_properties_and_domains: Iterable[EdgeQuantumNumberTypes], | ||
node_properties_and_domains: Iterable[NodeQuantumNumberTypes], | ||
) -> QNProblemSet: | ||
old_edge_settings = quantum_number_problem_set.solving_settings.states | ||
old_node_settings = quantum_number_problem_set.solving_settings.interactions | ||
old_edge_properties = quantum_number_problem_set.initial_facts.states | ||
old_node_properties = quantum_number_problem_set.initial_facts.interactions | ||
new_edge_settings = { | ||
edge_id: EdgeSettings( | ||
conservation_rules=edge_rules, | ||
rule_priorities=edge_setting.rule_priorities, | ||
qn_domains=({ | ||
key: val | ||
for key, val in edge_setting.qn_domains.items() | ||
if key in set(edge_properties_and_domains) | ||
}), | ||
) | ||
for edge_id, edge_setting in old_edge_settings.items() | ||
} | ||
new_node_settings = { | ||
node_id: NodeSettings( | ||
conservation_rules=node_rules, | ||
rule_priorities=node_setting.rule_priorities, | ||
qn_domains=({ | ||
key: val | ||
for key, val in node_setting.qn_domains.items() | ||
if key in set(node_properties_and_domains) | ||
}), | ||
) | ||
for node_id, node_setting in old_node_settings.items() | ||
} | ||
new_combined_settings = MutableTransition( | ||
topology=quantum_number_problem_set.solving_settings.topology, | ||
states=new_edge_settings, | ||
interactions=new_node_settings, | ||
) | ||
new_edge_properties = { | ||
edge_id: { | ||
edge_quantum_number: scalar | ||
for edge_quantum_number, scalar in graph_edge_property_map.items() | ||
if edge_quantum_number in edge_properties_and_domains | ||
} | ||
for edge_id, graph_edge_property_map in old_edge_properties.items() | ||
} | ||
new_node_properties = { | ||
node_id: { | ||
node_quantum_number: scalar | ||
for node_quantum_number, scalar in graph_node_property_map.items() | ||
if node_quantum_number in node_properties_and_domains | ||
} | ||
for node_id, graph_node_property_map in old_node_properties.items() | ||
} | ||
new_combined_properties = MutableTransition( | ||
topology=quantum_number_problem_set.initial_facts.topology, | ||
states=new_edge_properties, | ||
interactions=new_node_properties, | ||
) | ||
return attrs.evolve( | ||
quantum_number_problem_set, | ||
solving_settings=new_combined_settings, | ||
initial_facts=new_combined_properties, | ||
) | ||
|
||
|
||
@pytest.fixture(scope="session") | ||
def all_particles(): | ||
return [ | ||
qrules.system_control.create_edge_properties(part) | ||
for part in qrules.particle.load_pdg() | ||
] | ||
|
||
|
||
@pytest.fixture(scope="session") | ||
def quantum_number_problem_set() -> QNProblemSet: | ||
stm = qrules.StateTransitionManager( | ||
initial_state=["psi(2S)"], | ||
final_state=["gamma", "eta", "eta"], | ||
formalism="helicity", | ||
) | ||
problem_sets = stm.create_problem_sets() | ||
qn_problem_sets = [ | ||
p.to_qn_problem_set() | ||
for strength in sorted(problem_sets) | ||
for p in problem_sets[strength] | ||
redeboer marked this conversation as resolved.
Show resolved
Hide resolved
|
||
] | ||
return qn_problem_sets[0] |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.