question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[RELAY][RFC] Modify repr to return a valid Python AST

See original GitHub issue

I think we should update repr and by extension the debug printing methods defined in C++ to update a valid Python AST. This would make it possible for us to extract the debug representation when printing it and paste it into a Python file to edit and modify.

I think this will be very useful for experimenting and debugging.

cc @joshpoll @wweic @tqchen @MarisaKirisame

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

4reactions
jroeschcommented, Feb 21, 2019

My goal is to obtain a program fragment like:

Function(
  params=[Var("x", type_annotation=TensorType([10, 10], float32))], 
  ret_type=TensorType([10, 10], float32), 
  body=Call(relay.op.get("add"), ...),
 ...)

Instead of:

FunctionNode([Var(x, ty=TensorType([10, 10], float32))], TensorType([10, 10], float32), CallNode(Op(add), [Var(x, ty=TensorType([10, 10], float32)), Var(x, ty=TensorType([10, 10], float32))], (nullptr), [TensorType([10, 10], float32), TensorType([10, 10], float32)]), [], (nullptr))

Upon further reflection we could just do this in Python, though there are some challenges due to our name representation.

My main goal is that we could obtain textual representation of the program which can be copy-and pasted back into the interpreter along the idea presented by the pprint module (https://docs.python.org/3.7/library/pprint.html).

My inspiration is that I was writing tests and debugging some transformations and it would be nice to be able to easily manually edit the AST to observe changes instead of having to write a Relay program to do so.

0reactions
tqchencommented, Feb 8, 2020

close due to inactive status

Read more comments on GitHub >

github_iconTop Results From Across the Web

ast — Abstract Syntax Trees — Python 3.11.1 documentation
The ast module helps Python applications to process trees of the Python abstract syntax grammar. The abstract syntax itself might change with each...
Read more >
python - Parse a .py file, read the AST, modify it, then write ...
You can parse the python code (represented in string) by simply calling the API ast.parse() . This returns the handle to Abstract Syntax...
Read more >
Python repr() Method (With Examples) - TutorialsTeacher
The repr() function returns the string representation of the value passed to eval function by default. For the custom class object, it returns...
Read more >
Python __str__() and __repr__() functions | DigitalOcean
This method is called when repr() function is invoked on the object. If possible, the string returned should be a valid Python expression ......
Read more >
RFC 5321: Simple Mail Transfer Protocol
When addresses, rather than free-form debugging information, are returned, EXPN and VRFY MUST return only valid domain addresses that are usable in SMTP ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found