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

Macro Symbolics.@register no longer working inside Pluto notebooks #2091

Closed
adomasbaliuka opened this issue May 4, 2022 · 2 comments
Closed
Labels
macro Julia macros: @oops

Comments

@adomasbaliuka
Copy link

I use Symbolics.@register to prevent Symbolics from expanding certain functions. It used to work fine inside a Pluto notebooks about a month ago.

Since one of the recent updates (still trying to determine which one), it only works the first time a notebook is run. If Pluto is restarted and the same notebook is loaded a second time, the macro seems to have no effect. Sometimes "rerunning" the cell using the macro, and then also rerunning all cells that depend on it in the right order "fixes" the issue. Is there a better way to do this? I was thinking about just "expanding the macro manually and pasting the resulting code in a cell" but that code looks a bit weird and I'd rather not have it in my notebook for 10 functions...

I know there are generally issues with macros inside Pluto notebooks, however, was there some change recently? The current behavior also seems to break Pluto's "execution order does not matter" rule.

To reproduce

  1. Copy the following code into a fresh Pluto notebook
# ╔═╡ 4b733e22-99b2-4e95-8657-89e75ff713e2
# copy-paste into a new Pluto notebook.
using Symbolics

# ╔═╡ f1323c27-cf2a-4716-b42e-d895ffbc76a6
h(p) = p^2

# ╔═╡ 3082e9b8-c8ff-4e4c-9276-4f81704908a6
@register h(a)

# ╔═╡ 4d630382-35e9-4d9d-b8d1-313fb4e518c9
@variables a

# ╔═╡ 717eb23d-5539-4c67-9297-7a4e19574a02
h(a)
  1. Note the intended behavior that h(a) is displayed as Latex rendered "h(a)", rather than "a^2", which is what would happen without Symbolics.@register.
  2. (optional: Save notebook to disk.) Terminate the notebook, start a new one from a new Julia session. Load the saved notebook again.
  3. Note that h(a) is rendered as "a^2". This means that Symbolics.@register no longer has any effect.
  4. Manually "re-execute" the macro call and then manually re-execute the h(a) cell.
  5. Notice that h(a) is rendered as "a^2" again.

System information

Julia Version 1.7.1
Commit ac5cc99908 (2021-12-22 19:35 UTC)
Platform Info:
  OS: Linux (x86_64-pc-linux-gnu)
  CPU: Intel(R) Core(TM) i7-8565U CPU @ 1.80GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-12.0.1 (ORCJIT, skylake)
@Pangoraw
Copy link
Collaborator

Pangoraw commented May 4, 2022

Thanks for the detailed report! There was some change to macros in #1966. But I think the real issue here is that @register h(a) has a side effect on h and should be in the same cell as the definition of ħ. I can't reproduce when the @register cell is above h(a) in the notebook.

@Pangoraw Pangoraw added the macro Julia macros: @oops label May 4, 2022
@adomasbaliuka
Copy link
Author

@Pangoraw Thanks for your response. Indeed, when the @register call is used in the same cell where the function is defined, it works. This solves my problem. Of course, it would be even better if macros just worked everywhere, but I know this is hard in Pluto.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
macro Julia macros: @oops
Projects
None yet
Development

No branches or pull requests

2 participants