MrMustard for GKP state preparation

Hello are there tutorials available for performing non-Gaussian state preparation with a GBS device using the latest version of the MrMustard library? I am trying to investigate the capabilities of MrMustard for heralding GKP states using GBS. This paper (in particular Fig. 3) seems to suggest this is possible but the API for the code snippets in the paper seem to be older than the current version of MrMustard. The code here does not seem to work with the latest version (0.7.3) either and results in the following error:

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
File ~/.local/lib/python3.10/site-packages/mrmustard/math/backend_manager.py:174, in BackendManager.change_backend(self, name)
    173 try:
--> 174     backend = getattr(module, object)()
    175 except AttributeError:
    176     # lazy import

AttributeError: module 'mrmustard.math.backend_tensorflow' has no attribute 'BackendTensorflow'

During handling of the above exception, another exception occurred:

AttributeError                            Traceback (most recent call last)
Cell In[2], line 6
      3 from mrmustard.physics import fidelity
      4 from mrmustard.training import Optimizer
----> 6 math.change_backend("tensorflow")
      8 D = Dgate(x = 0.1, y = -0.5, x_trainable=True, y_trainable=True)
      9 L = Attenuator(transmissivity=0.5)

File ~/.local/lib/python3.10/site-packages/mrmustard/math/backend_manager.py:179, in BackendManager.change_backend(self, name)
    177     loader = all_modules[name]["loader"]
    178     loader.exec_module(module)
--> 179     backend = getattr(module, object)()
    181 # switch backend
...
   (...)
     82     a scalar tensor.
     83   """

AttributeError: module 'keras._tf_keras.keras' has no attribute '__internal__'

Hi @Amanuel ,

Welcome back to the Forum!

Let me check with our team and get back to you on this.

Hi @Amanuel ,

My colleague Luke actually figured out the issue! :raising_hands: It was not the docs but a dependency problem.

The issue seems to be that too recent a version of tensorflow gets installed by default (following these steps)

> mkdir MrMustard
> cd MrMustard
> uv venv --python 3.11
> uv pip install mrmustard, jupyterlab, ipywidgets

In order to fix the issue you need to use a version of TensorFlow not greater than 2.16.

> uv pip install "tensorflow<=2.16"

With this version things should work.

Let us know if this works for you!

Thanks @CatalinaAlbornoz this fixes the issue! One more question: it seems like MrMustard takes care of picked a Fock space cutoff for the user on it’s own is that correct? And it selects a cutoff for each mode individually by computing what cutoff for that mode will result in it’s marginalized photon number probability distributions having a total probability specified by mrmustard.settings.AUTOCUTOFF_PROBABILITY?

Hi @Amanuel ,

Yes, your understanding is correct, with a couple of details worth adding.

  1. The auto-cutoff is only computed for Gaussian states that don’t already have a Fock representation. If the state already carries a ket/dm (Fock) representation, the cutoffs are simply read off from that array’s existing shape (no marginal computation happens).
  2. You can always override it by passing cutoffs=[...] to methods like .ket(...) / .dm(...), or by changing the setting globally, e.g. mrmustard.settings.AUTOCUTOFF_PROBABILITY = 0.9999.
  3. This probability-based logic is what’s in current MrMustard (0.7.3). In older 0.3.0 the auto-cutoff used a mean + k·stdev heuristic (AUTOCUTOFF_STDEV_FACTOR) rather than a cumulative-probability threshold, so the exact behavior depends on the installed version.

I hope this helps!

1 Like