XanaduAI / MrMustard

A differentiable bridge between phase space and Fock space
https://mrmustard.readthedocs.io/
Apache License 2.0
78 stars 25 forks source link

ImportError: cannot import name 'builder' from 'google.protobuf.internal' #186

Closed sylviemonet closed 6 months ago

sylviemonet commented 1 year ago

Before posting a bug report

Expected behavior

  1. conda create a new env with python=3.9.
  2. Install TensorFlow by Conda install tensorflow -> get tensorflow version 2.10.0
  3. Install MrMustard by pip install mrmustard.

Actual behavior

Always it has ImportError.

Reproduces how often

Everytime

System information

---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
Cell In[1], line 1
----> 1 import mrmustard as mm; mm.about()

File ~/miniforge3/envs/tf11/lib/python3.9/site-packages/mrmustard/__init__.py:92, in about()
     90 import numba
     91 import scipy
---> 92 import thewalrus
     93 import tensorflow
     95 # a QuTiP-style infobox

File ~/miniforge3/envs/tf11/lib/python3.9/site-packages/thewalrus/__init__.py:97
      1 # Copyright 2021 Xanadu Quantum Technologies Inc.
      2 
      3 # Licensed under the Apache License, Version 2.0 (the "License");
   (...)
     12 # See the License for the specific language governing permissions and
     13 # limitations under the License.
     14 r"""
     15 The Walrus
     16 ==========
   (...)
     95 ------------
     96 """
---> 97 import thewalrus.quantum
     98 import thewalrus.csamples
     99 import thewalrus.decompositions

File ~/miniforge3/envs/tf11/lib/python3.9/site-packages/thewalrus/quantum/__init__.py:140
    137 import warnings
    138 import functools
--> 140 from .fock_tensors import (
    141     pure_state_amplitude,
    142     state_vector,
    143     density_matrix_element,
    144     density_matrix,
    145     fock_tensor,
    146     probabilities,
    147     loss_mat,
    148     update_probabilities_with_loss,
    149     update_probabilities_with_noise,
    150     find_classical_subsystem,
    151     tvd_cutoff_bounds,
    152     n_body_marginals,
    153 )
    155 from .adjacency_matrices import (
    156     adj_scaling,
    157     adj_scaling_torontonian,
    158     adj_to_qmat,
    159 )
    161 from .gaussian_checks import (
    162     is_valid_cov,
    163     is_pure_cov,
   (...)
    166     is_symplectic,
    167 )

File ~/miniforge3/envs/tf11/lib/python3.9/site-packages/thewalrus/quantum/fock_tensors.py:27
     24 import numpy as np
     25 import dask
---> 27 from scipy.special import factorial as fac
     28 from numba import jit
     30 from ..symplectic import expand, is_symplectic, reduced_state

File ~/miniforge3/envs/tf11/lib/python3.9/site-packages/scipy/special/__init__.py:649
      1 """
      2 ========================================
      3 Special functions (:mod:`scipy.special`)
   (...)
    644 
    645 """
    647 from ._sf_error import SpecialFunctionWarning, SpecialFunctionError
--> 649 from . import _ufuncs
    650 from ._ufuncs import *
    652 from . import _basic

ImportError: dlopen(/Users/xanadu/miniforge3/envs/tf11/lib/python3.9/site-packages/scipy/special/_ufuncs.cpython-39-darwin.so, 0x0002): Library not loaded: '@rpath/liblapack.3.dylib'
  Referenced from: '/Users/xanadu/miniforge3/envs/tf11/lib/python3.9/site-packages/scipy/special/_ufuncs.cpython-39-darwin.so'
  Reason: tried: '/Users/xanadu/miniforge3/envs/tf11/lib/python3.9/site-packages/scipy/special/liblapack.3.dylib' (no such file), '/Users/xanadu/miniforge3/envs/tf11/lib/python3.9/site-packages/scipy/special/../../../../liblapack.3.dylib' (no such file), '/Users/xanadu/miniforge3/envs/tf11/lib/python3.9/site-packages/scipy/special/liblapack.3.dylib' (no such file), '/Users/xanadu/miniforge3/envs/tf11/lib/python3.9/site-packages/scipy/special/../../../../liblapack.3.dylib' (no such file), '/Users/xanadu/miniforge3/envs/tf11/bin/../lib/liblapack.3.dylib' (no such file), '/Users/xanadu/miniforge3/envs/tf11/bin/../lib/liblapack.3.dylib' (no such file), '/usr/local/lib/liblapack.3.dylib' (no such file), '/usr/lib/liblapack.3.dylib' (no such file)

Source code

from mrmustard.lab import *

Tracebacks

---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
Cell In[2], line 1
----> 1 from mrmustard.lab import *

File ~/miniforge3/envs/tf11/lib/python3.9/site-packages/mrmustard/lab/__init__.py:25
      1 # Copyright 2021 Xanadu Quantum Technologies Inc.
      2 
      3 # Licensed under the Apache License, Version 2.0 (the "License");
   (...)
     12 # See the License for the specific language governing permissions and
     13 # limitations under the License.
     15 r"""
     16 The lab module is all you need to construct and simulate photonic circuits.
     17 It contains the items you'd find in a lab:
   (...)
     22 * the Circuit class
     23 """
---> 25 from .circuit import *
     26 from .states import *
     27 from .gates import *

File ~/miniforge3/envs/tf11/lib/python3.9/site-packages/mrmustard/lab/circuit.py:26
     24 from typing import List, Tuple, Optional
     25 from mrmustard.types import Matrix, Vector
