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

NotImplementedError: Function convolution not implemented for backend numpy #323

Open
1 task done
ewanmer20 opened this issue Jan 15, 2024 · 1 comment
Open
1 task done
Labels
bug Something isn't working

Comments

@ewanmer20
Copy link

Before posting a bug report

  • I have searched exisisting GitHub issues to make sure the issue does not already exist.

Expected behavior

Hello,
I have recently started using MrMustard and I tried to run this simple piece of code from the website to check if I installed it correctly. I attached a text file that contains all the dependencies of the python environment I have been using. To set up the environment, I just ran the following commands in the anaconda prompt:

conda create -n mrmustardtest python=3.9
conda activate mrmustardtest
pip install git+https://github.com/XanaduAI/MrMustard.git

Actual behavior

Error message

Reproduces how often

Every time

System information

name: mrmustardtest
channels:
  - defaults
dependencies:
  - ca-certificates=2023.12.12=haa95532_0
  - openssl=3.0.12=h2bbff1b_0
  - pip=23.3.1=py39haa95532_0
  - python=3.9.18=h1aa4202_0
  - setuptools=68.2.2=py39haa95532_0
  - sqlite=3.41.2=h2bbff1b_0
  - tzdata=2023d=h04d1e81_0
  - vc=14.2=h21ff451_1
  - vs2015_runtime=14.27.29016=h5e58377_2
  - wheel=0.41.2=py39haa95532_0
  - pip:
      - absl-py==2.0.0
      - astunparse==1.6.3
      - cachetools==5.3.2
      - certifi==2023.11.17
      - charset-normalizer==3.3.2
      - click==8.1.7
      - cloudpickle==3.0.0
      - colorama==0.4.6
      - commonmark==0.9.1
      - cycler==0.12.1
      - dask==2024.1.0
      - decorator==5.1.1
      - dm-tree==0.1.8
      - flatbuffers==23.5.26
      - fonttools==4.47.2
      - fsspec==2023.12.2
      - gast==0.5.4
      - google-auth==2.26.2
      - google-auth-oauthlib==1.2.0
      - google-pasta==0.2.0
      - grpcio==1.60.0
      - h5py==3.10.0
      - idna==3.6
      - importlib-metadata==7.0.1
      - julia==0.6.1
      - keras==2.15.0
      - kiwisolver==1.4.5
      - libclang==16.0.6
      - llvmlite==0.39.1
      - locket==1.0.0
      - markdown==3.5.2
      - markupsafe==2.1.3
      - matplotlib==3.5.0
      - ml-dtypes==0.2.0
      - mpmath==1.3.0
      - mrmustard==0.7.0.dev0
      - networkx==3.2.1
      - numba==0.56.4
      - numpy==1.23.5
      - oauthlib==3.2.2
      - opt-einsum==3.3.0
      - packaging==23.2
      - partd==1.4.1
      - pillow==10.2.0
      - protobuf==4.23.4
      - pyasn1==0.5.1
      - pyasn1-modules==0.3.0
      - pygments==2.17.2
      - pyparsing==3.1.1
      - python-dateutil==2.8.2
      - pyyaml==6.0.1
      - requests==2.31.0
      - requests-oauthlib==1.3.1
      - rich==10.15.1
      - rsa==4.9
      - scipy==1.8.0
      - setuptools-scm==8.0.4
      - six==1.16.0
      - sympy==1.12
      - tensorboard==2.15.1
      - tensorboard-data-server==0.7.2
      - tensorflow==2.15.0
      - tensorflow-estimator==2.15.0
      - tensorflow-intel==2.15.0
      - tensorflow-io-gcs-filesystem==0.31.0
      - tensorflow-probability==0.22.1
      - termcolor==2.4.0
      - thewalrus==0.19.0
      - tomli==2.0.1
      - toolz==0.12.0
      - tqdm==4.66.1
      - typing-extensions==4.9.0
      - urllib3==2.1.0
      - werkzeug==3.0.1
      - wrapt==1.14.1
      - zipp==3.17.0
prefix: C:\Users\em1120\AppData\Local\anaconda3\envs\mrmustardtest

Source code

from mrmustard.lab import *
results = Gaussian(3) << PNRDetector(efficiency = [0.9, 0.8], modes = [0,1])
print(results[2,3])

Tracebacks

Traceback (most recent call last):
  File "C:\Users\em1120\AppData\Local\anaconda3\envs\mrmustardtest\lib\site-packages\mrmustard\math\backend_manager.py", line 105, in _apply
    attr = getattr(self.backend, fn)
AttributeError: 'BackendNumpy' object has no attribute 'convolution'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "c:\Users\em1120\qkdlab\Simulations\MrMustardSimulation\QKDProtocol.py", line 48, in <module>
    results = Gaussian(3) << PNRDetector(efficiency = [0.9, 0.8], modes = [0,1])
  File "C:\Users\em1120\AppData\Local\anaconda3\envs\mrmustardtest\lib\site-packages\mrmustard\lab\detectors.py", line 97, in __init__
    self.recompute_stochastic_channel()
  File "C:\Users\em1120\AppData\Local\anaconda3\envs\mrmustardtest\lib\site-packages\mrmustard\lab\detectors.py", line 126, in recompute_stochastic_channel
    math.convolve_probs_1d(
  File "C:\Users\em1120\AppData\Local\anaconda3\envs\mrmustardtest\lib\site-packages\mrmustard\math\backend_manager.py", line 1455, in convolve_probs_1d
    return self.convolve_probs(prob, q)
  File "C:\Users\em1120\AppData\Local\anaconda3\envs\mrmustardtest\lib\site-packages\mrmustard\math\backend_manager.py", line 1470, in convolve_probs
    return self.convolution(
  File "C:\Users\em1120\AppData\Local\anaconda3\envs\mrmustardtest\lib\site-packages\mrmustard\math\backend_manager.py", line 430, in convolution
    return self._apply("convolution", (array, filters, padding, data_format))
  File "C:\Users\em1120\AppData\Local\anaconda3\envs\mrmustardtest\lib\site-packages\mrmustard\math\backend_manager.py", line 109, in _apply
    raise NotImplementedError(msg)
NotImplementedError: Function ``convolution`` not implemented for backend ``numpy``.

Additional information

No response

@ewanmer20 ewanmer20 added the bug Something isn't working label Jan 15, 2024
@sylviemonet
Copy link
Contributor

sylviemonet commented Jan 15, 2024

Hi @ewanmer20 , I would suggest to add this change backend thing at the beginning of your code.
`import mrmustard.math as math

math.change_backend("tensorflow")`
Because now MrMustard supports two backends (Numpy and TensorFlow) and this is related to the backend TensorFlow originally.

One may experience a crash of code because of the Memory issue, so we also suggest to do this as a PNRDetector:
Gaussian(3) << Fock([2,3], modes=[0,1])

At the same time, our team is going to work on this issue and please let us know if you have more questions related.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants