Skip to content
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

HypergraphSubstitutionSystem #643

Draft
wants to merge 27 commits into
base: master
Choose a base branch
from

Conversation

daneelsan
Copy link
Collaborator

@daneelsan daneelsan commented May 12, 2021

Changes

  • Implements HypergraphSubstitutionSystem, which uses the existing low-level Hypergraph-related code to compute the evolution of hypergraphs.
  • SetReplace* and WolframModel symbols now call GenerateMultihistory[HypergraphSubstitutionSystem[...], ...], and covert the resulting multihistory object to a {WolframModelEvolutionObject, 2}.

Comments

  • Tests

  • Documentation

Examples

In[] := {{1, 2, 3}, {2, 4, 5}, {4, 6, 7}} //
    GenerateMultihistory[
      HypergraphSubstitutionSystem[ToPatternRules[{{1, 2, 3}, {2, 4, 5}} -> {{5, 6, 1}, {6, 4, 2}, {4, 5, 3}}]],
      {"MaxGeneration" -> 5, "MaxDestroyerEvents" -> 1},
      None,
      {"ReverseSortedInputTokenIndices", "InputTokenIndices", "RuleIndex"},
      {}
    ] // SetReplaceTypeConvert[{WolframModelEvolutionObject, 2}] //
      #["ExpressionsEventsGraph", VertexLabels -> "Index"] &

Example


This change is Reviewable

daneelsan and others added 23 commits May 11, 2021 10:50
…etween HypergraphSubstitutionSystem and WolframModelEvolutionObject.
…onSystem; Saving "GlobalAtoms" instead of "GlobalAtomsIndexMap" in the multihistory object.
…ypergraphSubstitutionSystem[...], ...]; Renaming "EventOrderingFunction".
…ng in setSubstitutionSystem.m to avoid message clashing with the new type system message.
…ng All as one of the default deduplication choices.
@daneelsan daneelsan added evolution Modifies code for running the evolution of the model feature New functionality, or change in existing functionality wolfram language Requires Wolfram Language implementation labels Jun 20, 2021
@daneelsan daneelsan added this to the Project Yellowstone milestone Jun 20, 2021
@daneelsan daneelsan self-assigned this Jun 20, 2021
Copy link
Owner

@maxitg maxitg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't look through all of it yet (as far as I understand it's not completely done yet), but I left a few large-scale comments. We might also need to discuss the whole interaction between match-all/deduplication/event sets in more detail at some point.

Reviewable status: 0 of 19 files reviewed, 4 unresolved discussions (waiting on @daneelsan)


Documentation/Types/Multihistory/HypergraphSubstitutionSystem0.md, line 8 at r4 (raw file):

```wl
In[] := multi = GenerateMultihistory[HypergraphSubstitutionSystem[{{a_, b_}, {a_, c_}} :> {{b, c}}],

Why does it take multiset system rules? Shouldn't it take {{1, 2}, {1, 3}} -> {{2, 3}} since it cannot take anything more general? There is a special case of explicit vertices, but I think it will be better handled with something like {{1, Global[2]}, {1, 3}} -> {{Global[2], 3}}, meaning, {{a_, 2}, {a_, b_}} :> {{2, b}}.


Documentation/Types/Multihistory/HypergraphSubstitutionSystem0.md, line 17 at r4 (raw file):

<img src="/Documentation/Images/HypergraphMultihistory.png" width="607.8">

It uses the hypergraph related C++ code found in the [libSetReplace](/libSetReplace/), same as what **WolframModel**

I think if we are going to refer to WolframModel, it would be best to do it in the past tense or otherwise make it clear that it is not deprecated (otherwise, it's not clear why we have both).


Documentation/Types/Multihistory/HypergraphSubstitutionSystem0.md, line 25 at r4 (raw file):

hypergraph object is kept inside (see
[Managed Library Expressions](https://reference.wolfram.com/language/LibraryLink/tutorial/InteractionWithWolframLanguage#353220453)):

It might be useful to discuss the implications of this (such as that it won't work with parallel kernels and cannot be stored in a notebook).


Kernel/HypergraphSubstitutionSystem.m, line 229 at r4 (raw file):

  <|"MaxGeneration"      -> {Infinity, "NonNegativeIntegerOrInfinity"},
    "MaxDestroyerEvents" -> {Infinity, "NonNegativeIntegerOrInfinity"},
    "EventSeparation"    -> {"Spacelike", {"Spacelike", "Any"}}|>,

Nice! That's probably a better place to put it than anything I came up with before. Arguably, GenerateFullEventSet should set this to "Any" automatically, and MultisetSubstitutionSystem should support the case where "EventSeparation" is "Spacelike", but token deduplication is All.

maxitg added a commit that referenced this pull request Jul 19, 2021
## Changes

* This is a complete rewrite of the generator system.
* Old `GenerateMultihistory` syntax is removed.
* Instead, all generators have the format

  ```wl
  Generator[System[rules], param1 -> value1, ...] @ init
  ```

  Note that `param1`, etc. are symbols rather than strings. They have usage messages, etc. Also, one can use lists or associations instead, e.g.,

  ```wl
  Generator[System[rules], {param1 -> value1}, <|param2 -> value2|>, param3 -> value3] @ init
  ```

* Parameters are now declared separately from systems and generators.
* Systems need to declare a logical expression specifying which parameters can be specified. For example,

  ```wl
  Implies[MaxEvents || MaxDestroyerEvents, EventOrder]
  ```

  means that `EventOrder` needs to be specified if either `MaxEvents` or `MaxDestroyerEvents` are specified.

* Generators have predefined values for some parameters. E.g., `GenerateSingleHistory` sets `MaxDestroyerEvents -> 1`, which can no longer be changed.

## Comments

* Apologies for a huge PR. There is a lot of refactoring here as all instances of `GenerateMultihistory` had to be changed.
* Ordering functions page is deleted for now but should return as a page for the `EventOrder` parameter once it is used somewhere.
* @daneelsan, unfortunately, it will break #643, but on the flip side, it should make it a lot easier to define parameters (as one does not need to think where to put them anymore).

## Examples

* `GenerateSingleHistory`:

```wl
In[] := #["StatesList"] & @
 SetReplaceTypeConvert[{WolframModelEvolutionObject, 2}] @
  GenerateSingleHistory[MultisetSubstitutionSystem[{a_, b_} :> {a + b}], MaxEvents -> 4] @ {1, 2, 3}
Out[] = {{1, 2, 3}, {3, 3}, {6}}
```

* `GenerateAllHistories`:

```wl
In[] := #["ExpressionsEventsGraph", VertexLabels -> Placed[Automatic, After]] & @
 SetReplaceTypeConvert[{WolframModelEvolutionObject, 2}] @
  GenerateMultihistory[
    MultisetSubstitutionSystem[{a_, b_} /; a < b :> {a + b}], MaxGeneration -> 2] @ Range[3]
```
<img width="399" alt="image" src="https://user-images.githubusercontent.com/1479325/122285946-f08ade80-ceb4-11eb-882d-7da3fdeb75fb.png">
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
evolution Modifies code for running the evolution of the model feature New functionality, or change in existing functionality wolfram language Requires Wolfram Language implementation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants