Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions qiskit/backends/providers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# -*- coding: utf-8 -*-

# Copyright 2018, IBM.
#
# This source code is licensed under the Apache License, Version 2.0 found in
# the LICENSE.txt file in the root directory of this source tree.

"""Provider plugin manager."""

import logging

import stevedore

logger = logging.getLogger(__name__)


class ProviderPluginManager:
"""Qiskit provider plugin manager class

This class is used to manage the lifecycle of external backend provider
plugins. It provides functions for getting all backends
"""
def __init__(self):
self.ext_plugins = stevedore.ExtensionManager(
'qiskit.providers', invoke_on_load=True,
propagate_map_exceptions=True,
on_load_failure_callback=self.failure_hook)

@staticmethod
def failure_hook(_, err_plugin, err):
"""Log errors on import and don't fail."""
logger.error("Could not load provider plugin %r with error: %s",
err_plugin.name, err)

def get_providers(self):
"""Return dict of all discovered provider plugins."""
providers = {}
for plug in self.ext_plugins:
providers[plug.name] = plug.obj
return providers

def get_all_backends(self):
"""Return dict of lists of backends for all discovered provider plugins."""
backends_dict = {}
for plug in self.ext_plugins:
backends_dict[plug.name] = plug.obj.backends()
return backends_dict
5 changes: 5 additions & 0 deletions qiskit/providers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,17 @@

import pkgutil

from qiskit.backends.providers import ProviderPluginManager
from .basebackend import BaseBackend
from .baseprovider import BaseProvider
from .basejob import BaseJob
from .exceptions import JobError, JobTimeoutError, QiskitBackendNotFoundError
from .jobstatus import JobStatus


ALL_PROVIDERS = ProviderPluginManager().get_providers()
for prov in ALL_PROVIDERS:
globals()[prov] = ALL_PROVIDERS[prov]

# Allow extending this namespace.
__path__ = pkgutil.extend_path(__path__, __name__)
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ ply>=3.10
psutil>=5
scipy>=0.19
sympy>=1.3
stevedore>=1.30.0
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"psutil>=5",
"scipy>=0.19,!=0.19.1",
"sympy>=1.3"
"stevedore>=1.30.0"
]

# Add Cython extensions here
Expand Down