The problem (described below) is that, when importing tsim in a notebook, we get an error because ipywidgets is not installed.
It would be nice to have either (a) tsim have an extra that installs ipywidgets or (b) to have ipywidgets be a dependency of tsim.
Below is the context of the issue copied from the issue in bloqade-circuit: QuEraComputing/bloqade-circuit#837
With the new version of bloqade-tsim==0.1.4, which no longer installs "ipywidgets" by default, we can an import error from "pyzx_param". However, the error message is masked by the bloqade.tsim ImportError override.
To reproduce
- Run
uv sync --no-dev
- Run
uv pip install bloqade-tsim==0.1.4
- Run the following code in a notebook
from bloqade.tsim import Circuit
from bloqade import squin
@squin.kernel
def test_kernel():
reg = squin.qalloc(5)
return
test_circ = Circuit(test_kernel)
This will yield the following error
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
Cell In[3], line 1
----> 1 test_circ = Circuit(test_kernel)
File ~/Desktop/qmain/personal-workspace/bloqade-circuit/src/bloqade/tsim/circuit.py:46, in Circuit.__init__(self, kernel, insert_ticks, *args, **kwargs)
44 if isinstance(kernel, ir.Method):
45 kernel = _codegen(kernel, insert_ticks=insert_ticks)
---> 46 super().__init__(kernel, *args, **kwargs)
File ~/Desktop/qmain/personal-workspace/bloqade-circuit/src/bloqade/tsim/circuit.py:13, in _MissingTsimCircuit.__init__(self, *args, **kwargs)
12 def __init__(self, *args, **kwargs):
---> 13 raise ImportError(
14 "tsim is required for bloqade.tsim.Circuit. "
15 'Install with: pip install "bloqade-circuit[tsim]"'
16 )
ImportError: tsim is required for bloqade.tsim.Circuit. Install with: pip install "bloqade-circuit[tsim]"
Issue
The problem is that the user has already installed tsim but the ImportError message says that they should install tsim to fix the problem. The problem is not with installing tsim; the problem can be seen if we import tsim directly. Running the code
gives the following
---------------------------------------------------------------------------
ModuleNotFoundError Traceback (most recent call last)
Cell In[4], line 1
----> 1 from tsim import Circuit
File ~/Desktop/qmain/personal-workspace/bloqade-circuit/.venv/lib/python3.12/site-packages/tsim/__init__.py:19
1 """ZX-calculus based circuit sampler for universal quantum circuits.
2
3 tsim supports fast sampling from quantum circuits with few non-Clifford gates.
(...) 14 - `utils/`: Utility functions for visualization and linear algebra.
15 """
17 __version__ = "0.1.4"
---> 19 from tsim.circuit import Circuit as Circuit
20 from tsim.sampler import (
21 CompiledDetectorSampler as CompiledDetectorSampler,
22 CompiledMeasurementSampler as CompiledMeasurementSampler,
23 )
File ~/Desktop/qmain/personal-workspace/bloqade-circuit/.venv/lib/python3.12/site-packages/tsim/circuit.py:14
3 from __future__ import annotations
5 from typing import (
6 TYPE_CHECKING,
7 Any,
(...) 11 overload,
12 )
---> 14 import pyzx_param as zx
15 import stim
16 from pyzx_param.graph.base import BaseGraph
File ~/Desktop/qmain/personal-workspace/bloqade-circuit/.venv/lib/python3.12/site-packages/pyzx_param/__init__.py:48
46 from . import tikz
47 from . import simulate
---> 48 from . import editor
49 from . import routing
50 from . import local_search
File ~/Desktop/qmain/personal-workspace/bloqade-circuit/.venv/lib/python3.12/site-packages/pyzx_param/editor.py:38
35 from .editor_actions import MATCHES_VERTICES, MATCHES_EDGES, operations, operations_to_js
37 if get_mode() == 'notebook':
---> 38 import ipywidgets as widgets
39 from traitlets import Unicode, validate, Bool, Int, Float
40 from IPython.display import display, HTML
ModuleNotFoundError: No module named 'ipywidgets'
So the true problem is that the user needs to install 'ipywidgets'.
The problem (described below) is that, when importing tsim in a notebook, we get an error because
ipywidgetsis not installed.It would be nice to have either (a) tsim have an extra that installs
ipywidgetsor (b) to haveipywidgetsbe a dependency of tsim.Below is the context of the issue copied from the issue in bloqade-circuit: QuEraComputing/bloqade-circuit#837
With the new version of bloqade-tsim==0.1.4, which no longer installs "ipywidgets" by default, we can an import error from "pyzx_param". However, the error message is masked by the bloqade.tsim ImportError override.
To reproduce
uv sync --no-devuv pip install bloqade-tsim==0.1.4This will yield the following error
Issue
The problem is that the user has already installed tsim but the ImportError message says that they should install tsim to fix the problem. The problem is not with installing tsim; the problem can be seen if we import tsim directly. Running the code
gives the following
So the true problem is that the user needs to install 'ipywidgets'.