solving

Functions to solve a particle reaction problem.

This module is responsible for solving a particle reaction problem stated by a StateTransitionGraph and corresponding GraphSettings. The Solver classes (e.g. CSPSolver) generate new quantum numbers (for example belonging to an intermediate state) and validate the decay processes with the rules formulated by the conservation_rules module.

class CSPSolver(allowed_intermediate_particles: expertsystem.particle.ParticleCollection)[source]

Bases: expertsystem.reaction.solving.Solver

Solver reducing the task to a Constraint Satisfaction Problem.

Solving this done with the python-constraint module.

The variables are the quantum numbers of particles/edges, but also some composite quantum numbers which are attributed to the interaction nodes (such as angular momentum \(L\)). The conservation rules serve as the constraints and a special wrapper class serves as an adapter.

find_solutions(graph: expertsystem.reaction.topology.StateTransitionGraph[Tuple[expertsystem.particle.Particle, float]], graph_settings: expertsystem.reaction.solving.GraphSettings)expertsystem.reaction.solving.Result[source]

Find solutions for the given input.

It is expected that this function determines and returns all of the found solutions. In case no solutions are found a partial list of violated rules has to be given. This list of violated rules does not have to be complete.

Parameters
  • graph – a StateTransitionGraph which contains all of the known facts quantum numbers of the problem.

  • edge_settings – mapping of edge id’s to EdgeSettings, that assigns specific rules and variable domains to an edge of the graph.

  • node_settings – mapping of node id’s to NodeSettings, that assigns specific rules and variable domains to a node of the graph.

Returns

contains possible solutions, violated rules and not executed rules due to requirement issues.

Return type

Result

class EdgeSettings(conservation_rules: Set[expertsystem.reaction.conservation_rules.GraphElementRule] = NOTHING, rule_priorities: Dict[expertsystem.reaction.conservation_rules.GraphElementRule, int] = NOTHING, qn_domains: Dict[Any, Any] = NOTHING)[source]

Bases: object

Solver settings for a specific edge of a graph.

__eq__(other)

Method generated by attrs for class EdgeSettings.

conservation_rules: Set[expertsystem.reaction.conservation_rules.GraphElementRule]
qn_domains: Dict[Any, Any]
rule_priorities: Dict[expertsystem.reaction.conservation_rules.GraphElementRule, int]
class GraphSettings(edge_settings: Dict[int, expertsystem.reaction.solving.EdgeSettings] = NOTHING, node_settings: Dict[int, expertsystem.reaction.solving.NodeSettings] = NOTHING)[source]

Bases: object

__eq__(other)

Method generated by attrs for class GraphSettings.

edge_settings: Dict[int, expertsystem.reaction.solving.EdgeSettings]
node_settings: Dict[int, expertsystem.reaction.solving.NodeSettings]
class InteractionTypes(value)[source]

Bases: enum.Enum

Types of interactions in the form of an enumerate.

EM = 2
Strong = 1
Weak = 3
class NodeSettings(conservation_rules: Set[Union[expertsystem.reaction.conservation_rules.GraphElementRule, expertsystem.reaction.conservation_rules.EdgeQNConservationRule, expertsystem.reaction.conservation_rules.ConservationRule]] = NOTHING, rule_priorities: Dict[Union[expertsystem.reaction.conservation_rules.GraphElementRule, expertsystem.reaction.conservation_rules.EdgeQNConservationRule, expertsystem.reaction.conservation_rules.ConservationRule], int] = NOTHING, qn_domains: Dict[Any, Any] = NOTHING)[source]

Bases: object

Container class for the interaction settings.

This class can be assigned to each node of a state transition graph. Hence, these settings contain the complete configuration information which is required for the solution finding, e.g:

  • set of conservation rules

  • mapping of rules to priorities (optional)

  • mapping of quantum numbers to their domains

  • strength scale parameter (higher value means stronger force)

__eq__(other)

Method generated by attrs for class NodeSettings.