---> 26 from mrmustard.training import Parametrized
     27 from mrmustard.utils.xptensor import XPMatrix, XPVector
     28 from mrmustard.lab.abstract import Transformation

File ~/miniforge3/envs/tf11/lib/python3.9/site-packages/mrmustard/training/__init__.py:69
      1 # Copyright 2022 Xanadu Quantum Technologies Inc.
      2 
      3 # Licensed under the Apache License, Version 2.0 (the "License");
   (...)
     12 # See the License for the specific language governing permissions and
     13 # limitations under the License.
     15 """The optimizer module contains all logic for parameter and circuit optimization
     16 in Mr Mustard.
     17 
   (...)
     66 
     67 """
---> 69 from .parametrized import Parametrized
     70 from .optimizer import Optimizer

File ~/miniforge3/envs/tf11/lib/python3.9/site-packages/mrmustard/training/parametrized.py:22
     15 """This module contains the :class:`.Parametrized` class which acts as
     16 an abstract base class for all parametrized objects. Arguments of the
     17 class constructor generate a backend Tensor and are assigned to fields
     18 of the class.
     19 """
     21 from typing import Sequence, List, Generator, Any
---> 22 from mrmustard.math import Math
     23 from .parameter import create_parameter, Trainable, Constant, Parameter
     25 math = Math()

File ~/miniforge3/envs/tf11/lib/python3.9/site-packages/mrmustard/math/__init__.py:43
     40 from mrmustard import settings
     42 if importlib.util.find_spec("tensorflow"):
---> 43     from mrmustard.math.tensorflow import TFMath
     44 if importlib.util.find_spec("torch"):
     45     from mrmustard.math.torch import TorchMath

File ~/miniforge3/envs/tf11/lib/python3.9/site-packages/mrmustard/math/tensorflow.py:18
     15 """This module contains the Tensorflow implementation of the :class:`Math` interface."""
     17 import numpy as np
---> 18 import tensorflow as tf
     19 from thewalrus import hermite_multidimensional, grad_hermite_multidimensional
     21 from mrmustard.math.autocast import Autocast

File ~/miniforge3/envs/tf11/lib/python3.9/site-packages/tensorflow/__init__.py:37
     34 import sys as _sys
     35 import typing as _typing
---> 37 from tensorflow.python.tools import module_util as _module_util
     38 from tensorflow.python.util.lazy_loader import LazyLoader as _LazyLoader
     40 # Make sure code inside the TensorFlow codebase can use tf2.enabled() at import.

File ~/miniforge3/envs/tf11/lib/python3.9/site-packages/tensorflow/python/__init__.py:37
     29 # We aim to keep this file minimal and ideally remove completely.
     30 # If you are adding a new file with @tf_export decorators,
     31 # import it in modules_with_exports.py instead.
     32 
     33 # go/tf-wildcard-import
     34 # pylint: disable=wildcard-import,g-bad-import-order,g-import-not-at-top
     36 from tensorflow.python import pywrap_tensorflow as _pywrap_tensorflow
---> 37 from tensorflow.python.eager import context
     39 # pylint: enable=wildcard-import
     40 
     41 # Bring in subpackages.
     42 from tensorflow.python import data

File ~/miniforge3/envs/tf11/lib/python3.9/site-packages/tensorflow/python/eager/context.py:29
     26 import numpy as np
     27 import six
---> 29 from tensorflow.core.framework import function_pb2
     30 from tensorflow.core.protobuf import config_pb2
     31 from tensorflow.core.protobuf import coordination_config_pb2

File ~/miniforge3/envs/tf11/lib/python3.9/site-packages/tensorflow/core/framework/function_pb2.py:5
      1 # -*- coding: utf-8 -*-
      2 # Generated by the protocol buffer compiler.  DO NOT EDIT!
      3 # source: tensorflow/core/framework/function.proto
      4 """Generated protocol buffer code."""
----> 5 from google.protobuf.internal import builder as _builder
      6 from google.protobuf import descriptor as _descriptor
      7 from google.protobuf import descriptor_pool as _descriptor_pool

ImportError: cannot import name 'builder' from 'google.protobuf.internal' (/Users/xanadu/miniforge3/envs/tf11/lib/python3.9/site-packages/google/protobuf/internal/__init__.py)

Additional information

I start a new user account on my Mac M1 chip so that I build a new env for MM.
ziofil commented 1 year ago

hmm.... did you try to install tensorflow-macos?

sylviemonet commented 1 year ago

I tried this: conda create a new env with python=3.9. Install TensorFlow by pip install tensorflow-macos -> get tensorflow-macos version 2.11.0 Install MrMustard by pip install mrmustard.

`ERROR: Cannot install mrmustard==0.1.0, mrmustard==0.1.1, mrmustard==0.2.0 and mrmustard==0.3.0 because these package versions have conflicting dependencies.

The conflict is caused by: mrmustard 0.3.0 depends on tensorflow>=2.4.0 mrmustard 0.2.0 depends on tensorflow>=2.4.0 mrmustard 0.1.1 depends on tensorflow>=2.4.0 mrmustard 0.1.0 depends on tensorflow>=2.4.0

To fix this you could try to:

  1. loosen the range of package versions you've specified
  2. remove package versions to allow pip attempt to solve the dependency conflict

ERROR: ResolutionImpossible: for help visit https://pip.pypa.io/en/latest/topics/dependency-resolution/#dealing-with-dependency-conflicts`

sduquemesa commented 1 year ago

Was this resolved?

ziofil commented 6 months ago

closing, feel free to reopen if still relevant.