Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Improve graph I/O #184

Merged
merged 3 commits into from
Sep 25, 2024
Merged

Improve graph I/O #184

merged 3 commits into from
Sep 25, 2024

Conversation

dcerkoney
Copy link
Collaborator

  1. Add getter properties and setter set_properties! to AbstractGraph interface. This fixes a bug in I/O for user-defined concrete graph types such as the example ConcreteGraph defined in the test set.
  2. Improve string representations for graphs, Feynman graphs, and operators.
  3. Add plaintext representations for all custom graph, operator, and quantum operator symbols.
  4. Bugfix for typestr in function _stringrep to correctly display subgraph IDs (see examples below).
  5. Add tests for all string representations.
  6. Clean up comments in tests and tree_properties.jl.

For example, the code

using AbstractTrees, FeynmanDiagram

ComputationalGraphs.uidreset();
g = 2 * (Graph([]) + Graph([]));

function display(g)
    println("plaintext:\n", g)  # plaintext representation
    println("\nREPL:")
    show(g)                     # decorated representation shown by the REPL
    println("\n\nAbstractTrees:")
    print_tree(g)
end

display(g)

now produces the output:

plaintext:
4: Prod(3)=0.0

REPL:
4: Ⓧ (3)=0.0

AbstractTrees:
4: Ⓧ (3)=0.0
└─ 3: (1,2)=0.0
   ├─ 1: 0.0
   └─ 2: 0.0

instead of

plaintext:
4=0.0=FeynmanDiagram.ComputationalGraphs.Prod 

REPL:
4=0.0=FeynmanDiagram.ComputationalGraphs.Prod 

AbstractTrees:
4 : 4=0.0=FeynmanDiagram.ComputationalGraphs.Prod 
└─ 3 : 3=0.0=FeynmanDiagram.ComputationalGraphs.Sum 
   ├─ 1 : 1=0.0()
   └─ 2 : 2=0.0()

Similarly, the code

using AbstractTrees
using FeynmanDiagram
import FeynmanDiagram.FrontEnds: NoHartree

ComputationalGraphs.uidreset();
para = Parquet.DiagPara(type=Parquet.SigmaDiag, innerLoopNum=2, hasTau=true, filter=[NoHartree,]);
sigma2_ins = optimize!(Parquet.build(para).diagram)[1];
dict_sigma2_AD = taylorAD(
    [sigma2_ins], 
    [1, 0],
    [x -> x isa FrontEnds.BareGreenId, x -> x isa FrontEnds.BareInteractionId],
);
dmu_sigma2 = dict_sigma2_AD[[1, 0]][1];
print_tree(dmu_sigma2; maxdepth=7)

now produces the output

126: Ins, k[1.0, 0.0, 0.0], t(1, 1)[1]=Ⓧ (124)=0.0
└─ 124: Ins, k[1.0, 0.0, 0.0], t(1, 1)[1]=Ⓧ (119,1)=0.0
   ├─ 119: Dyn, k[0.0, 1.0, 0.0], t(1, 1)[1]=(117,118)=0.0
   │  ├─ 117: [1]=Ⓧ (7,111)=0.0
   │  │  ├─ 7: g0, Dyn, k[0.0, 1.0, 0.0], t(1, 2)=0.0
   │  │  └─ 111: (t = (2, 1),)[1]=(109,110)=0.0
   │  │     ├─ 109: [1]=Ⓧ (99,103)=0.0
   │  │     │  ├─ 99: Ins, k[0.0, 1.0, 0.0], t(2, 2)=Ⓧ (14,8)=0.0
   │  │     │  │  ├─ 14: Gfock, Dyn, k[0.0, 0.0, 1.0], t(2, 2)=0.0
   │  │     │  │  └─ 8: ccIns, k[0.0, 1.0, -1.0], t(1, 1)=0.0
   │  │     │  └─ 103: Dyn, k[0.0, 1.0, 0.0], t(2, 1)[1]=0.0
   │  │     └─ 110: [1]=Ⓧ (100,21)=0.0
   │  │        ├─ 100: Ins, k[0.0, 1.0, 0.0], t(2, 2)[1]=Ⓧ (95,8)=0.0
   │  │        │  ├─ 95: Dyn, k[0.0, 0.0, 1.0], t(2, 2)[1]=0.0
   │  │        │  └─ 8: ccIns, k[0.0, 1.0, -1.0], t(1, 1)=0.0
   │  │        └─ 21: G, Dyn, k[0.0, 1.0, 0.0], t(2, 1)=0.0
   │  └─ 118: [1]=Ⓧ (94,108)=0.0
   │     ├─ 94: Dyn, k[0.0, 1.0, 0.0], t(1, 2)[1]=0.0
   │     └─ 108: (t = (2, 1),)=Ⓧ (99,21)=0.0
   │        ├─ 99: Ins, k[0.0, 1.0, 0.0], t(2, 2)=Ⓧ (14,8)=0.0
   │        │  ├─ 14: Gfock, Dyn, k[0.0, 0.0, 1.0], t(2, 2)=0.0
   │        │  └─ 8: ccIns, k[0.0, 1.0, -1.0], t(1, 1)=0.0
   │        └─ 21: G, Dyn, k[0.0, 1.0, 0.0], t(2, 1)=0.0
   └─ 1: ccIns, k[1.0, -1.0, 0.0], t(1, 1)=0.0

