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

Don't decode a unicode string when using git version #2264

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

garrison
Copy link
Member

@garrison garrison commented Nov 22, 2024

Summary

In #907, the git sha1 was added to the version string on development builds. In #2158, encoding="utf-8" was added in _minimal_ext_cmd, which changed the output from a bytestring to a regular string. However, the original code path still expects a bytestring and calls .decode() on it. This fixes it in the way most obvious to me.

Details and comments

I am a bit puzzled that I am the first to notice this. My development builds of Aer otherwise result in the .decode() failing as soon as the package is imported. Even with this change, I am still unable to build and run qiskit-aer in an Ubuntu 24.04 container. The bug I get after this patch is

Traceback (most recent call last):
  File "/home/garrison/Qiskit/qiskit-aer/test.py", line 2, in <module>
    from qiskit_aer import AerSimulator
  File "/home/garrison/Qiskit/qiskit-aer/qiskit_aer/__init__.py", line 69, in <module>
    from qiskit_aer.aerprovider import AerProvider
  File "/home/garrison/Qiskit/qiskit-aer/qiskit_aer/aerprovider.py", line 20, in <module>
    from .backends.aer_simulator import AerSimulator
  File "/home/garrison/Qiskit/qiskit-aer/qiskit_aer/backends/__init__.py", line 17, in <module>
    from .aer_simulator import AerSimulator
  File "/home/garrison/Qiskit/qiskit-aer/qiskit_aer/backends/aer_simulator.py", line 24, in <module>
    from .aerbackend import AerBackend, AerError
  File "/home/garrison/Qiskit/qiskit-aer/qiskit_aer/backends/aerbackend.py", line 33, in <module>
    from ..noise.noise_model import NoiseModel, QuantumErrorLocation
  File "/home/garrison/Qiskit/qiskit-aer/qiskit_aer/noise/__init__.py", line 241, in <module>
    from .noise_model import NoiseModel
  File "/home/garrison/Qiskit/qiskit-aer/qiskit_aer/noise/noise_model.py", line 38, in <module>
    from ..backends.backend_utils import BASIS_GATES
  File "/home/garrison/Qiskit/qiskit-aer/qiskit_aer/backends/backend_utils.py", line 30, in <module>
    from .controller_wrappers import aer_initialize_libraries
ModuleNotFoundError: No module named 'qiskit_aer.backends.controller_wrappers'

EDIT: The above error resolved as soon as I changed directories away from the root directory of this repo before importing qiskit_aer.

In Qiskit#907, the git sha1 was added to the version string on
development builds.  In Qiskit#2158, `encoding="utf-8"` was added
in `_minimal_ext_cmd`, which changed the output from a
bytestring to a regular string.  However, the original
code path still expects a bytestring and calls `.decode()` on it.
This fixes it in the way most obvious to me.
@garrison
Copy link
Member Author

garrison commented Nov 23, 2024

I wonder if, instead, the sha1 should be saved in the version number when building the wheel. This code path only seems to be triggered in rare cases (e.g., when python is run using an editable Aer repo, or when run from the repo root -- as when I experienced the subsequent error above).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant