-
Notifications
You must be signed in to change notification settings - Fork 54
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
Move splitting primitives to serialize library #407
Merged
saulshanabrook
merged 5 commits into
egraphs-good:main
from
saulshanabrook:serialize-move-split-primitives
Sep 11, 2024
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
dc00449
Move splitting primitives to serialize library
saulshanabrook a555b2f
fix nits
saulshanabrook 405395d
Update egraph serialized to merged version
saulshanabrook bcff2a5
Fix method name
saulshanabrook 20a84f4
Other fix
saulshanabrook File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,3 +19,4 @@ _scratch.egg | |
|
||
# racket | ||
scripts/compiled | ||
tests/*.json |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -43,6 +43,9 @@ struct Args { | |
/// Maximum number of calls per function to render in dot/svg output | ||
#[clap(long, default_value = "40")] | ||
max_calls_per_function: usize, | ||
/// Number of times to inline leaves | ||
#[clap(long, default_value = "0")] | ||
serialize_n_inline_leaves: usize, | ||
Comment on lines
+46
to
+48
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I added the ability to inline leaves via the egglog CLI when making visualizations/json |
||
} | ||
|
||
// test if the current command should be evaluated | ||
|
@@ -209,31 +212,25 @@ fn main() { | |
std::process::exit(1) | ||
} | ||
} | ||
// if we are splitting primitive outputs, add `-split` to the end of the file name | ||
let serialize_filename = if args.serialize_split_primitive_outputs { | ||
input.with_file_name(format!( | ||
"{}-split", | ||
input.file_stem().unwrap().to_str().unwrap() | ||
)) | ||
} else { | ||
input.clone() | ||
}; | ||
if args.to_json { | ||
let json_path = serialize_filename.with_extension("json"); | ||
let config = SerializeConfig { | ||
split_primitive_outputs: args.serialize_split_primitive_outputs, | ||
..SerializeConfig::default() | ||
}; | ||
let serialized = egraph.serialize(config); | ||
serialized.to_json_file(json_path).unwrap(); | ||
} | ||
|
||
if args.to_dot || args.to_svg { | ||
let serialized = egraph.serialize_for_graphviz( | ||
args.serialize_split_primitive_outputs, | ||
args.max_functions, | ||
args.max_calls_per_function, | ||
); | ||
if args.to_json || args.to_dot || args.to_svg { | ||
let mut serialized = egraph.serialize(SerializeConfig::default()); | ||
if args.serialize_split_primitive_outputs { | ||
serialized.split_classes(|id, _| egraph.from_node_id(id).is_primitive()) | ||
} | ||
for _ in 0..args.serialize_n_inline_leaves { | ||
serialized.inline_leaves(); | ||
} | ||
|
||
// if we are splitting primitive outputs, add `-split` to the end of the file name | ||
let serialize_filename = if args.serialize_split_primitive_outputs { | ||
input.with_file_name(format!( | ||
"{}-split", | ||
input.file_stem().unwrap().to_str().unwrap() | ||
)) | ||
} else { | ||
input.clone() | ||
}; | ||
if args.to_dot { | ||
let dot_path = serialize_filename.with_extension("dot"); | ||
serialized.to_dot_file(dot_path).unwrap() | ||
|
@@ -242,6 +239,10 @@ fn main() { | |
let svg_path = serialize_filename.with_extension("svg"); | ||
serialized.to_svg_file(svg_path).unwrap() | ||
} | ||
if args.to_json { | ||
let json_path = serialize_filename.with_extension("json"); | ||
serialized.to_json_file(json_path).unwrap(); | ||
} | ||
} | ||
// no need to drop the egraph if we are going to exit | ||
if idx == args.inputs.len() - 1 { | ||
|
@@ -259,12 +260,12 @@ mod tests { | |
#[rustfmt::skip] | ||
let test_cases = vec![ | ||
vec![ | ||
"(extract", | ||
"\"1", | ||
")", | ||
"(", | ||
")))", | ||
"\"", | ||
"(extract", | ||
"\"1", | ||
")", | ||
"(", | ||
")))", | ||
"\"", | ||
";; )", | ||
")" | ||
], | ||
|
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I removed this helper function since it wasn't really doing much