instead of

126 : 126Ins, k[1.0, 0.0, 0.0], t(1, 1)[1]=0.0=FeynmanDiagram.ComputationalGraphs.Prod 
└─ 124 : 124Ins, k[1.0, 0.0, 0.0], t(1, 1)[1]=0.0=FeynmanDiagram.ComputationalGraphs.Prod 
   ├─ 119 : 119Dyn, k[0.0, 1.0, 0.0], t(1, 1)[1]=0.0=FeynmanDiagram.ComputationalGraphs.Sum 
   │  ├─ 117 : 117[1]=0.0=FeynmanDiagram.ComputationalGraphs.Prod 
   │  │  ├─ 7 : 7-g0Dyn, k[0.0, 1.0, 0.0], t(1, 2)=0.0()
   │  │  └─ 111 : 111(t = (2, 1),)[1]=0.0=FeynmanDiagram.ComputationalGraphs.Sum 
   │  │     ├─ 109 : 109[1]=0.0=FeynmanDiagram.ComputationalGraphs.Prod 
   │  │     │  ├─ 99 : 99Ins, k[0.0, 1.0, 0.0], t(2, 2)=0.0=FeynmanDiagram.ComputationalGraphs.Prod 
   │  │     │  │  ├─ 14 : 14-GfockDyn, k[0.0, 0.0, 1.0], t(2, 2)=0.0()
   │  │     │  │  └─ 8 : 8ccIns, k[0.0, 1.0, -1.0], t(1, 1)=0.0()
   │  │     │  └─ 103 : 103Dyn, k[0.0, 1.0, 0.0], t(2, 1)[1]=0.0()
   │  │     └─ 110 : 110[1]=0.0=FeynmanDiagram.ComputationalGraphs.Prod 
   │  │        ├─ 100 : 100Ins, k[0.0, 1.0, 0.0], t(2, 2)[1]=0.0=FeynmanDiagram.ComputationalGraphs.Prod 
   │  │        │  ├─ 95 : 95Dyn, k[0.0, 0.0, 1.0], t(2, 2)[1]=0.0()
   │  │        │  └─ 8 : 8ccIns, k[0.0, 1.0, -1.0], t(1, 1)=0.0()
   │  │        └─ 21 : 21-GDyn, k[0.0, 1.0, 0.0], t(2, 1)=0.0()
   │  └─ 118 : 118[1]=0.0=FeynmanDiagram.ComputationalGraphs.Prod 
   │     ├─ 94 : 94Dyn, k[0.0, 1.0, 0.0], t(1, 2)[1]=0.0()
   │     └─ 108 : 108(t = (2, 1),)=0.0=FeynmanDiagram.ComputationalGraphs.Prod 
   │        ├─ 99 : 99Ins, k[0.0, 1.0, 0.0], t(2, 2)=0.0=FeynmanDiagram.ComputationalGraphs.Prod 
   │        │  ├─ 14 : 14-GfockDyn, k[0.0, 0.0, 1.0], t(2, 2)=0.0()
   │        │  └─ 8 : 8ccIns, k[0.0, 1.0, -1.0], t(1, 1)=0.0()
   │        └─ 21 : 21-GDyn, k[0.0, 1.0, 0.0], t(2, 1)=0.0()
   └─ 1 : 1ccIns, k[1.0, -1.0, 0.0], t(1, 1)=0.0()

…erties` and setter `set_properties!` to AbstractGraph interface
…tion `_stringrep` to correctly display subgraph IDs
@dcerkoney dcerkoney added bug Something isn't working enhancement New feature or request labels Sep 19, 2024
@dcerkoney dcerkoney self-assigned this Sep 19, 2024
@dcerkoney dcerkoney merged commit 79f254b into master Sep 25, 2024
5 checks passed
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
bug Something isn't working enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants