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

Put linking and non-linking nonterminals in (hopefully) faster order in multi_solve #186

Merged
merged 9 commits into from
Sep 18, 2024

Conversation

grantexley
Copy link
Collaborator

No description provided.

@davidweichiang davidweichiang changed the title Issue 179 Put linking and non-linking nonterminals in (hopefully) faster order in multi_solve (closes #179) Sep 5, 2024
@davidweichiang davidweichiang changed the title Put linking and non-linking nonterminals in (hopefully) faster order in multi_solve (closes #179) Put linking and non-linking nonterminals in (hopefully) faster order in multi_solve Sep 5, 2024
@davidweichiang
Copy link
Collaborator

Closes #179.

fggs/multi.py Outdated

for neighbor in nonterminal_graph.get(node, []):
if neighbor not in visited:
dfs(neighbor, iteration + 1)
Copy link
Collaborator

Choose a reason for hiding this comment

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

You're computing the depth in the DFS tree, but the finishing times are supposed to be unique (if u != v then finish[u] != finish[v]). What you did might also work, but I'll have to think about it.

Copy link
Collaborator

Choose a reason for hiding this comment

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

IMG_5896

Copy link
Collaborator

Choose a reason for hiding this comment

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

Assuming that the DFS iterates over children left-to-right (so, A before D), I believe the depths and finishing times above are correct. And according to the current code, I think C and D would both be non-linking nonterminals. But according to the paper, just D would be a non-linking nonterminal.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

You're definitely right here. I'll make this change.

fggs/multi.py Outdated
#dfs on graph to get finish times
finish_times = {}
visited = set()
time = [0] #this must be a list so it is mutable and will persist over multiple calls to dfs
Copy link
Collaborator

Choose a reason for hiding this comment

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

You can just make this an int, i.e., time = 0, then inside dfs, write nonlocal time, then to increment time, write time += 1

@@ -81,6 +82,13 @@ def test_multi_solve(self):
x_sparse = multi_solve(a_sparse, b_sparse, transpose=True)
x_dense = torch.linalg.solve(torch.eye(*a_dense.shape)-a_dense.T, b_dense)
self.assertTrue(self.compare_vectors(x_sparse, x_dense), (x_sparse, x_dense))

### WIP ###
Copy link
Collaborator

Choose a reason for hiding this comment

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

Does this still need work?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This test is pretty basic and I think there should probably be some more testing. There isn't currently a great fgg in the test directory to test this function with. Do you think I should make a new fgg to test this with?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Is example12p.json not good? I think it would be a lot of work for you to make a whole new FGG, but you could. Or we can build one from a PERPL program.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

example12.json and cycle.json both have a nonlinking nonterminal, but they are already at the end of a.shapes[0].keys() by default, so _order_nonterminals doesn't actually change anything when run on them.
I just added advanced_cycle.json which doesn't have this issue.

@@ -1,7 +1,10 @@
from fggs.multi import *
import fggs.multi as multi_module
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please import as multi or if not possible, then as fggs.multi

Copy link
Collaborator

Choose a reason for hiding this comment

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

Could we call it double_cycle.json instead?

@davidweichiang davidweichiang merged commit 112dad7 into main Sep 18, 2024
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants