q-optimize / c3

Toolset for control, calibration and characterization of physical systems
https://c3-toolset.readthedocs.io/
Apache License 2.0
66 stars 36 forks source link

Problems in examples/Full_loop_single_qubit.ipynb #244

Open frankharkins opened 7 months ago

frankharkins commented 7 months ago

Describe the bug

When running the example notebook, I came across two problems:

  1. The following warning appears over 5000 times:
    WARNING:tensorflow:You are casting an input of type complex128 to an incompatible dtype
     float64.  This will discard the imaginary part and may not be what you intended.
  2. There's an error in code cell 41, although the notebook does continue to execute despite this.

    Traceback ```pytb Error in callback (for post_execute), with arguments args (),kwargs {}: --------------------------------------------------------------------------- ValueError Traceback (most recent call last) File ~/Documents/testspace/.venv/lib/python3.11/site-packages/matplotlib/pyplot.py:197, in _draw_all_if_interactive() 195 def _draw_all_if_interactive() -> None: 196 if matplotlib.is_interactive(): --> 197 draw_all() File ~/Documents/testspace/.venv/lib/python3.11/site-packages/matplotlib/_pylab_helpers.py:132, in Gcf.draw_all(cls, force) 130 for manager in cls.get_all_fig_managers(): 131 if force or manager.canvas.figure.stale: --> 132 manager.canvas.draw_idle() File ~/Documents/testspace/.venv/lib/python3.11/site-packages/matplotlib/backend_bases.py:1893, in FigureCanvasBase.draw_idle(self, *args, **kwargs) 1891 if not self._is_idle_drawing: 1892 with self._idle_draw_cntx(): -> 1893 self.draw(*args, **kwargs) File ~/Documents/testspace/.venv/lib/python3.11/site-packages/matplotlib/backends/backend_agg.py:388, in FigureCanvasAgg.draw(self) 385 # Acquire a lock on the shared font cache. 386 with (self.toolbar._wait_cursor_for_draw_cm() if self.toolbar 387 else nullcontext()): --> 388 self.figure.draw(self.renderer) 389 # A GUI class may be need to update a window using this draw, so 390 # don't forget to call the superclass. 391 super().draw() File ~/Documents/testspace/.venv/lib/python3.11/site-packages/matplotlib/artist.py:95, in _finalize_rasterization..draw_wrapper(artist, renderer, *args, **kwargs) 93 @wraps(draw) 94 def draw_wrapper(artist, renderer, *args, **kwargs): ---> 95 result = draw(artist, renderer, *args, **kwargs) 96 if renderer._rasterizing: 97 renderer.stop_rasterizing() File ~/Documents/testspace/.venv/lib/python3.11/site-packages/matplotlib/artist.py:72, in allow_rasterization..draw_wrapper(artist, renderer) 69 if artist.get_agg_filter() is not None: 70 renderer.start_filter() ---> 72 return draw(artist, renderer) 73 finally: 74 if artist.get_agg_filter() is not None: File ~/Documents/testspace/.venv/lib/python3.11/site-packages/matplotlib/figure.py:3154, in Figure.draw(self, renderer) 3151 # ValueError can occur when resizing a window. 3153 self.patch.draw(renderer) -> 3154 mimage._draw_list_compositing_images( 3155 renderer, self, artists, self.suppressComposite) 3157 for sfig in self.subfigs: 3158 sfig.draw(renderer) File ~/Documents/testspace/.venv/lib/python3.11/site-packages/matplotlib/image.py:132, in _draw_list_compositing_images(renderer, parent, artists, suppress_composite) 130 if not_composite or not has_images: 131 for a in artists: --> 132 a.draw(renderer) 133 else: 134 # Composite any adjacent images together 135 image_group = [] File ~/Documents/testspace/.venv/lib/python3.11/site-packages/matplotlib/artist.py:72, in allow_rasterization..draw_wrapper(artist, renderer) 69 if artist.get_agg_filter() is not None: 70 renderer.start_filter() ---> 72 return draw(artist, renderer) 73 finally: 74 if artist.get_agg_filter() is not None: File ~/Documents/testspace/.venv/lib/python3.11/site-packages/matplotlib/axes/_base.py:3070, in _AxesBase.draw(self, renderer) 3067 if artists_rasterized: 3068 _draw_rasterized(self.figure, artists_rasterized, renderer) -> 3070 mimage._draw_list_compositing_images( 3071 renderer, self, artists, self.figure.suppressComposite) 3073 renderer.close_group('axes') 3074 self.stale = False File ~/Documents/testspace/.venv/lib/python3.11/site-packages/matplotlib/image.py:132, in _draw_list_compositing_images(renderer, parent, artists, suppress_composite) 130 if not_composite or not has_images: 131 for a in artists: --> 132 a.draw(renderer) 133 else: 134 # Composite any adjacent images together 135 image_group = [] File ~/Documents/testspace/.venv/lib/python3.11/site-packages/matplotlib/artist.py:72, in allow_rasterization..draw_wrapper(artist, renderer) 69 if artist.get_agg_filter() is not None: 70 renderer.start_filter() ---> 72 return draw(artist, renderer) 73 finally: 74 if artist.get_agg_filter() is not None: File ~/Documents/testspace/.venv/lib/python3.11/site-packages/matplotlib/lines.py:800, in Line2D.draw(self, renderer) 797 lc_rgba = mcolors.to_rgba(self._color, self._alpha) 798 gc.set_foreground(lc_rgba, isRGBA=True) --> 800 gc.set_dashes(*self._dash_pattern) 801 renderer.draw_path(gc, tpath, affine.frozen()) 802 gc.restore() File ~/Documents/testspace/.venv/lib/python3.11/site-packages/matplotlib/backend_bases.py:965, in GraphicsContextBase.set_dashes(self, dash_offset, dash_list) 962 raise ValueError( 963 "All values in the dash list must be non-negative") 964 if dl.size and not np.any(dl > 0.0): --> 965 raise ValueError( 966 'At least one value in the dash list must be positive') 967 self._dashes = dash_offset, dash_list ValueError: At least one value in the dash list must be positive --------------------------------------------------------------------------- ValueError Traceback (most recent call last) File ~/Documents/testspace/.venv/lib/python3.11/site-packages/IPython/core/formatters.py:343, in BaseFormatter.__call__(self, obj) 341 pass 342 else: --> 343 return printer(obj) 344 # Finally look for special method names 345 method = get_real_method(obj, self.print_method) File ~/Documents/testspace/.venv/lib/python3.11/site-packages/IPython/core/pylabtools.py:152, in print_figure(fig, fmt, bbox_inches, base64, **kwargs) 149 from matplotlib.backend_bases import FigureCanvasBase 150 FigureCanvasBase(fig) --> 152 fig.canvas.print_figure(bytes_io, **kw) 153 data = bytes_io.getvalue() 154 if fmt == 'svg': File ~/Documents/testspace/.venv/lib/python3.11/site-packages/matplotlib/backend_bases.py:2164, in FigureCanvasBase.print_figure(self, filename, dpi, facecolor, edgecolor, orientation, format, bbox_inches, pad_inches, bbox_extra_artists, backend, **kwargs) 2161 # we do this instead of `self.figure.draw_without_rendering` 2162 # so that we can inject the orientation 2163 with getattr(renderer, "_draw_disabled", nullcontext)(): -> 2164 self.figure.draw(renderer) 2165 if bbox_inches: 2166 if bbox_inches == "tight": File ~/Documents/testspace/.venv/lib/python3.11/site-packages/matplotlib/artist.py:95, in _finalize_rasterization..draw_wrapper(artist, renderer, *args, **kwargs) 93 @wraps(draw) 94 def draw_wrapper(artist, renderer, *args, **kwargs): ---> 95 result = draw(artist, renderer, *args, **kwargs) 96 if renderer._rasterizing: 97 renderer.stop_rasterizing() File ~/Documents/testspace/.venv/lib/python3.11/site-packages/matplotlib/artist.py:72, in allow_rasterization..draw_wrapper(artist, renderer) 69 if artist.get_agg_filter() is not None: 70 renderer.start_filter() ---> 72 return draw(artist, renderer) 73 finally: 74 if artist.get_agg_filter() is not None: File ~/Documents/testspace/.venv/lib/python3.11/site-packages/matplotlib/figure.py:3154, in Figure.draw(self, renderer) 3151 # ValueError can occur when resizing a window. 3153 self.patch.draw(renderer) -> 3154 mimage._draw_list_compositing_images( 3155 renderer, self, artists, self.suppressComposite) 3157 for sfig in self.subfigs: 3158 sfig.draw(renderer) File ~/Documents/testspace/.venv/lib/python3.11/site-packages/matplotlib/image.py:132, in _draw_list_compositing_images(renderer, parent, artists, suppress_composite) 130 if not_composite or not has_images: 131 for a in artists: --> 132 a.draw(renderer) 133 else: 134 # Composite any adjacent images together 135 image_group = [] File ~/Documents/testspace/.venv/lib/python3.11/site-packages/matplotlib/artist.py:72, in allow_rasterization..draw_wrapper(artist, renderer) 69 if artist.get_agg_filter() is not None: 70 renderer.start_filter() ---> 72 return draw(artist, renderer) 73 finally: 74 if artist.get_agg_filter() is not None: File ~/Documents/testspace/.venv/lib/python3.11/site-packages/matplotlib/axes/_base.py:3070, in _AxesBase.draw(self, renderer) 3067 if artists_rasterized: 3068 _draw_rasterized(self.figure, artists_rasterized, renderer) -> 3070 mimage._draw_list_compositing_images( 3071 renderer, self, artists, self.figure.suppressComposite) 3073 renderer.close_group('axes') 3074 self.stale = False File ~/Documents/testspace/.venv/lib/python3.11/site-packages/matplotlib/image.py:132, in _draw_list_compositing_images(renderer, parent, artists, suppress_composite) 130 if not_composite or not has_images: 131 for a in artists: --> 132 a.draw(renderer) 133 else: 134 # Composite any adjacent images together 135 image_group = [] File ~/Documents/testspace/.venv/lib/python3.11/site-packages/matplotlib/artist.py:72, in allow_rasterization..draw_wrapper(artist, renderer) 69 if artist.get_agg_filter() is not None: 70 renderer.start_filter() ---> 72 return draw(artist, renderer) 73 finally: 74 if artist.get_agg_filter() is not None: File ~/Documents/testspace/.venv/lib/python3.11/site-packages/matplotlib/lines.py:800, in Line2D.draw(self, renderer) 797 lc_rgba = mcolors.to_rgba(self._color, self._alpha) 798 gc.set_foreground(lc_rgba, isRGBA=True) --> 800 gc.set_dashes(*self._dash_pattern) 801 renderer.draw_path(gc, tpath, affine.frozen()) 802 gc.restore() File ~/Documents/testspace/.venv/lib/python3.11/site-packages/matplotlib/backend_bases.py:965, in GraphicsContextBase.set_dashes(self, dash_offset, dash_list) 962 raise ValueError( 963 "All values in the dash list must be non-negative") 964 if dl.size and not np.any(dl > 0.0): --> 965 raise ValueError( 966 'At least one value in the dash list must be positive') 967 self._dashes = dash_offset, dash_list ValueError: At least one value in the dash list must be positive ```

To Reproduce

Clone the repo, install:

pip install -e .
pip install notebook

Then run the notebook on OSX.

pip freeze output ``` absl-py==2.1.0 adaptive==1.1.0 alabaster==0.7.16 anyascii==0.3.2 anyio==4.3.0 appnope==0.1.4 argon2-cffi==23.1.0 argon2-cffi-bindings==21.2.0 arrow==1.3.0 astroid==3.1.0 asttokens==2.4.1 astunparse==1.6.3 async-lru==2.0.4 attrs==23.2.0 Babel==2.14.0 beautifulsoup4==4.12.3 bleach==6.1.0 -e git+https://github.com/frankharkins/c3.git@48b7917eb8d84e1471ff9fb911129c354e752dbf#egg=c3_toolset cachetools==5.3.3 certifi==2024.2.2 cffi==1.16.0 cfgv==3.4.0 charset-normalizer==3.3.2 cloudpickle==3.0.0 cma==3.3.0 comm==0.2.1 contourpy==1.2.0 coverage==7.4.3 cycler==0.12.1 debugpy==1.8.1 decorator==5.1.1 defusedxml==0.7.1 dill==0.3.8 distlib==0.3.8 dm-tree==0.1.8 docutils==0.20.1 execnet==2.0.2 executing==2.0.1 fastjsonschema==2.19.1 filelock==3.13.1 flatbuffers==23.5.26 fonttools==4.49.0 fqdn==1.5.1 gast==0.5.4 google-auth==2.28.1 google-auth-oauthlib==1.2.0 google-pasta==0.2.0 grpcio==1.62.0 h11==0.14.0 h5py==3.10.0 hjson==3.1.0 httpcore==1.0.4 httpx==0.27.0 identify==2.5.35 idna==3.6 imagesize==1.4.1 iniconfig==2.0.0 ipykernel==6.29.3 ipython==8.22.2 isoduration==20.11.0 jedi==0.19.1 Jinja2==3.1.3 json5==0.9.20 jsonpointer==2.4 jsonschema==4.21.1 jsonschema-specifications==2023.12.1 jupyter-events==0.9.0 jupyter-lsp==2.2.3 jupyter_client==8.6.0 jupyter_core==5.7.1 jupyter_server==2.13.0 jupyter_server_terminals==0.5.2 jupyterlab==4.1.3 jupyterlab_pygments==0.3.0 jupyterlab_server==2.25.3 keras==2.15.0 kiwisolver==1.4.5 libclang==16.0.6 loky==3.4.1 Markdown==3.5.2 markdown-it-py==3.0.0 MarkupSafe==2.1.5 matplotlib==3.8.3 matplotlib-inline==0.1.6 mdurl==0.1.2 mistune==3.0.2 ml-dtypes==0.2.0 mpmath==1.3.0 nbclient==0.9.0 nbconvert==7.16.2 nbformat==5.9.2 nest-asyncio==1.6.0 nodeenv==1.8.0 notebook==7.1.1 notebook_shim==0.2.4 numpy==1.26.4 oauthlib==3.2.2 opt-einsum==3.3.0 overrides==7.7.0 packaging==23.2 pandas==2.2.1 pandocfilters==1.5.1 parso==0.8.3 pbr==6.0.0 pexpect==4.9.0 pillow==10.2.0 platformdirs==4.2.0 pluggy==1.4.0 ply==3.11 pre-commit==3.6.2 prometheus_client==0.20.0 prompt-toolkit==3.0.43 protobuf==4.25.3 psutil==5.9.8 ptyprocess==0.7.0 pure-eval==0.2.2 pyasn1==0.5.1 pyasn1-modules==0.3.0 pycparser==2.21 Pygments==2.17.2 pyparsing==3.1.1 pytest==8.0.2 pytest-cov==4.1.0 pytest-xdist==3.5.0 python-dateutil==2.9.0.post0 python-json-logger==2.0.7 pytz==2024.1 PyYAML==6.0.1 pyzmq==25.1.2 qiskit==0.46.0 qiskit-aer==0.13.3 qiskit-terra==0.46.0 referencing==0.33.0 requests==2.31.0 requests-oauthlib==1.3.1 rfc3339-validator==0.1.4 rfc3986-validator==0.1.1 rich==13.7.1 rpds-py==0.18.0 rsa==4.9 rustworkx==0.14.1 scipy==1.12.0 Send2Trash==1.8.2 six==1.16.0 sniffio==1.3.1 snowballstemmer==2.2.0 sortedcollections==2.1.0 sortedcontainers==2.4.0 soupsieve==2.5 Sphinx==7.2.6 sphinx-autoapi==3.0.0 sphinxcontrib-applehelp==1.0.8 sphinxcontrib-devhelp==1.0.6 sphinxcontrib-htmlhelp==2.0.5 sphinxcontrib-jsmath==1.0.1 sphinxcontrib-qthelp==1.0.7 sphinxcontrib-serializinghtml==1.1.10 stack-data==0.6.3 stevedore==5.2.0 symengine==0.11.0 sympy==1.12 tensorboard==2.15.2 tensorboard-data-server==0.7.2 tensorflow==2.15.0 tensorflow-estimator==2.15.0 tensorflow-io-gcs-filesystem==0.36.0 tensorflow-probability==0.23.0 termcolor==2.4.0 terminado==0.18.0 tinycss2==1.2.1 tornado==6.4 traitlets==5.14.1 types-python-dateutil==2.8.19.20240106 typing_extensions==4.10.0 tzdata==2024.1 uri-template==1.3.0 urllib3==2.2.1 versioningit==3.0.0 virtualenv==20.25.1 wcwidth==0.2.13 webcolors==1.13 webencodings==0.5.1 websocket-client==1.7.0 Werkzeug==3.0.1 wrapt==1.14.1 ```

Expected behavior

No (or very few) warnings and no errors.

Environment (please complete the following information)