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 use pkg_resources.get_distribution(..).version #27

Closed
PureTryOut opened this issue May 6, 2020 · 22 comments
Closed

Don't use pkg_resources.get_distribution(..).version #27

PureTryOut opened this issue May 6, 2020 · 22 comments
Assignees
Labels
type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design.

Comments

@PureTryOut
Copy link

Environment details

  • OS type and version: Alpine Linux edge
  • Python version: 3.8
  • pip version: Irrelevant, pure system packages used
  • google-api-core version: 1.16.0

Issue

I'm trying to run the tests with the end goal being packaging this for Alpine Linux.
All the dependencies are installed and I'm running the tests with PYTHONPATH="$PWD/build/lib" pytest so I can run the tests without having the package installed yet.

I'm probably just doing something wrong, but every test file fails with the following:

_____________________________________________ ERROR collecting tests/unit/test_bidi.py ______________________________________________
tests/unit/test_bidi.py:24: in <module>
    from google.api_core import bidi
build/lib/google/api_core/__init__.py:23: in <module>
    __version__ = get_distribution("google-api-core").version
/usr/lib/python3.8/site-packages/pkg_resources/__init__.py:482: in get_distribution
    dist = get_provider(dist)
/usr/lib/python3.8/site-packages/pkg_resources/__init__.py:358: in get_provider
    return working_set.find(moduleOrReq) or require(str(moduleOrReq))[0]
/usr/lib/python3.8/site-packages/pkg_resources/__init__.py:901: in require
    needed = self.resolve(parse_requirements(requirements))
/usr/lib/python3.8/site-packages/pkg_resources/__init__.py:787: in resolve
    raise DistributionNotFound(req, requirers)
E   pkg_resources.DistributionNotFound: The 'google-api-core' distribution was not found and is required by the application
@busunkim96
Copy link
Contributor

Hi - could you provide details on how you're installing google-api-core?

@busunkim96 busunkim96 added the type: question Request for information or clarification. Not an issue. label May 6, 2020
@PureTryOut
Copy link
Author

I'm making an Alpine package with the intention to upstream it to their repositories.

The build script should speak for itself:

# Contributor: Bart Ribbers <bribbers@disroot.org>
# Maintainer: Bart Ribbers <bribbers@disroot.org>
pkgname=py3-google-api-core
pkgver=1.16.0
pkgrel=0
pkgdesc="Google Cloud Client Library for Python"
url="https://github.com/googleapis/google-cloud-python"
arch="noarch"
license="Apache-2.0"
depends="python3 py3-tz py3-requests py3-google-auth py3-protobuf py3-googleapis-common-protos"
makedepends="py3-setuptools py3-pytest py3-mock py3-grpcio"
source="https://pypi.python.org/packages/source/g/google-api-core/google-api-core-$pkgver.tar.gz"
builddir="$srcdir/google-api-core-$pkgver"

build() {
	python3 setup.py build
}

check() {
	PYTHONPATH="$PWD/build/lib" pytest
}

package() {
	python3 setup.py install --prefix=/usr --root="$pkgdir"
}

sha512sums="4897abf3ae59f84b6f0fa83c4704696649058028ed3d7439b2372cc9659634bd0f8eee2bc7f0a5fa7dce06f7e47581eeded659b6cb545a4e40d05de0e060d8f7  google-api-core-1.16.0.tar.gz"

I'm first building the package using setup.py build, after which I run pytest on the result.

@busunkim96
Copy link
Contributor

Ah I don't think pkg_resources.get_distribution works correctly when the library is built with python3 setup.py ....

In our tests we always install the library with pip, even for local installs.

pip install .

session.install("-e", ".")

Is there some way to use pip?

@PureTryOut
Copy link
Author

Not for installation sadly no, our packaging standards don't allow it.

@busunkim96
Copy link
Contributor

Unfortunately we have to be a bit particular about maintaining the version in one place because it needs to be reported in request headers. We currently maintain a single source of truth by placing the version in setup.py.

We could explore moving to another way of single-sourcing the version if more demand. https://packaging.python.org/guides/single-sourcing-package-version/

I'll keep this issue open as a feature request.

@busunkim96 busunkim96 added type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design. and removed type: question Request for information or clarification. Not an issue. labels May 6, 2020
@busunkim96 busunkim96 changed the title Test fails Don't use pkg_resources.get_distribution(..).version May 6, 2020
@PureTryOut
Copy link
Author

Unfortunately we have to be a bit particular about maintaining the version in one place because it needs to be reported in request headers.

That I understand. I'm sure more packages have this problem, I wonder how others do it.

@pganssle
Copy link

pganssle commented Aug 19, 2020

FWIW, both pkg_resources and directly invoking setup.py install are semi-deprecated and are mostly unsupported.

The replacement for pkg_resources.distribution(...).version is importlib.metadata.version(...) (backported to pre-3.7 Python as importlib_metadata), though I doubt that will solve anyone's problem if the installation metadata is simply not present.

More context about the setup.py install deprecation here, but the short answer is that you should always prefer pip install to setup.py install, even in a package manager. A few people (particularly those involved in Arch linux packaging) have been working on minimal PEP 517 build frontend to build wheels and a minimal wheel installer, so possibly early adoption of those technologies will work better for you, @PureTryOut.

@crwilcox
Copy link
Contributor

crwilcox commented Oct 1, 2020

@PureTryOut did you happen to figure a way around this? If not we may be able to move the version out of setup.py as @busunkim96 previously indicated.

@crwilcox
Copy link
Contributor

crwilcox commented Oct 1, 2020

Also, this is a workaround another project seems to be using. https://github.com/oppia/oppia/pull/10824/files#diff-b6d8dd401ae816cad17bf9926ce3385dR78

@crwilcox
Copy link
Contributor

crwilcox commented Oct 1, 2020

Unfortunately I am not reproducing this issue on macos, in a virtualenv, using setup.py build I am passed getting a distribution version when loading the package.

However, as noted above, there is friction using the libraries in GAE. So it is possible we could improve both use cases with the same fix, likely increasing the ability for the version/pkg to be discovered.

❯ python -m venv venv; source venv/bin/activate
❯ python setup.py build
❯ python
Python 3.8.5 (default, Sep 21 2020, 13:30:58)
[Clang 11.0.3 (clang-1103.0.32.62)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.path.append("{MY WORKING DIRECTORY}/build/lib")
>>> from google import api_core
>>> import pkg_resources
>>> pkg_resources.get_distribution("google-api-core").version
'1.22.2'

@merwok
Copy link

merwok commented Oct 1, 2020

Could you print more info from the object returned by get_distribution?
I don’t think it is finding info in $PWD/build/lib, because the build command does not create egg-info or dist-info directory. I suspect your call is picking up a previous install of google-api-core.

For the original problem: a nice way to handle this is to invert the process, so have the version in the code and use a build tool that knows how to find the version number in the source (flit, setuptools can do that for example). Then you don’t need to depend on a packaging lib at runtime.

@crwilcox
Copy link
Contributor

crwilcox commented Oct 1, 2020

I think it may have been picking up the dev copy (not the one in build). I can repro if I move to another directory after build :)

❯ python -m venv venv; source venv/bin/activate
❯ pip freeze
❯ python setup.py build
❯ export PYTHONPATH="${PWD}/build/lib"
❯ cd build