conservation_rules: Set[Union[expertsystem.reaction.conservation_rules.GraphElementRule, expertsystem.reaction.conservation_rules.EdgeQNConservationRule, expertsystem.reaction.conservation_rules.ConservationRule]]
interaction_strength: float = 1.0
qn_domains: Dict[Any, Any]
rule_priorities: Dict[Union[expertsystem.reaction.conservation_rules.GraphElementRule, expertsystem.reaction.conservation_rules.EdgeQNConservationRule, expertsystem.reaction.conservation_rules.ConservationRule], int]
class Result(solutions: Optional[List[expertsystem.reaction.topology.StateTransitionGraph[Tuple[expertsystem.particle.Particle, float]]]] = None, not_executed_node_rules: Optional[Dict[int, Set[str]]] = None, violated_node_rules: Optional[Dict[int, Set[str]]] = None, not_executed_edge_rules: Optional[Dict[int, Set[str]]] = None, violated_edge_rules: Optional[Dict[int, Set[str]]] = None, formalism_type: Optional[str] = None)[source]

Bases: object

Defines a result to a problem set processed by the solving code.

collapse_graphs() → List[expertsystem.reaction.topology.StateTransitionGraph[expertsystem.particle.ParticleCollection]][source]
extend(other_result: expertsystem.reaction.solving.Result, intersect_violations: bool = False)None[source]
property formalism_type
get_final_state() → List[expertsystem.particle.Particle][source]
get_initial_state() → List[expertsystem.particle.Particle][source]
get_intermediate_particles()expertsystem.particle.ParticleCollection[source]

Extract the names of the intermediate state particles.

get_particle_graphs() → List[expertsystem.reaction.topology.StateTransitionGraph[expertsystem.particle.Particle]][source]

Strip list of StateTransitionGraph s of the spin projections.

Extract a list of StateTransitionGraph instances with only particles on the edges.

property not_executed_edge_rules
property not_executed_node_rules
property solutions
property violated_edge_rules
property violated_node_rules
class Scoresheet[source]

Bases: object

register_rule(graph_element_id: int, rule: Union[expertsystem.reaction.conservation_rules.GraphElementRule, expertsystem.reaction.conservation_rules.EdgeQNConservationRule, expertsystem.reaction.conservation_rules.ConservationRule]) → Callable[[bool], None][source]
property rule_calls
property rule_passes
class Solver[source]

Bases: abc.ABC

Interface of a Solver.

abstract find_solutions(graph: expertsystem.reaction.topology.StateTransitionGraph[Tuple[expertsystem.particle.Particle, float]], graph_settings: expertsystem.reaction.solving.GraphSettings)expertsystem.reaction.solving.Result[source]

Find solutions for the given input.

It is expected that this function determines and returns all of the found solutions. In case no solutions are found a partial list of violated rules has to be given. This list of violated rules does not have to be complete.

Parameters
  • graph – a StateTransitionGraph which contains all of the known facts quantum numbers of the problem.

  • edge_settings – mapping of edge id’s to EdgeSettings, that assigns specific rules and variable domains to an edge of the graph.

  • node_settings – mapping of node id’s to NodeSettings, that assigns specific rules and variable domains to a node of the graph.

Returns

contains possible solutions, violated rules and not executed rules due to requirement issues.

Return type

Result

convert_non_executed_rules_to_names(rules: Union[Dict[int, Set[Union[expertsystem.reaction.conservation_rules.GraphElementRule, expertsystem.reaction.conservation_rules.EdgeQNConservationRule, expertsystem.reaction.conservation_rules.ConservationRule]]], Dict[int, Set[expertsystem.reaction.conservation_rules.GraphElementRule]]]) → Dict[int, Set[str]][source]
convert_violated_rules_to_names(rules: Union[Dict[int, Set[Union[expertsystem.reaction.conservation_rules.GraphElementRule, expertsystem.reaction.conservation_rules.EdgeQNConservationRule, expertsystem.reaction.conservation_rules.ConservationRule]]], Dict[int, Set[expertsystem.reaction.conservation_rules.GraphElementRule]]]) → Dict[int, Set[str]][source]
validate_fully_initialized_graph(graph: expertsystem.reaction.topology.StateTransitionGraph[Tuple[expertsystem.particle.Particle, float]], rules_per_node: Dict[int, Set[Union[expertsystem.reaction.conservation_rules.GraphElementRule, expertsystem.reaction.conservation_rules.EdgeQNConservationRule, expertsystem.reaction.conservation_rules.ConservationRule]]], rules_per_edge: Dict[int, Set[expertsystem.reaction.conservation_rules.GraphElementRule]])expertsystem.reaction.solving.Result[source]