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

Improvement: annotate cycles with variable names #1304

Merged

Conversation

fuenfundachtzig
Copy link
Contributor

@fuenfundachtzig fuenfundachtzig commented May 2, 2024

Fixes #847

Copy link

vercel bot commented May 2, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
marimo-docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 3, 2024 5:38pm
marimo-storybook ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 3, 2024 5:38pm

@akshayka
Copy link
Contributor

akshayka commented May 2, 2024

@fuenfundachtzig, thank you for doing this; definitely an improvement. I'll plan to review once it's moved out of draft, but let me know if you want eyes earlier.

@fuenfundachtzig
Copy link
Contributor Author

@fuenfundachtzig, thank you for doing this; definitely an improvement. I'll plan to review once it's moved out of draft, but let me know if you want eyes earlier.

Thanks a lot :) There is a failing test, let me look into that first (might have time over the weekend).

@fuenfundachtzig
Copy link
Contributor Author

The test fails because I am using a set in

EdgeWithVar = Tuple[CellId_t, Set[str], CellId_t]

which becomes part of the cell output if there is a CycleError in

edges_with_vars: tuple[EdgeWithVar, ...]

making the CellOutput no longer JSON-serializable in

cell_id: _serialize_to_base64(json.dumps(output.asdict()))
.

I could either

  • simply change the definition of EdgeWithVar to use a list instead of a set, or
  • add a custom handler to json.dumps that converts set to lists

Any preferences?

@akshayka
Copy link
Contributor

akshayka commented May 3, 2024

I'd just use a list instead of a set for simplicity.

Copy link
Contributor

@akshayka akshayka left a comment

Choose a reason for hiding this comment

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

This is great! I left just a few small comments and suggestions.

<li className={liStyle} key={`${edge[0]}-${edge[1]}`}>
<CellLinkError cellId={edge[0]} />
{" -> "} {edge[1].length == 1 ? edge[1] : edge[1].join(", ")}{" "}
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
{" -> "} {edge[1].length == 1 ? edge[1] : edge[1].join(", ")}{" "}
<span className="text-muted-foreground">
{" - "} {edge[1].length == 1 ? edge[1] : edge[1].join(", ")}
{" -> "}
</span>

@@ -19,6 +19,9 @@
from collections.abc import Collection

Edge = Tuple[CellId_t, CellId_t]
# EdgeWithVar uses a list rather than a set for the variables linking the cells
# as sets are not JSON-serializable (required by static_notebook_template())
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
# as sets are not JSON-serializable (required by static_notebook_template())
# as sets are not JSON-serializable (required by static_notebook_template()).
# The first entry is the source node; the second entry is a list of defs from
# the source read by the destination; and the third entry is the destination
# node.

Comment on lines 60 to 62
# before reporting the cells in the cycle to the user,
# we first annotate the cycle with the variable names
# that link its cells
Copy link
Contributor

Choose a reason for hiding this comment

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

Super small nit on comment formatting.

Suggested change
# before reporting the cells in the cycle to the user,
# we first annotate the cycle with the variable names
# that link its cells
# before reporting the cells in the cycle to the user,
# we first annotate the cycle with the variable names
# that link its cells

for edge in expected_edges:
assert edge in error.edges or (edge[1], edge[0]) in error.edges
assert edge in error.edges_with_vars or reversed(edge) in error.edges_with_vars
Copy link
Contributor

Choose a reason for hiding this comment

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

I believe the reversed logic wasn't needed originally; removed it and these tests
still pass on my machine. Checking for the presence of a reversed edge is no longer
correct, since the variables that flow on the edges change when you flip the direction.

Suggested change
assert edge in error.edges_with_vars or reversed(edge) in error.edges_with_vars
assert edge in error.edges_with_vars

@fuenfundachtzig
Copy link
Contributor Author

Thanks for the suggestions! I have implemented all of them. You're right about the reversed... I had wondered about that but didn't want to break anything I might be overlooking.

I have also decided to sort the variables when printing them.

sorting variable names in output
Copy link
Contributor

@akshayka akshayka left a comment

Choose a reason for hiding this comment

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

Thanks!

@akshayka akshayka merged commit 5fa04ce into marimo-team:main May 3, 2024
25 of 26 checks passed
Copy link

github-actions bot commented May 3, 2024

🚀 Development release published. You may be able to view the changes at https://marimo.app?v=0.4.11-dev10

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.

Naming in cycle resolution
2 participants