❯ python
Python 3.8.5 (default, Sep 21 2020, 13:30:58)
[Clang 11.0.3 (clang-1103.0.32.62)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.path.append("/Users/crwilcox/workspace/python-api-core/build/lib")

>>> import pkg_resources
>>> pkg_resources.get_distribution("google-api-core")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/crwilcox/workspace/python-api-core/venv/lib/python3.8/site-packages/pkg_resources/__init__.py", line 482, in get_distribution
    dist = get_provider(dist)
  File "/Users/crwilcox/workspace/python-api-core/venv/lib/python3.8/site-packages/pkg_resources/__init__.py", line 358, in get_provider
    return working_set.find(moduleOrReq) or require(str(moduleOrReq))[0]
  File "/Users/crwilcox/workspace/python-api-core/venv/lib/python3.8/site-packages/pkg_resources/__init__.py", line 901, in require
    needed = self.resolve(parse_requirements(requirements))
  File "/Users/crwilcox/workspace/python-api-core/venv/lib/python3.8/site-packages/pkg_resources/__init__.py", line 787, in resolve
    raise DistributionNotFound(req, requirers)
pkg_resources.DistributionNotFound: The 'google-api-core' distribution was not found and is required by the application

However, worth noting, I also can't import the package at all, I can get the error.

❯ python
Python 3.8.5 (default, Sep 21 2020, 13:30:58)
[Clang 11.0.3 (clang-1103.0.32.62)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.path.append("/Users/crwilcox/workspace/python-api-core/build/lib")
>>> from google import api_core
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: cannot import name 'api_core' from 'google' (unknown location)

@merwok
Copy link

merwok commented Oct 1, 2020

Is the package built (copied) into ~/workspace/python-api-core/build/lib?

@crwilcox
Copy link
Contributor

crwilcox commented Oct 1, 2020

Yes.

❯ pwd
/Users/crwilcox/workspace/python-api-core/build/lib/google
❯ ls
__init__.py __pycache__ api_core

@crwilcox
Copy link
Contributor

crwilcox commented Oct 1, 2020

I am looking into moving us to not using pkg_resources. Though it is part of namespacing (we do have a fallback to pkgutil)

Also, in order to change this we need to modify our release tooling as it assumes version is specified in setup.py.

@crwilcox
Copy link
Contributor

crwilcox commented Oct 1, 2020

Not meaning to cross thread the issue, but we do seem to have a repro in AppEngine Standard for Python 2.7

Vendoring google-cloud-datastore into the basic quickstart (hello world) the runtime will fail similarly.

Traceback (most recent call last):
  File "/base/alloc/tmpfs/dynamic_runtimes/python27g/4a2384f6b69cef45/python27/python27_lib/versions/1/google/appengine/runtime/wsgi.py", line 238, in Handle
    handler = _config_handle.add_wsgi_middleware(self._LoadHandler())
  File "/base/alloc/tmpfs/dynamic_runtimes/python27g/4a2384f6b69cef45/python27/python27_lib/versions/1/google/appengine/runtime/wsgi.py", line 309, in _LoadHandler
    handler, path, err = LoadObject(self._handler)
  File "/base/alloc/tmpfs/dynamic_runtimes/python27g/4a2384f6b69cef45/python27/python27_lib/versions/1/google/appengine/runtime/wsgi.py", line 83, in LoadObject
    obj = __import__(path[0])
  File "/base/data/home/apps/s~crwilcox-test/20201001t151852.429923747926530875/main.py", line 17, in <module>
    from google.cloud import datastore
  File "/base/data/home/apps/s~crwilcox-test/20201001t151852.429923747926530875/lib/google/cloud/datastore/__init__.py", line 62, in <module>
    from google.cloud.datastore.batch import Batch
  File "/base/data/home/apps/s~crwilcox-test/20201001t151852.429923747926530875/lib/google/cloud/datastore/batch.py", line 24, in <module>
    from google.cloud.datastore import helpers
  File "/base/data/home/apps/s~crwilcox-test/20201001t151852.429923747926530875/lib/google/cloud/datastore/helpers.py", line 29, in <module>
    from google.cloud.datastore_v1.proto import datastore_pb2
  File "/base/data/home/apps/s~crwilcox-test/20201001t151852.429923747926530875/lib/google/cloud/datastore_v1/__init__.py", line 17, in <module>
    from google.cloud.datastore_v1 import types
  File "/base/data/home/apps/s~crwilcox-test/20201001t151852.429923747926530875/lib/google/cloud/datastore_v1/types.py", line 25, in <module>
    from google.api_core.protobuf_helpers import get_messages
  File "/base/data/home/apps/s~crwilcox-test/20201001t151852.429923747926530875/lib/google/api_core/__init__.py", line 23, in <module>
    __version__ = get_distribution("google-api-core").version
  File "/base/alloc/tmpfs/dynamic_runtimes/python27g/4a2384f6b69cef45/python27/python27_lib/versions/third_party/setuptools-36.6.0/pkg_resources/__init__.py", line 562, in get_distribution
    dist = get_provider(dist)
  File "/base/alloc/tmpfs/dynamic_runtimes/python27g/4a2384f6b69cef45/python27/python27_lib/versions/third_party/setuptools-36.6.0/pkg_resources/__init__.py", line 436, in get_provider
    return working_set.find(moduleOrReq) or require(str(moduleOrReq))[0]
  File "/base/alloc/tmpfs/dynamic_runtimes/python27g/4a2384f6b69cef45/python27/python27_lib/versions/third_party/setuptools-36.6.0/pkg_resources/__init__.py", line 981, in require
    needed = self.resolve(parse_requirements(requirements))
  File "/base/alloc/tmpfs/dynamic_runtimes/python27g/4a2384f6b69cef45/python27/python27_lib/versions/third_party/setuptools-36.6.0/pkg_resources/__init__.py", line 867, in resolve
    raise DistributionNotFound(req, requirers)
DistributionNotFound: The 'google-api-core' distribution was not found and is required by the application"

@busunkim96
Copy link
Contributor

@crwilcox There's a note in the old google-cloud-python repo that says says the google-cloud-* libs will not work in Py 2 App Engine. https://github.com/googleapis/google-cloud-python#google-cloud-python-client

Heads up! These libraries are supported on App Engine standard's Python 3 runtime but are not supported on App Engine's Python 2 runtime.

Is that use case something we're looking to support?

@crwilcox
Copy link
Contributor

crwilcox commented Oct 1, 2020

Support is a strong word. That said, seeing that this dependency is causing issues in both areas makes me feel we may want to see if we can avoid it. The interesting thing is that the issue alpine building is the same.

All that in mind, even if I fix this (right now I mocked it out in vendored versions by just saying the version was a static string, we have issues importing rsa in GAE.

"
Traceback (most recent call last):
  File "/base/alloc/tmpfs/dynamic_runtimes/python27g/4a2384f6b69cef45/python27/python27_lib/versions/1/google/appengine/runtime/wsgi.py", line 238, in Handle
    handler = _config_handle.add_wsgi_middleware(self._LoadHandler())
  File "/base/alloc/tmpfs/dynamic_runtimes/python27g/4a2384f6b69cef45/python27/python27_lib/versions/1/google/appengine/runtime/wsgi.py", line 309, in _LoadHandler
    handler, path, err = LoadObject(self._handler)
  File "/base/alloc/tmpfs/dynamic_runtimes/python27g/4a2384f6b69cef45/python27/python27_lib/versions/1/google/appengine/runtime/wsgi.py", line 83, in LoadObject
    obj = __import__(path[0])
  File "/base/data/home/apps/s~crwilcox-test/20201001t152952.429923926239081090/main.py", line 17, in <module>
    from google.cloud import datastore
  File "/base/data/home/apps/s~crwilcox-test/20201001t152952.429923926239081090/lib/google/cloud/datastore/__init__.py", line 62, in <module>
    from google.cloud.datastore.batch import Batch
  File "/base/data/home/apps/s~crwilcox-test/20201001t152952.429923926239081090/lib/google/cloud/datastore/batch.py", line 24, in <module>
    from google.cloud.datastore import helpers
  File "/base/data/home/apps/s~crwilcox-test/20201001t152952.429923926239081090/lib/google/cloud/datastore/helpers.py", line 29, in <module>
    from google.cloud.datastore_v1.proto import datastore_pb2
  File "/base/data/home/apps/s~crwilcox-test/20201001t152952.429923926239081090/lib/google/cloud/datastore_v1/__init__.py", line 18, in <module>
    from google.cloud.datastore_v1.gapic import datastore_client
  File "/base/data/home/apps/s~crwilcox-test/20201001t152952.429923926239081090/lib/google/cloud/datastore_v1/gapic/datastore_client.py", line 22, in <module>
    from google.oauth2 import service_account
  File "/base/data/home/apps/s~crwilcox-test/20201001t152952.429923926239081090/lib/google/oauth2/service_account.py", line 77, in <module>
    from google.auth import _service_account_info
  File "/base/data/home/apps/s~crwilcox-test/20201001t152952.429923926239081090/lib/google/auth/_service_account_info.py", line 22, in <module>
    from google.auth import crypt
  File "/base/data/home/apps/s~crwilcox-test/20201001t152952.429923926239081090/lib/google/auth/crypt/__init__.py", line 43, in <module>
    from google.auth.crypt import rsa
  File "/base/data/home/apps/s~crwilcox-test/20201001t152952.429923926239081090/lib/google/auth/crypt/rsa.py", line 27, in <module>
    from google.auth.crypt import _python_rsa
  File "/base/data/home/apps/s~crwilcox-test/20201001t152952.429923926239081090/lib/google/auth/crypt/_python_rsa.py", line 28, in <module>
    import rsa
  File "/base/data/home/apps/s~crwilcox-test/20201001t152952.429923926239081090/lib/rsa/__init__.py", line 1
SyntaxError: Non-ASCII character '\xc3' in file /base/data/home/apps/s~crwilcox-test/20201001t152952.429923926239081090/lib/rsa/__init__.py on line 1, but no encoding declared; see http://python.org/dev/peps/pep-0263/ for details"

@merwok
Copy link

merwok commented Oct 2, 2020

Note that with Python 3, you can have namespace packages without needing pkgutil.

@crwilcox
Copy link
Contributor

crwilcox commented Oct 2, 2020

Unfortunately this package is last in line to drop Python 2 support as most of our packages depend on it. Moreover, we are seeing this issue, at least on GAE, on Python 2 specifically. I believe due to the way packages are vendored.

@crwilcox
Copy link
Contributor

crwilcox commented Oct 5, 2020

@PureTryOut @merwok I released https://pypi.org/project/google-api-core/1.22.4/ which should no longer require get_distribution. Please let me know if this works for your use now :)

Unfortunately for many of the other libraries the use is a little more complicated as its use is in both manually authored and generated code. If this approach does work and other libraries (google-cloud-datastore for instance?) would need further work and likely some fixing of generated surfaces to address this there.

@tseaver
Copy link
Contributor

tseaver commented Oct 6, 2020

Via #80.

@tseaver tseaver closed this as completed Oct 6, 2020
gcf-merge-on-green bot pushed a commit to googleapis/google-auth-library-python that referenced this issue Mar 16, 2021
Move the version from `setup.py` to `google/auth/version.py`.  Same as googleapis/python-api-core#80.  (see googleapis/python-api-core#27 for motivation). This is option 3 in https://packaging.python.org/guides/single-sourcing-package-version/.

This unblocks a version check I'd like to add in googleapis/python-api-core#134.

Usage:

```py
>>> import google.auth
>>> google.auth.__version__
'1.25.0'
```
ddabble added a commit to ddabble/django-simple-history that referenced this issue Jul 4, 2023
(It seems like after the last commit added `python = 3.12` to `tox.ini`,
that version was actually being used, which made the tests fail against
Python 3.12-dev.)

As of Python 3.12, the `pkg_resources` package is no longer provided
(see https://docs.python.org/3.13/whatsnew/3.12.html#removed).
The package has been deprecated in favor of `importlib.metadata
(see the "Attention" notice at the top of
https://setuptools.pypa.io/en/latest/pkg_resources.html),
and the replacement for `pkg_resources.get_distribution()` is
`importlib.metadata.version()` (according to
googleapis/python-api-core#27 (comment)).
See also https://docs.python.org/3/library/importlib.metadata.html#distribution-versions.
ddabble added a commit to ddabble/django-simple-history that referenced this issue Jul 4, 2023
(It seems like after the last commit added `python = 3.12` to `tox.ini`,
that version was actually being used, which made the tests fail against
Python 3.12-dev.)

As of Python 3.12, the `pkg_resources` package is no longer provided
(see https://docs.python.org/3.13/whatsnew/3.12.html#removed).
The package has been deprecated in favor of `importlib.metadata
(see the "Attention" notice at the top of
https://setuptools.pypa.io/en/latest/pkg_resources.html),
and the replacement for `pkg_resources.get_distribution()` is
`importlib.metadata.version()` (according to
googleapis/python-api-core#27 (comment)).
See also https://docs.python.org/3/library/importlib.metadata.html#distribution-versions.
DouglasHeriot added a commit to DouglasHeriot/opentelemetry-operations-python that referenced this issue Jul 5, 2023
Similar to discussion at googleapis/python-api-core#27 I am using opentelemetry in an environment where modules are vendored without pip. So, pkg_resources can not be used to search for a module at runtime to get its version.
DouglasHeriot added a commit to DouglasHeriot/opentelemetry-operations-python that referenced this issue Aug 3, 2023
Similar to discussion at googleapis/python-api-core#27 I am using opentelemetry in an environment where modules are vendored without pip. So, pkg_resources can not be used to search for a module at runtime to get its version.
DouglasHeriot added a commit to DouglasHeriot/opentelemetry-operations-python that referenced this issue Aug 3, 2023
Similar to discussion at googleapis/python-api-core#27 I am using opentelemetry in an environment where modules are vendored without pip. So, pkg_resources can not be used to search for a module at runtime to get its version.
DouglasHeriot added a commit to DouglasHeriot/opentelemetry-operations-python that referenced this issue Aug 3, 2023
Similar to discussion at googleapis/python-api-core#27 I am using opentelemetry in an environment where modules are vendored without pip. So, pkg_resources can not be used to search for a module at runtime to get its version.
DouglasHeriot added a commit to DouglasHeriot/opentelemetry-operations-python that referenced this issue Aug 3, 2023
Similar to discussion at googleapis/python-api-core#27 I am using opentelemetry in an environment where modules are vendored without pip. So, pkg_resources can not be used to search for a module at runtime to get its version.
DouglasHeriot added a commit to DouglasHeriot/opentelemetry-operations-python that referenced this issue Aug 3, 2023
Similar to discussion at googleapis/python-api-core#27 I am using opentelemetry in an environment where modules are vendored without pip. So, pkg_resources can not be used to search for a module at runtime to get its version.
aabmass added a commit to GoogleCloudPlatform/opentelemetry-operations-python that referenced this issue Aug 3, 2023
* Pin upstream version of opentelemetry when running tests

Fix in #254 didn't apply to tox environments that run `pip install .`

`test_detects_gce` was failing with opentelemetry-sdk version 1.19.0
instead of 1.18.0

* Don't use `pkg_resources.get_distribution(..).version`

Similar to discussion at googleapis/python-api-core#27 I am using opentelemetry in an environment where modules are vendored without pip. So, pkg_resources can not be used to search for a module at runtime to get its version.

---------

Co-authored-by: Aaron Abbott <aaronabbott@google.com>
garrison added a commit to garrison/qiskit-ibm-runtime that referenced this issue Feb 29, 2024
PR Qiskit#1347 added `setuptools` to `requirements-dev.txt` in an effort
to make `qiskit-ibm-runtime` work with Python 3.12.  However,
`qiskit_ibm_runtime/api/session.py` actually imports `pkg_resources`,
which is provided by setuptools, so really setuptools should have been
added to [`REQUIREMENTS`](https://github.com/Qiskit/qiskit-ibm-runtime/blob/e152d122782959a04ebf2330f776d4c4e309ad14/setup.py#L21)
in `setup.py` so that it is installed automatically for any downstream
users of Qiskit Runtime, too.

Better yet, however, is to drop this explicit dependency on setuptools,
since [`pkg_resources` is deprecated](https://setuptools.pypa.io/en/latest/pkg_resources.html)
in favor of `importlib`.  Hence, this PR migrates from `pkg_resources`
to `importlib.metadata` (there are a few more words about this
[here](googleapis/python-api-core#27 (comment))).

My investigation into this was prompted by us trying to add
Python 3.12 support to the circuit-knitting-toolbox
(Qiskit-Extensions/circuit-knitting-toolbox#429),
and seeing CI errors prompted by `qiskit-ibm-runtime`'s importing
of `pkg_resources`.
kt474 added a commit to Qiskit/qiskit-ibm-runtime that referenced this issue Feb 29, 2024
PR #1347 added `setuptools` to `requirements-dev.txt` in an effort
to make `qiskit-ibm-runtime` work with Python 3.12.  However,
`qiskit_ibm_runtime/api/session.py` actually imports `pkg_resources`,
which is provided by setuptools, so really setuptools should have been
added to [`REQUIREMENTS`](https://github.com/Qiskit/qiskit-ibm-runtime/blob/e152d122782959a04ebf2330f776d4c4e309ad14/setup.py#L21)
in `setup.py` so that it is installed automatically for any downstream
users of Qiskit Runtime, too.

Better yet, however, is to drop this explicit dependency on setuptools,
since [`pkg_resources` is deprecated](https://setuptools.pypa.io/en/latest/pkg_resources.html)
in favor of `importlib`.  Hence, this PR migrates from `pkg_resources`
to `importlib.metadata` (there are a few more words about this
[here](googleapis/python-api-core#27 (comment))).

My investigation into this was prompted by us trying to add
Python 3.12 support to the circuit-knitting-toolbox
(Qiskit-Extensions/circuit-knitting-toolbox#429),
and seeing CI errors prompted by `qiskit-ibm-runtime`'s importing
of `pkg_resources`.

Co-authored-by: Kevin Tian <kevin.tian@ibm.com>
jyu00 added a commit to Qiskit/qiskit-ibm-runtime that referenced this issue Mar 4, 2024
* Migrate fake backends from `qiskit.providers.fake_provider` (#1140)

* Migrate fake provider

* fix lint

* Only migrate backends and fake_provider file to minimize duplication

* Add reno

* Update snippet to use runtime service

---------

Co-authored-by: Kevin Tian <kevin.tian@ibm.com>

* Fix BYOB job results bytes typing issue  (#1220)

* try/except raw result truncation

* catch typeError

* revert try/except, use response.text

* update unit test

* Fix fake backends integration test (#1225)

* Clean up/fix integration test

* Update test case

* Fix black

* Added deprecation warning when using qiskitrc file (#1219)

* Added deprecation warning when using qiskitrc file

* Fixed bug whereby deprecation warnings cause failure for all 'qiskit*' modules. Changed warning to deprecation warning.

* Release note

* Small grammer fix

* black

---------

Co-authored-by: Kevin Tian <kevin.tian@ibm.com>

* Update session.from_id() (#1163)

* update session.from_id()

* add deprecation warning

* add reno

* Prepare release 0.15.0 (#1226)

* Update main branch 0.16.0 (#1227)

* Revert `Session.from_id 0.15.0` changes   (#1229)

* Revert "Update session.from_id() (#1163)"

This reverts commit 8fa0472.

* add reno

* Prepare release 0.15.1 (#1230)

* Update main branch to 0.16.0 again (#1232)

* Remove all code related to custom programs (#1192)

* initial removal

* cleanup more files

* move result_decoder

* fix lint

* update unit tests

* update integration tests

* more docs changes

* release note

* fix path

---------

Co-authored-by: Jessie Yu <jessieyu@us.ibm.com>

* Make sessions thread safe (#1196)

* Make sessions thread safe.

The lock prevents other threads from sending new jobs to the service
only if the session hasnot been setup yet. I.e.: when sending the
first "session starter job", or root job. After this happens, the code
is left unlocked to allow threads to access the service concurrently.

Error handling is needed to ensure the lock is always released.

* Allow multiple sessions to execute simultaneously

* Make session test more deterministic

---------

Co-authored-by: Kevin Tian <kevin.tian@ibm.com>
Co-authored-by: Jessie Yu <jessieyu@us.ibm.com>

* Instance & channel_strategy validation  (#1233)

* compare cloud instance with channel strategy

* fix unit tests

* error wording

---------

Co-authored-by: Jessie Yu <jessieyu@us.ibm.com>

* Prepare release 0.16.1 (#1239)

* release notes

* fix release

* update to 0.17 (#1240)

* Stop referring to qiskit.org in API docs (#1242)

* Add job.properties() method (#1252)

* Add job.properties() method

* add reno

* Remove non-API docs and translations (#1256)

This is the same as Qiskit/qiskit#11352. Now that qiskit.org/ecosystem/ibm-runtime redirects to docs.quantum.ibm.com, we can simplify the docs. 

See the PR description in Qiskit/qiskit#11352 for details on the motivation for each change. The only difference from Qiskit is that we still keep the tutorials around because learning.quantum.ibm.com uses them.

I used a script with `ripgrep` to confirm that none of the images were in use.

* Raise error if backend retrieved not in current instance  (#1249)

* Error if backend not in instance

* add reno

* update reno

* docs build

* fix docs again

* docs formatting :/

* add integration test

* Update test/integration/test_backend.py

Co-authored-by: merav-aharoni <merav@il.ibm.com>

* Update test/integration/test_backend.py

Co-authored-by: merav-aharoni <merav@il.ibm.com>

---------

Co-authored-by: merav-aharoni <merav@il.ibm.com>

* Fix backend_converter `faulty_qubit` name error (#1257)

* fix backend_converter

* add reno

* Update Tutorial section names (#1241)

* The transpilation tutorial has been updated to use the new runtime transpilation passes, and Batch

* Fix style checker

* Updated names

* Updated section names for transpiled tutorial

* Updated grover

* Fixed consistency

* Final updates

---------

Co-authored-by: Kevin Tian <kevin.tian@ibm.com>

* make test_backend_wrong_instance IQP only (#1258)

* Add pointer to qiskit/documentation issues (#1260)

* add pointer to qiskit/documentation issues

* Update .github/ISSUE_TEMPLATE/config.yml

Co-authored-by: Eric Arellano <14852634+Eric-Arellano@users.noreply.github.com>

* Update CONTRIBUTING.md

Co-authored-by: Eric Arellano <14852634+Eric-Arellano@users.noreply.github.com>

---------

Co-authored-by: Kevin Tian <kt474@cornell.edu>
Co-authored-by: Eric Arellano <14852634+Eric-Arellano@users.noreply.github.com>

* Update `test_backend_wrong_instance` (#1259)

* wip debug wrong instance test

* enable integration test

* use backend names instead of obj

* Don't block for the first job in a session (#1170)

* don't block if backend not selected

* add reno

* add test

* Add `activated_at` field to session.details() (#1266)

* add activated_at to session.details()

* add reno

* Revert "Don't block for the first job in a session (#1170)" (#1267)

* Revert "Don't block for the first job in a session (#1170)"

This reverts commit f2e24e4.

* keep test

* Prepare release 0.17.0 (#1268)

* update main branch 0.17.1 (#1269)

* Remove test_session_no_backend (#1272)

* Added RuntimeJob.queue_info() method (#1210)

* Added support for RuntimeJob.queueinfo

* Moved methods for consistency with main

* Changed backend_status to job.status

* lint

* update test

---------

Co-authored-by: Kevin Tian <kevin.tian@ibm.com>

* Replace programs with primitives in api docs  (#1281)

* programs -> primitives

* address comment

* Deprecate service.runtime (#1278)

* Deprecate service.runtime

* add reno

* Removed support for qiskitrc file (#1121)

* Removed support for qiskitrc file

* lint

---------

Co-authored-by: Kevin Tian <kevin.tian@ibm.com>

* Add max_time parameter to IBMBackend.open_session() (#1274)

* Added max_time to IBMBackend.open_session.

* Release note

* Changed format of test

* Migrate fake backend base classes (#1270)

Co-authored-by: Kevin Tian <kevin.tian@ibm.com>

* Add Q-CTRL integration tests  (#1173)

* add initial qctrl test file

* add test & decorator

* add tests from Mirko

* Added assertness for preciseness of results

* remove print statements

* move into e2e folder

* setup ci

* Update q-ctrl-tests.yml

* add account test

* add more account tests

* Update test/qctrl/test_qctrl.py

Co-authored-by: Rathish Cholarajan <rathishc24@gmail.com>

* address comments

* update date to 2023

* Update test/qctrl/test_qctrl.py

Co-authored-by: Blake Johnson <blakejohnson04@gmail.com>

* Update test/qctrl/test_qctrl.py

Co-authored-by: Blake Johnson <blakejohnson04@gmail.com>

---------

Co-authored-by: merav-aharoni <merav@il.ibm.com>
Co-authored-by: Rathish Cholarajan <rathishc24@gmail.com>
Co-authored-by: Blake Johnson <blakejohnson04@gmail.com>

* update grover tutorial equation (#1293)

* Add dynamic circuits backend filter (#1291)

* Add dynamic circuits backend filter

* add reno

* switch docs from mathjax to katex (#1301)

Updates the sphinx documentation build to use KaTeX instead of MathJax because the final docs build uses KaTeX. The same change was made in Qiskit in Qiskit/qiskit#11435.

* Remove qiskit.org links (#1302)

* Update session_id docstring (#1304)

* Update provider and qiskit versions (#1305)

* Exclude params on job retrieval by default (#1308)

* exclude params on job retrieval by default

* add reno

* add test

* Reactive the viewcode extension for docs (#1312)

We got source links working in API docs on docs.quantum.ibm.com! See Qiskit/documentation#620. To do this, we need to active `sphinx.ext.viewcode`.

Note that we still plan to improve this implementation in the future to have more precise links by using `sphinx.ext.linkcode`, tracked by Qiskit/documentation#517. This PR is to unblock the first iteration of this source links mechanism.

* Add config files to manifest (#1319)

* Fix pip environment resolution (#1329)

Calling `pip install` multiple times can (deeply unfortunately) allow an
environment to become out-of-sync; `pip` doesn't "remember" the
constraints of previous installation commands.

One of the largest effects here is that doing `pip install -e .`
_followed_ by `pip install git+<qiskit>@main` installs `qiskit-terra`
from the initial installation (via `qiskit==0.45.2`), then installs
`qiskit==1.0.0.dev0` from Git, which is an incompatible environment.
Doing the whole environment resolution in a single `pip install` command
fixes this, as the `qiskit` dependency is correctly resolved to be
_only_ the `1.0.0.dev0` version.

Co-authored-by: Kevin Tian <kevin.tian@ibm.com>

* Use IBM-Provider-vendored pub/sub mechanism (#1328)

This is being removed from Qiskit 1.0, and the IBM Provider is (until
deprecated) taking over brokering the IBM-Runtime-internal events.

Co-authored-by: Kevin Tian <kevin.tian@ibm.com>

* Add transpiler tests (#1323)

* Add transpiler tests

* remove qiskittestcase

* Prepare release 0.18.0 (#1335)

* Update main branch 0.18.1 (#1336)

* Turn off qiskit.org docs deploy (#1340)

* Remove `qiskit.test` (#1292)

* replace qiskit.test.ReferenceCircuits

* replace BaseQiskitTest

* Update qiskit_ibm_runtime/qiskit_runtime_service.py

Co-authored-by: Jessie Yu <jessieyu@us.ibm.com>

* Update qiskit_ibm_runtime/sampler.py

Co-authored-by: Jessie Yu <jessieyu@us.ibm.com>

* Update qiskit_ibm_runtime/session.py

Co-authored-by: Jessie Yu <jessieyu@us.ibm.com>

* Update test/utils.py

Co-authored-by: Jessie Yu <jessieyu@us.ibm.com>

---------

Co-authored-by: Jessie Yu <jessieyu@us.ibm.com>

* Add missing API Refs to docs (#1343)

### Summary
The documentation from the `transpile` and `fake_provider` modules does not appear in the rendered docs in qiskit.org/documentation or docs.quantum-computing.ibm.com.


### Details and comments

Fixes [Qiskit Docs Issue #238](Qiskit/documentation#238)

Replaces PR #1330.

Transpiler Doc files added:

 - qiskit_ibm_runtime.transpiler.passes.html
- qiskit_ibm_provider.transpiler.passes.basis.html
- qiskit_ibm_provider.transpiler.passes.scheduling.ALAPScheduleAnalysis.html
- qiskit_ibm_provider.transpiler.passes.scheduling.ASAPScheduleAnalysis.html
- qiskit_ibm_provider.transpiler.passes.scheduling.BlockBasePadder.html
- qiskit_ibm_provider.transpiler.passes.scheduling.DynamicCircuitInstructionDurations.html
- qiskit_ibm_provider.transpiler.passes.scheduling.html
- qiskit_ibm_provider.transpiler.passes.scheduling.PadDelay.html
- qiskit_ibm_provider.transpiler.passes.scheduling.PadDynamicalDecoupling.html

<details>
<summary> Fake Provider Docs added: </summary>

- qiskit_ibm_runtime.fake_provider.FakeAlmaden.html
- qiskit_ibm_runtime.fake_provider.FakeAlmadenV2.html
- qiskit_ibm_runtime.fake_provider.FakeArmonk.html
- qiskit_ibm_runtime.fake_provider.FakeArmonkV2.html
- qiskit_ibm_runtime.fake_provider.FakeAthens.html
- qiskit_ibm_runtime.fake_provider.FakeAthensV2.html
- qiskit_ibm_runtime.fake_provider.FakeAuckland.html
- qiskit_ibm_runtime.fake_provider.FakeBelem.html
- qiskit_ibm_runtime.fake_provider.FakeBelemV2.html
- qiskit_ibm_runtime.fake_provider.FakeBoeblingen.html
- qiskit_ibm_runtime.fake_provider.FakeBoeblingenV2.html
- qiskit_ibm_runtime.fake_provider.FakeBogota.html
- qiskit_ibm_runtime.fake_provider.FakeBogotaV2.html
- qiskit_ibm_runtime.fake_provider.FakeBrooklyn.html
- qiskit_ibm_runtime.fake_provider.FakeBrooklynV2.html
- qiskit_ibm_runtime.fake_provider.FakeBurlington.html
- qiskit_ibm_runtime.fake_provider.FakeBurlingtonV2.html
- qiskit_ibm_runtime.fake_provider.FakeCairo.html
- qiskit_ibm_runtime.fake_provider.FakeCairoV2.html
- qiskit_ibm_runtime.fake_provider.FakeCambridge.html
- qiskit_ibm_runtime.fake_provider.FakeCambridgeV2.html
- qiskit_ibm_runtime.fake_provider.FakeCasablanca.html
- qiskit_ibm_runtime.fake_provider.FakeCasablancaV2.html
- qiskit_ibm_runtime.fake_provider.FakeEssex.html
- qiskit_ibm_runtime.fake_provider.FakeEssexV2.html
- qiskit_ibm_runtime.fake_provider.FakeGeneva.html
- qiskit_ibm_runtime.fake_provider.FakeGuadalupe.html
- qiskit_ibm_runtime.fake_provider.FakeGuadalupeV2.html
- qiskit_ibm_runtime.fake_provider.FakeHanoi.html
- qiskit_ibm_runtime.fake_provider.FakeHanoiV2.html
- qiskit_ibm_runtime.fake_provider.FakeJakarta.html
- qiskit_ibm_runtime.fake_provider.FakeJakartaV2.html
- qiskit_ibm_runtime.fake_provider.FakeJohannesburg.html
- qiskit_ibm_runtime.fake_provider.FakeJohannesburgV2.html
- qiskit_ibm_runtime.fake_provider.FakeKolkata.html
- qiskit_ibm_runtime.fake_provider.FakeKolkataV2.html
- qiskit_ibm_runtime.fake_provider.FakeLagos.html
- qiskit_ibm_runtime.fake_provider.FakeLagosV2.html
- qiskit_ibm_runtime.fake_provider.FakeLima.html
- qiskit_ibm_runtime.fake_provider.FakeLimaV2.html
- qiskit_ibm_runtime.fake_provider.FakeLondon.html
- qiskit_ibm_runtime.fake_provider.FakeLondonV2.html
- qiskit_ibm_runtime.fake_provider.FakeManhattan.html
- qiskit_ibm_runtime.fake_provider.FakeManhattanV2.html
- qiskit_ibm_runtime.fake_provider.FakeManila.html
- qiskit_ibm_runtime.fake_provider.FakeManilaV2.html
- qiskit_ibm_runtime.fake_provider.FakeMelbourne.html
- qiskit_ibm_runtime.fake_provider.FakeMelbourneV2.html
- qiskit_ibm_runtime.fake_provider.FakeMontreal.html
- qiskit_ibm_runtime.fake_provider.FakeMontrealV2.html
- qiskit_ibm_runtime.fake_provider.FakeMumbai.html
- qiskit_ibm_runtime.fake_provider.FakeMumbaiV2.html
- qiskit_ibm_runtime.fake_provider.FakeNairobi.html
- qiskit_ibm_runtime.fake_provider.FakeNairobiV2.html
- qiskit_ibm_runtime.fake_provider.FakeOslo.html
- qiskit_ibm_runtime.fake_provider.FakeOurense.html
- qiskit_ibm_runtime.fake_provider.FakeOurenseV2.html
- qiskit_ibm_runtime.fake_provider.FakeParis.html
- qiskit_ibm_runtime.fake_provider.FakeParisV2.html
- qiskit_ibm_runtime.fake_provider.FakePerth.html
- qiskit_ibm_runtime.fake_provider.FakePoughkeepsie.html
- qiskit_ibm_runtime.fake_provider.FakePoughkeepsieV2.html
- qiskit_ibm_runtime.fake_provider.FakePrague.html
- qiskit_ibm_runtime.fake_provider.FakeProviderForBackendV2.html
- qiskit_ibm_runtime.fake_provider.FakeProvider.html
- qiskit_ibm_runtime.fake_provider.FakeQuito.html
- qiskit_ibm_runtime.fake_provider.FakeQuitoV2.html
- qiskit_ibm_runtime.fake_provider.FakeRochester.html
- qiskit_ibm_runtime.fake_provider.FakeRochesterV2.html
- qiskit_ibm_runtime.fake_provider.FakeRome.html
- qiskit_ibm_runtime.fake_provider.FakeRomeV2.html
- qiskit_ibm_runtime.fake_provider.FakeRueschlikon.html
- qiskit_ibm_runtime.fake_provider.FakeSantiago.html
- qiskit_ibm_runtime.fake_provider.FakeSantiagoV2.html
- qiskit_ibm_runtime.fake_provider.FakeSherbrooke.html
- qiskit_ibm_runtime.fake_provider.FakeSingapore.html
- qiskit_ibm_runtime.fake_provider.FakeSingaporeV2.html
- qiskit_ibm_runtime.fake_provider.FakeSydney.html
- qiskit_ibm_runtime.fake_provider.FakeSydneyV2.html
- qiskit_ibm_runtime.fake_provider.FakeTenerife.html
- qiskit_ibm_runtime.fake_provider.FakeTokyo.html
- qiskit_ibm_runtime.fake_provider.FakeToronto.html
- qiskit_ibm_runtime.fake_provider.FakeTorontoV2.html
- qiskit_ibm_runtime.fake_provider.FakeValencia.html
- qiskit_ibm_runtime.fake_provider.FakeValenciaV2.html
- qiskit_ibm_runtime.fake_provider.FakeVigo.html
- qiskit_ibm_runtime.fake_provider.FakeVigoV2.html
- qiskit_ibm_runtime.fake_provider.FakeWashington.html
- qiskit_ibm_runtime.fake_provider.FakeWashingtonV2.html
- qiskit_ibm_runtime.fake_provider.FakeYorktown.html
- qiskit_ibm_runtime.fake_provider.FakeYorktownV2.html

</details>

Co-authored-by: Rebecca Dimock <66339736+beckykd@users.noreply.github.com>

* Set use_symengine on qpy generation if symengine is installed (#1355)

This commit sets the use_symengine flag during qpy export used during
job payload generation if symengine is installed. For qiskit <1.0
symengine is a hard dependency on platforms that have support for it
(x86_64, aarch64, and ppc64le linux and macOS) and an optional
requirement on other qiskit supported platforms, and when available it
greatly improves the runtime performance of symbolic expressions in
Qiskit. By default QPY opts for the more compatible sympy representation
of an unbound ParameterExpression as it's maximally compatible, and
means that no matter the environment the payload will be loaded from it
will be able to parse the payload. In QPY version 10 a new flag was
added to the payload definition that enables users to use a native
binary symengine representation of a symbolic expression that is
significantly faster to generate and parse, but it still defaults to
sympy as using this flag limits the compatibility of the payload.
However, for runtime job submission we know that the service always has
symengine available so we should be using this flag for job submission
if the local environment has symengine installed as it will greatly
speed up the serialization of unbound ParameterExpression objects.

In Qiskit 1.0, symengine is promoted to a hard requriment for all
environments and use_symengine=True is the default in Qiskit's qpy
module. But, setting it like this is still a good idea as it will always
be safe to do this, it's just in qiskit 1.0 symengine will always be
installed.

* Fix for unit tests (#1356)

* Run all unit tests

* Import fake providers

* Format

* Fake providers not used in this branch

* Unused import

---------

Co-authored-by: Kevin Tian <kevin.tian@ibm.com>

* Update flaky integration tests (#1359)

* Fix bad Sphinx API doc Provider naming (#1360)

This resulted in the imports being called `qiskit_ibm_provider` rather than `qiskit_ibm_runtime`.

Co-authored-by: Frank Harkins <frankharkins@users.noreply.github.com>

* Merge qiskit-ibm-provider into qiskit-ibm-runtime (#1285)

* initial commit

* more replacements

* more replacements

* add auth/api

* add reno

* add qpy module back

* address comments

* fix docs build

* Update invalid token test (#1367)

* Copy pub/sub code into qiskit-ibm-runtime (#1349)

* Copy pub/sub code into qiskit-ibm-runtime

* fix docs build

* Remove mthree from requirements-dev (#1370)

* Handle Qiskit 1.0 removals (#1363)

* Handle Qiskit 1.0 removals

* Remove removed qiskit modules

* add both qiskit synthesis imports

* fix docs build

* fix lint errors from 1.0.0RC1

* update basicaer import

* Update qiskit_ibm_runtime/fake_provider/fake_backend.py

Co-authored-by: Elena Peña Tapia <57907331+ElePT@users.noreply.github.com>

* address comments

* Update imports & docstrings

---------

Co-authored-by: Elena Peña Tapia <57907331+ElePT@users.noreply.github.com>

* Copy over provider session & remove qiskit-ibm-provider (#1368)

* Move provider's session & remove qiskit-ibm-provider

* fix black

* Handle qpy serialization across versions and delete vendored fork (#1377)

* Handle qpy serialization across versions and delete vendored fork

For the next qiskit-ibm-runtime release it is desired to have it support
both Qiskit 0.45.x/0.46.x and Qiskit 1.0.0. To do this with QPY it means
we need to emit a fixed qpy version of 10 as that's currently the
maximum version the server side can parse. The easiest way to manage
this across versions is actually to rely on Qiskit's qpy module again.
Starting in Qiskit 1.0.0 the qiskit.qpy.dump() function a new kwarg,
version exists to specify the version of qpy emitted. We can use this
to control the rollout of QPY format versions as the server side is
updated. For right now this is fixed to version 10 which is the same as
the QPY format version emitted by 0.45.x and 0.46.0. Because the
versions are the same we can just use qiskit's qpy module moving forward
as either we're on qiskit 0.45.x/0.46.x and will emit version 10 (as there
is no option) or we're on >=1.0.0 and we explicitly set the qpy version
to one that's compatible with the server side.

The qpy internals usage to serialize parameters and parameter
expressions are left in place (although expanded on to include #1355 for
parameter expressions) as an alternative needs to be considered for
this. It is not a good idea to rely on qpy internals and explicitly
private functions to do partial serialization.

This commit also deletes the vendored fork as it's never been included
in a released version of qiskit-ibm-runtime and nothing is using it
anymore.

Related to: #1375

* Fix lint

* Fix lint again

* Run integration tests against Qiskit main (#1376)

* Fix qiskit main integratino tests cron job (#1379)

* Prepare release 0.19.0 (#1380)

* Prepare release 0.19

* add reno stating compatibility

* Update main branch version 0.19.1 (#1382)

* Porting qiskit-ibm-provider/787: Fix `DynamicCircuitInstructionDurations.from_backend` for both `Backend versions` (#1383)

* porting qiskit-ibm-provider/pull/787

* porting qiskit-ibm-provider/pull/787

* black

* oops

* monkey patch Qiskit/qiskit#11727

* black lynt

* mypy

---------

Co-authored-by: Kevin Tian <kevin.tian@ibm.com>

* Cast use_symengine input to a bool (#1385)

* Cast use_symengine input to a bool

This commit works around a bug in Qiskit 0.45.x, 0.46.0, and 1.0.0rc1
with the `use_symengine` flag on `qpy.dump()`. The dump function has a
bug when it receives a truthy value instead of a bool literal that it
will generate a corrupt qpy because of a mismatch between how the
encoding was processed (the encoding is incorrectly set to sympy in the
file header but uses symengine encoding in the actual body of the
circuit.  This is being fixed in Qiskit/qiskit#11730 for 1.0.0, and will
be backported to 0.46.1. But to ensure compatibility with 0.45.x, 0.46.0,
and 1.0.0rc1 while waiting for those releases we can workaround this by
just casting the value to a boolean.

* Fix mypy failures

* Mypy fixes again

* Prepare release 0.19.1 (#1386)

* Update main branch version 0.19.2 (#1388)

* Use barrier labels to define intervals for DD (#1358)

* Add transpiler tests

* Named barrier to select dd intervals

* reno

* consistent pad arguments in PadDelay

* Decouple single_pulse option

* fix docsting

* Add test

* Fix for PadDelay

* format

* line too long

---------

Co-authored-by: kevin-tian <kevin.tian@ibm.com>

* Remove remaining qiskit.org links (#1397)

* Remove remaining qiskit.org links

* Update qiskit_ibm_runtime/provider_session.py

Co-authored-by: Kevin Tian <kt474@cornell.edu>

---------

Co-authored-by: Kevin Tian <kt474@cornell.edu>

* Support Python 3.12 (#1347)

* Support Python 3.12

* update requirments

* update requirements

* Add deprecation policy (#1405)

* add deprecation file

* update guide

* fix wording

Co-authored-by: Kevin Tian <kt474@cornell.edu>

---------

Co-authored-by: Kevin Tian <kt474@cornell.edu>

* Fix scheduling in control flow with instructions of non-uniform durations (#1378)

* Map indices for durations in inner block

* Add test

* Reno

* Fix docs

* Missing docstring

---------

Co-authored-by: Kevin Tian <kevin.tian@ibm.com>

* Add deprecation warning for abstract circuits (#1404)

* Add abstract circuit warning

* add reno

* use correct Sequence import

* unit tests

* Fix docs build with Qiskit 1.0  (#1411)

* fix docs build

* Replace qiskit.tools

* Use POST /sessions endpoint  (#1372)

* wip use post sessions

* address comments

* fix mypy & lint

* use private method

* Add reno

* attempt fix unit tests

* unit tests

* add logic to work with IQP

* remove todo

* Update releasenotes/notes/session-modes-5c22b68620f8d690.yaml

Co-authored-by: Jessie Yu <jessieyu@us.ibm.com>

* Update docstrings, passing mode into payload

* Update unit tests

* address comments

* Pass max_time to /sessions

* unit tests

* integration test

---------

Co-authored-by: Jessie Yu <jessieyu@us.ibm.com>

* Use POST /sessions in backend.run sessions (#1415)

* Use POST /sessions in backend.run sessions

* Add reno

* update tests

* add test_run_after_cancel back

* remove max_time arg from Session

* Add max_time

* Prepare release 0.20.0 (#1418)

* Update main branch version 0.20.1 (#1419)

* Update ISA validation (#1414)

* check coupling map

* restore stack level

* mypy

* remove layout check

* check width

* allow pulse gates

* add release note

* Fix bug with retrieving fake backends  (#1402)

* bug fix w retrieving fake backend

* Move test

* Update sessions mode release note (#1430)

* Add warning if no backend provided on cloud channel (#1425)

* add warning if no backend provided

* add test and reno

* Update msg & add to base_primitive

* Update reno

* Update releasenotes/notes/require-cloud-backend-38a74144347c735d.yaml

Co-authored-by: Jessie Yu <jessieyu@us.ibm.com>

---------

Co-authored-by: Jessie Yu <jessieyu@us.ibm.com>

* Fix missing releases notes before Runtime 0.9 (#1434)

Even though we had the release note files, Reno was not including them.

* Use sphinx.ext.linkcode for more precise source code links (#1431)

* added .idea to .gitignore for Pycharm

* switched sphinx-ext-viewcode for sphinx-ext-linkcode

* remove leftover code from Azure

Co-authored-by: Eric Arellano <14852634+Eric-Arellano@users.noreply.github.com>

* Update tox.ini

* remove leftover code from Azure part 2

Co-authored-by: Eric Arellano <14852634+Eric-Arellano@users.noreply.github.com>

* change dashes to underscores

Co-authored-by: Eric Arellano <14852634+Eric-Arellano@users.noreply.github.com>

* switch from qiskit to qiskit_ibm_runtime

Co-authored-by: Eric Arellano <14852634+Eric-Arellano@users.noreply.github.com>

* remove leftover code from Azure part 3

Co-authored-by: Eric Arellano <14852634+Eric-Arellano@users.noreply.github.com>

* final updates to determine_github_branch method

Co-authored-by: Eric Arellano <14852634+Eric-Arellano@users.noreply.github.com>

* cha

Co-authored-by: Eric Arellano <14852634+Eric-Arellano@users.noreply.github.com>

* added colon

* Fix issue with inherited methods

---------

Co-authored-by: Eric Arellano <14852634+Eric-Arellano@users.noreply.github.com>
Co-authored-by: Kevin Tian <kevin.tian@ibm.com>

* Update deprecated actions in workflows (#1439)

### Summary
In recent PRs including my PR #1431, the CI has been throwing several errors due to old versions of actions that are using node12 or node16 instead of node20. I updated the actions to use the latest versions which should eliminate the CI warnings.

* Fix deprecated `upload-artifact` GitHub action (#1441)

* Fix bad tox.ini passenv setting (#1445)

See Qiskit/qiskit-ibm-provider#825 for context.

* Handle control flow instructions in Target generation (#1443)

* Handle control flow instructions in Target generation

This commit updates the convert_to_target() function that is used to
convert the API response objects used to describe a backend and generate
a Qiskit Target object from that to properly handle control flow
instructions. The supported control flow instructions are listed in the
`supported_instructions` field of the configuration payload. [1] This
commit updates the logic to look for the presence of known control flow
instruction names in that field and add them as appropriate to the
target as global variadic instructions to indicate to Qiskit's
transpiler and other Target object users that the backend supports the
instructions.

[1] https://github.com/Qiskit/ibm-quantum-schemas/blob/0231221082ec722cc31db09c0b41a25f441ac338/schemas/backend_configuration_schema.json#L165-L170

* Add release note

---------

Co-authored-by: Jessie Yu <jessieyu@us.ibm.com>

* Update backend() type hint to BackendV2 (#1442)

Co-authored-by: Jessie Yu <jessieyu@us.ibm.com>

* Updates to tutorials for 1.0 + ISA changes (#1408)

* A majority of these tutorials are already 1.0 ready, but were re-run to double-check

Additional changes include fixes for the ISA changes in #794

* fix black/lint

* docs build

* fix docs build again

* docs build

---------

Co-authored-by: Kevin Tian <kevin.tian@ibm.com>

* Migrate from `pkg_resources` to `importlib.metadata` (#1449)

PR #1347 added `setuptools` to `requirements-dev.txt` in an effort
to make `qiskit-ibm-runtime` work with Python 3.12.  However,
`qiskit_ibm_runtime/api/session.py` actually imports `pkg_resources`,
which is provided by setuptools, so really setuptools should have been
added to [`REQUIREMENTS`](https://github.com/Qiskit/qiskit-ibm-runtime/blob/e152d122782959a04ebf2330f776d4c4e309ad14/setup.py#L21)
in `setup.py` so that it is installed automatically for any downstream
users of Qiskit Runtime, too.

Better yet, however, is to drop this explicit dependency on setuptools,
since [`pkg_resources` is deprecated](https://setuptools.pypa.io/en/latest/pkg_resources.html)
in favor of `importlib`.  Hence, this PR migrates from `pkg_resources`
to `importlib.metadata` (there are a few more words about this
[here](googleapis/python-api-core#27 (comment))).

My investigation into this was prompted by us trying to add
Python 3.12 support to the circuit-knitting-toolbox
(Qiskit-Extensions/circuit-knitting-toolbox#429),
and seeing CI errors prompted by `qiskit-ibm-runtime`'s importing
of `pkg_resources`.

Co-authored-by: Kevin Tian <kevin.tian@ibm.com>

* Add fake backends for newer IBM backends (#1440)

* Add fake backends for newer IBM backends

This commit adds news fake backend classes for the following newer IBM
backends: Algiers, Brisbane, Cusco, Kawasaki, Kyoto, Osaka, Peekskill, Quebec,
and Torino. This was done using a modified version of the qiskit script
to update backends [1] (to use qiskit-ibm-runtime instead of
qiskit-ibmq-provider). There is a standalone script adding this
functionality for this repo in #1263.

[1] https://github.com/Qiskit/qiskit/blob/stable/0.46/tools/update_fake_backends.py

Fixes #1421

* Remove unused import

* Add new backends to FakeProviderForBackendV2 too

* Don't forget FakeKyiv in docs or provider class

---------

Co-authored-by: Kevin Tian <kevin.tian@ibm.com>

* Run q-ctrl tests nightly (#1452)

* Raise if abstract circuits are used (#1437)

* support dynamic circuits

* raise for abstract circuits

* lint

* fix test

* remove hard coded instructions

* check target is not none

* lint

* fix test

* check for error not warning

* bypass simulator

* fix merge issues

* delete extra line

---------

Co-authored-by: Elena Peña Tapia <57907331+ElePT@users.noreply.github.com>
Co-authored-by: Kevin Tian <kevin.tian@ibm.com>
Co-authored-by: merav-aharoni <merav@il.ibm.com>
Co-authored-by: Salvador de la Puente González <neo.salvador@gmail.com>
Co-authored-by: Eric Arellano <14852634+Eric-Arellano@users.noreply.github.com>
Co-authored-by: Sanket Panda <pandasa123@gmail.com>
Co-authored-by: abbycross <across@us.ibm.com>
Co-authored-by: Kevin Tian <kt474@cornell.edu>
Co-authored-by: Rathish Cholarajan <rathishc24@gmail.com>
Co-authored-by: Blake Johnson <blakejohnson04@gmail.com>
Co-authored-by: Kevin J. Sung <kevjsung@umich.edu>
Co-authored-by: Jake Lishman <jake.lishman@ibm.com>
Co-authored-by: Kaelyn Ferris <43348706+kaelynj@users.noreply.github.com>
Co-authored-by: Rebecca Dimock <66339736+beckykd@users.noreply.github.com>
Co-authored-by: Matthew Treinish <mtreinish@kortar.org>
Co-authored-by: Diego Ristè <10402430+dieris@users.noreply.github.com>
Co-authored-by: Frank Harkins <frankharkins@users.noreply.github.com>
Co-authored-by: Luciano Bello <bel@zurich.ibm.com>
Co-authored-by: melechlapson <melechlapson@yahoo.com>
Co-authored-by: melechlapson <Melech.Lapson@ibm.com>
Co-authored-by: Sanket Panda <sanket@ibm.com>
Co-authored-by: Jim Garrison <garrison@ibm.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design.
Projects
None yet
Development

No branches or pull requests

6 participants