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

Import of fastcalc raises ImportError #541

Open
haroldmeerwaldt opened this issue Feb 18, 2025 · 2 comments
Open

Import of fastcalc raises ImportError #541

haroldmeerwaldt opened this issue Feb 18, 2025 · 2 comments
Labels
bug A bug or regression likely quick Things we expect to not take significant investigation or changes (remove label if issue spirals)
Milestone

Comments

@haroldmeerwaldt
Copy link

Describe the bug
When I import the pygsti.modelpacks.smq2Q_XYICNOT module, I get an ImportError.

To Reproduce
Steps to reproduce the behavior:

  1. make virtual environment with venv
  2. pip install pygsti
  3. in Python: from pygsti.modelpacks import smq2Q_XYICNOT
  4. See error:
C:\YYY\env\Lib\site-packages\pygsti\baseobjs\opcalc\__init__.py:31: UserWarning: 
An optimized Cython-based implementation of `pygsti.baseobjs.opcalc` is available as
an extension, but couldn't be imported. This might happen if the
extension has not been built. `pip install cython`, then reinstall
pyGSTi to build Cython extensions. Alternatively, setting the
environment variable `PYGSTI_NO_CYTHON_WARNING` will suppress this
message.

  _warnings.warn(warn_msg)
Traceback (most recent call last):
  File "C:\XXX\scratch_30.py", line 1, in <module>
    from pygsti.modelpacks import smq2Q_XYICNOT
  File "C:\YYY\env\Lib\site-packages\pygsti\__init__.py", line 12, in <module>
    from . import algorithms as alg
  File "C:\YYY\env\Lib\site-packages\pygsti\algorithms\__init__.py", line 17, in <module>
    from .contract import *
  File "C:\YYY\env\Lib\site-packages\pygsti\algorithms\contract.py", line 18, in <module>
    from pygsti import optimize as _opt
  File "C:\YYY\env\Lib\site-packages\pygsti\optimize\__init__.py", line 14, in <module>
    from .customlm import *
  File "C:\YYY\env\Lib\site-packages\pygsti\optimize\customlm.py", line 22, in <module>
    from pygsti.optimize.simplerlm import Optimizer, OptimizerResult
  File "C:\YYY\env\Lib\site-packages\pygsti\optimize\simplerlm.py", line 25, in <module>
    from pygsti.objectivefns.objectivefns import Chi2Function, TimeIndependentMDCObjectiveFunction
  File "C:\YYY\env\Lib\site-packages\pygsti\objectivefns\__init__.py", line 13, in <module>
    from .objectivefns import ObjectiveFunctionBuilder, \
  File "C:\YYY\env\Lib\site-packages\pygsti\objectivefns\objectivefns.py", line 28, in <module>
    from pygsti.models.model import OpModel as _OpModel
  File "C:\YYY\env\Lib\site-packages\pygsti\models\__init__.py", line 14, in <module>
    from .cloudnoisemodel import CloudNoiseModel
  File "C:\YYY\env\Lib\site-packages\pygsti\models\cloudnoisemodel.py", line 21, in <module>
    from pygsti.models.implicitmodel import ImplicitOpModel as _ImplicitOpModel, _init_spam_layers
  File "C:\YYY\env\Lib\site-packages\pygsti\models\implicitmodel.py", line 18, in <module>
    from pygsti.models import model as _mdl
  File "C:\YYY\env\Lib\site-packages\pygsti\models\model.py", line 23, in <module>
    from pygsti.models.layerrules import LayerRules as _LayerRules
  File "C:\YYY\env\Lib\site-packages\pygsti\models\layerrules.py", line 14, in <module>
    from pygsti.modelmembers import operations as _op
  File "C:\YYY\env\Lib\site-packages\pygsti\modelmembers\operations\__init__.py", line 17, in <module>
    from .composedop import ComposedOp
  File "C:\YYY\env\Lib\site-packages\pygsti\modelmembers\operations\composedop.py", line 19, in <module>
    from pygsti.modelmembers.operations.experrorgenop import ExpErrorgenOp as _ExpErrorgenOp
  File "C:\YYY\env\Lib\site-packages\pygsti\modelmembers\operations\experrorgenop.py", line 22, in <module>
    from pygsti.modelmembers.operations.lindbladerrorgen import LindbladParameterization as _LindbladParameterization
  File "C:\YYY\env\Lib\site-packages\pygsti\modelmembers\operations\lindbladerrorgen.py", line 27, in <module>
    from pygsti.modelmembers.operations.lindbladcoefficients import LindbladCoefficientBlock as _LindbladCoefficientBlock
  File "C:\YYY\env\Lib\site-packages\pygsti\modelmembers\operations\lindbladcoefficients.py", line 11, in <module>
    from pygsti.tools import fastcalc as _fc
ImportError: cannot import name 'fastcalc' from 'pygsti.tools' (C:\YYY\env\Lib\site-packages\pygsti\tools\__init__.py)

Expected behavior
I expected to be able to import the module without error.

Environment (please complete the following information):

  • pyGSTi version 0.9.13
  • python version 3.12.8
  • OS: Windows 11, 10.0.22631

Additional context

  • also occurs with cython installed before installing pygsti
@haroldmeerwaldt haroldmeerwaldt added the bug A bug or regression label Feb 18, 2025
@sserita
Copy link
Contributor

sserita commented Feb 18, 2025

Hi @haroldmeerwaldt, thanks for the report! This is probably a quick fix, looks like we are not guarding fastcalc properly here.

But in the meantime, can you try running python setup.py build_ext --inplace in your pyGSTi directory to force the Cython extensions to recompile and see if that fixes things?

@sserita sserita added the likely quick Things we expect to not take significant investigation or changes (remove label if issue spirals) label Feb 18, 2025
@sserita sserita added this to the 0.9.13.1 milestone Feb 18, 2025
@haroldmeerwaldt
Copy link
Author

haroldmeerwaldt commented Feb 20, 2025

Hi @sserita, thank you for looking at this.

I did an editable [complete] install of pyGSTi in the virtual environment after cloning the repository (pyGSTi 0.9.13.post3) and could import fastcalc successfully. There is a fastcalc.cp312-win_amd64.pyd file in pygsti.tools.

I am assuming you meant running python setup.py build_ext --inplace for building from source; in the end I didn't need to.

If I then pip install pygsti==0.9.13 for the pypi package again, I cannot import fastcalc. There is no fastcalc.cp312-win_amd64.pyd file in pygsti.tools.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A bug or regression likely quick Things we expect to not take significant investigation or changes (remove label if issue spirals)
Projects
None yet
Development

No branches or pull requests

2 participants