kappybara.mixture#
Functions
|
Group components by isomorphism. |
|
Get all agents within a distance radius of the given agents. |
Classes
|
A mixture that explicitly tracks connected components. |
|
Represents bonds between sites. |
|
A collection of agents and their connections. |
|
Specifies changes to be applied to a mixture. |
- class kappybara.mixture.ComponentMixture(patterns=None)[source]#
A mixture that explicitly tracks connected components.
- Parameters:
patterns (Iterable[Pattern] | None)
- components#
Indexed set of all components in the mixture.
- apply_update(update)[source]#
Apply a collection of changes to the mixture.
- Parameters:
update (MixtureUpdate) – MixtureUpdate specifying changes to apply.
- Return type:
None
- components: IndexedSet[Component]#
- class kappybara.mixture.Edge(site1, site2)[source]#
Represents bonds between sites.
Note
Edge(x, y) is the same as Edge(y, x).
- site1#
First site in the bond.
- Type:
- site2#
Second site in the bond.
- Type:
- class kappybara.mixture.Mixture(patterns=None)[source]#
A collection of agents and their connections.
- Parameters:
patterns (Iterable[Pattern] | None)
- agents#
Indexed set of all agents in the mixture.
- _embeddings#
Cache of embeddings for tracked components.
- _max_embedding_width#
Maximum diameter of tracked components.
- Type:
int
- add(component)[source]#
Add a component to the mixture.
- Parameters:
component (Component) – Component to add with its agents and connections.
- Return type:
None
- agents: IndexedSet[Agent]#
- apply_update(update)[source]#
Apply a collection of changes to the mixture.
- Parameters:
update (MixtureUpdate) – MixtureUpdate specifying changes to apply.
- Return type:
None
- embeddings(component)[source]#
Get embeddings of a tracked component.
Notes
Returns the number of matches directly returned by subgraph isomorphism, i.e. not accounting for symmetries.
- Parameters:
component (Component) – Component to get embeddings for.
- Returns:
Set of embeddings for the component.
- Raises:
KeyError – If component is not being tracked.
- Return type:
- classmethod from_kappa(patterns)[source]#
Create a mixture from Kappa pattern strings and counts.
- Parameters:
patterns (dict[str, int]) – Dictionary mapping pattern strings to copy counts.
- Returns:
New Mixture with instantiated patterns.
- Return type:
Self
- instantiate(pattern, n_copies=1)[source]#
Add instances of a pattern to the mixture.
- Parameters:
pattern (Pattern | str) – Pattern to instantiate, or Kappa string.
n_copies (int) – Number of copies to create.
- Raises:
AssertionError – If pattern is underspecified.
- Return type:
None
- property kappa_str: str#
The mixture representation in Kappa format.
- Returns:
Kappa string with %init declarations for each component type.
- class kappybara.mixture.MixtureUpdate(agents_to_add=<factory>, agents_to_remove=<factory>, edges_to_add=<factory>, edges_to_remove=<factory>, agents_changed=<factory>)[source]#
Specifies changes to be applied to a mixture.
- Parameters:
- agents_to_add#
Agents to be added to the mixture.
- Type:
list[kappybara.pattern.Agent]
- agents_to_remove#
Agents to be removed from the mixture.
- Type:
list[kappybara.pattern.Agent]
- edges_to_add#
Edges to be created.
- Type:
- edges_to_remove#
Edges to be removed.
- Type:
- agents_changed#
Agents with internal state changes.
- Type:
- connect_sites(site1, site2)[source]#
Specify to create an edge between two sites.
If the sites are bound to other sites, indicates to remove those edges.
- create_agent(agent)[source]#
Create a new agent based on a template.
Note
Sites in the created agent will be emptied.
- disconnect_site(site)[source]#
Specify that a site should be unbound.
- Parameters:
site (Site) – Site to disconnect from its partner.
- Return type:
None
- register_changed_agent(agent)[source]#
Register an agent as having internal state changes.
- Parameters:
agent (Agent) – Agent that has been internally modified.
- Return type:
None
- remove_agent(agent)[source]#
Specify to remove an agent and its edges from the mixture.
- Parameters:
agent (Agent) – Agent to remove.
- Return type:
None