kappybara.pattern#
Classes
|
Represents an agent with a type and collection of sites. |
|
A set of agents that are all in the same connected component. |
Dictionary representing a mapping from pattern agents to mixture agents. |
|
|
A pattern consisting of multiple agents, some of which may be None (empty slots). |
|
Represents a site on an agent with state and binding partner information. |
|
- class kappybara.pattern.Agent(type, sites)[source]#
Represents an agent with a type and collection of sites.
- Parameters:
type (str)
sites (Iterable[Site])
- type#
Type name of the agent.
- interface#
Dictionary mapping site labels to Site objects.
- property depth_first_traversal: list[Self]#
Perform depth-first traversal starting from this agent.
- Returns:
List of agents in depth-first order.
- detached()[source]#
Create a clone with all sites emptied of partners.
- Returns:
New agent with same type and states but no connections.
- Return type:
Self
- embeds_in(other)[source]#
Check whether self as a pattern matches other as a concrete agent.
- Parameters:
other (Self) – Concrete agent to match against.
- Returns:
True if this agent pattern matches the concrete agent.
- Return type:
bool
- classmethod from_kappa(kappa_str)[source]#
Parse a single agent from a Kappa string.
- Parameters:
kappa_str (str) – Kappa string describing a single agent.
- Returns:
Parsed Agent object.
- Raises:
AssertionError – If the string doesn’t describe exactly one agent.
- Return type:
Self
- property instantiable: bool#
Check if this agent pattern can be instantiated.
- Returns:
True if all sites are sufficiently specified.
- isomorphic(other)[source]#
Check if two Agents are equivalent locally, ignoring partners.
Note
Doesn’t assume agents of the same type will have the same site signatures.
- Parameters:
other (Self) – Agent to compare against.
- Returns:
True if agents are locally isomorphic.
- Return type:
bool
- property kappa_str#
The agent representation in Kappa format.
- Returns:
Kappa string representation of the agent.
- property neighbors: list[Self]#
The agents directly connected to this one.
- Returns:
List of neighboring agents.
- property underspecified: bool#
Check if a concrete Agent can be created from this pattern.
- Returns:
True if any site is underspecified.
- class kappybara.pattern.Component(agents, n_copies=1)[source]#
A set of agents that are all in the same connected component.
Note
Connectedness is not guaranteed statically and must be enforced.
- Parameters:
agents (IndexedSet[Agent])
n_copies (int)
- agents#
Indexed set of agents in this component.
- n_copies#
Number of copies of this component (usually 1).
- Type:
int
- add(agent)[source]#
Add an agent to this component.
- Parameters:
agent (Agent) – Agent to add to the component.
- agents: IndexedSet[Agent]#
- property diameter: int#
Get the maximum minimum shortest path between any two agents.
- Returns:
Diameter of the component graph.
- classmethod from_kappa(kappa_str)[source]#
Parse a single component from a Kappa string.
- Parameters:
kappa_str (str) – Kappa string describing a connected component.
- Returns:
Parsed Component object.
- Raises:
AssertionError – If the pattern doesn’t represent exactly one component.
- Return type:
Self
- isomorphic(other)[source]#
Check if two components are isomorphic.
- Parameters:
other (Self) – Component to compare against.
- Returns:
True if an isomorphism exists between the components.
- Return type:
bool
- isomorphisms(other)[source]#
Find bijections which respect links in the site graph.
Checks for bijections ensuring that any internal site state specified in one component exists and is the same in the other.
Note
Handles isomorphism generally, between instantiated components in a mixture and potentially between rule patterns.
- property kappa_str: str#
The component representation in Kappa format.
- Returns:
Kappa string representation of the component.
- property n_automorphisms: int#
Returns the number of automorphisms of the component.
Note
This uses a cached result, and thus should only be used for static components, i.e. the ones in rules and observables. Do not use this for components in a mixture that can change.
- Returns:
The number of isomorphisms of the component onto itself.
- n_copies: int#
- class kappybara.pattern.Embedding[source]#
Dictionary representing a mapping from pattern agents to mixture agents.
- class kappybara.pattern.Pattern(agents)[source]#
A pattern consisting of multiple agents, some of which may be None (empty slots).
- Parameters:
agents (list[Agent | None])
- agents#
List of agents, where None represents empty slots in rules.
- Type:
list[kappybara.pattern.Agent | None]
- static agents_to_kappa_str(agents)[source]#
Convert a collection of agents to Kappa string representation.
- Parameters:
agents (Iterable[Agent | None]) – Collection of agents to convert.
- Returns:
Kappa string representation of the agents.
- Return type:
str
- property components: list[Component]#
The connected components in this pattern.
- Returns:
List of Component objects representing connected parts.
- classmethod from_kappa(kappa_str)[source]#
Parse a pattern from a Kappa string.
- Parameters:
kappa_str (str) – Kappa string describing a pattern.
- Returns:
Parsed Pattern object.
- Raises:
AssertionError – If the string doesn’t describe exactly one pattern.
- Return type:
Self
- property kappa_str: str#
The pattern representation in Kappa format.
- Returns:
Kappa string representation of the pattern.
- n_isomorphisms(other)[source]#
Counts the number of bijections which respect links in the site graph.
Note
Runtime is exponential in the number of components; use with caution.
- Parameters:
other (Self) – Pattern to count isomorphisms with.
- Returns:
The number of isomorphisms between the patterns.
- Return type:
int
- property underspecified: bool#
Check if any agents in the pattern are underspecified.
- Returns:
True if any agent is None or underspecified.
- class kappybara.pattern.Site(label, state, partner)[source]#
Represents a site on an agent with state and binding partner information.
- agent#
The agent this site belongs to (set after initialization).
- Type:
- label#
Name of the site.
- state#
Internal state of the site.
- partner#
Binding partner specification.
- property bound: bool#
Check if the site is bound.
- Returns:
True if the site is bound to something.
- property coupled: bool#
Check if the site is coupled to a specific other site.
- Returns:
True if the site has a direct partner reference.
- embeds_in(other)[source]#
Check whether self as a pattern matches other as a concrete site.
- Parameters:
other (Self) – Concrete site to match against.
- Returns:
True if this site pattern matches the concrete site.
- Return type:
bool
- property kappa_partner_str: str#
- property kappa_state_str: str#
- property kappa_str: str#
The site representation in Kappa format.
- Returns:
Kappa string representation of the site.
- property stated: bool#
Check if the site has a specific internal state.
- Returns:
True if the site has a determined state.
- property underspecified: bool#
Check if a concrete Site can be created from this pattern.
- Returns:
True if the site specification is incomplete.
- property undetermined: bool#
Check if the site is in a state equivalent to leaving it unnamed in an agent.
- Returns:
True if the site is undetermined.