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

Preview for Mira context #114

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

Preview for Mira context #114

wants to merge 2 commits into from

Conversation

satchelbaldwin
Copy link
Contributor

Adds preview support for Mira modelling context.

@brandomr brandomr marked this pull request as ready for review March 19, 2024 21:11
Copy link
Contributor

@mattprintz mattprintz left a comment

Choose a reason for hiding this comment

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

Suggestions.

Comment on lines +11 to +14
with open(filename, "rb") as f:
data = f.read()
enc = base64.b64encode(bytes(data))
return enc.decode("utf-8")
Copy link
Contributor

Choose a reason for hiding this comment

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

This will actually leave files in the "jupyter" user's home directory, since subkernels currently actually run as a normal kernel in the same environment. We probably don't want to create clutter.
We should probably delete these files after we read them, or write to a IOBuffer so the contents are all in memory.

Comment on lines +17 to +24
__state = locals()
__models = {}

for model in {{model_vars}}:
model: str
__models[model] = {"text/plain": repr(__state[model]), "image/png": __visualize_model(model, __state[model])}

del __state
Copy link
Contributor

Choose a reason for hiding this comment

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

By using jinja templating, I think we can clean this up to something like the following.
(Note: I haven't really tested this, so don't take this as a solved solution.)
As you can see, instead of generating and reading from a locals() dict, we are just generating code that access the variables directly.

Suggested change
__state = locals()
__models = {}
for model in {{model_vars}}:
model: str
__models[model] = {"text/plain": repr(__state[model]), "image/png": __visualize_model(model, __state[model])}
del __state
__models = {
{% for model_var in model_vars %}
"{{model_var}}": {"text/plain": repr({{model_var}}), "image/png": __visualize_model("{{model_var}}", {{model_var}})}
{% endfor %}
}

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