Ejemplo n.º 1
0
    def test_get_backend(self):
        """Test get backends.

        If all correct should return a name the same as input.
        """
        local_provider = DefaultQISKitProvider()
        backend = local_provider.get_backend(name='local_qasm_simulator')
        self.assertEqual(backend.configuration['name'], 'local_qasm_simulator')
Ejemplo n.º 2
0
    def test_get_backend(self):
        """Test get backends.

        If all correct should return a name the same as input.
        """
        local_provider = DefaultQISKitProvider()
        backend = local_provider.get_backend(name='local_qasm_simulator_py')
        self.assertEqual(backend.configuration['name'], 'local_qasm_simulator_py')
Ejemplo n.º 3
0
    def test_local_backends_exist(self):
        """Test if there are local backends.

        If all correct some should exists.
        """
        local_provider = DefaultQISKitProvider()
        local = local_provider.available_backends({'local': True})
        self.log.info(local)
        self.assertTrue(len(local) > 0)
Ejemplo n.º 4
0
    def test_local_backends_exist(self):
        """Test if there are local backends.

        If all correct some should exists.
        """
        local_provider = DefaultQISKitProvider()
        local = local_provider.available_backends({'local': True})
        self.log.info(local)
        self.assertTrue(len(local) > 0)
Ejemplo n.º 5
0
    def test_local_backend_parameters(self):
        """Test backend parameters.

        If all correct should pass the vaildation.
        """
        qiskit_provider = DefaultQISKitProvider()
        local_backends = qiskit_provider.available_backends({'local': True})
        for backend in local_backends:
            parameters = backend.parameters
            # FIXME test against schema and decide what parameters
            # is for a simulator
            self.assertEqual(len(parameters), 0)
Ejemplo n.º 6
0
    def test_local_backend_calibration(self):
        """Test backend calibration.

        If all correct should pass the vaildation.
        """
        qiskit_provider = DefaultQISKitProvider()
        local_backends = qiskit_provider.available_backends({'local': True})
        for backend in local_backends:
            calibration = backend.calibration
            # FIXME test against schema and decide what calibration
            # is for a simulator
            self.assertEqual(len(calibration), 0)
Ejemplo n.º 7
0
    def test_local_backend_calibration(self):
        """Test backend calibration.

        If all correct should pass the vaildation.
        """
        qiskit_provider = DefaultQISKitProvider()
        local_backends = qiskit_provider.available_backends({'local': True})
        for backend in local_backends:
            calibration = backend.calibration
            # FIXME test against schema and decide what calibration
            # is for a simulator
            self.assertEqual(len(calibration), 0)
Ejemplo n.º 8
0
    def test_local_backend_parameters(self):
        """Test backend parameters.

        If all correct should pass the vaildation.
        """
        qiskit_provider = DefaultQISKitProvider()
        local_backends = qiskit_provider.available_backends({'local': True})
        for backend in local_backends:
            parameters = backend.parameters
            # FIXME test against schema and decide what parameters
            # is for a simulator
            self.assertEqual(len(parameters), 0)
Ejemplo n.º 9
0
    def test_local_backend_status(self):
        """Test backend_status.

        If all correct should pass the vaildation.
        """
        local_provider = DefaultQISKitProvider()
        backend = local_provider.get_backend(name='local_qasm_simulator')
        status = backend.status
        schema_path = self._get_resource_path(
            'deprecated/backends/backend_status_schema_py.json', path=Path.SCHEMAS)
        with open(schema_path, 'r') as schema_file:
            schema = json.load(schema_file)

        jsonschema.validate(status, schema)
Ejemplo n.º 10
0
    def test_local_backend_status(self):
        """Test backend_status.

        If all correct should pass the vaildation.
        """
        local_provider = DefaultQISKitProvider()
        backend = local_provider.get_backend(name='local_qasm_simulator')
        status = backend.status
        schema_path = self._get_resource_path(
            'backends/backend_status_schema_py.json', path=Path.SCHEMAS)
        with open(schema_path, 'r') as schema_file:
            schema = json.load(schema_file)

        jsonschema.validate(status, schema)
Ejemplo n.º 11
0
    def test_local_backend_configuration(self):
        """Test backend configuration.

        If all correct should pass the vaildation.
        """
        qiskit_provider = DefaultQISKitProvider()
        local_backends = qiskit_provider.available_backends({'local': True})
        for backend in local_backends:
            configuration = backend.configuration
            schema_path = self._get_resource_path(
                'backends/backend_configuration_schema_old_py.json',
                path=Path.SCHEMAS)
            with open(schema_path, 'r') as schema_file:
                schema = json.load(schema_file)
            jsonschema.validate(configuration, schema)
Ejemplo n.º 12
0
    def test_local_backend_configuration(self):
        """Test backend configuration.

        If all correct should pass the vaildation.
        """
        qiskit_provider = DefaultQISKitProvider()
        local_backends = qiskit_provider.available_backends({'local': True})
        for backend in local_backends:
            configuration = backend.configuration
            schema_path = self._get_resource_path(
                'deprecated/backends/backend_configuration_schema_old_py.json',
                path=Path.SCHEMAS)
            with open(schema_path, 'r') as schema_file:
                schema = json.load(schema_file)
            jsonschema.validate(configuration, schema)
Ejemplo n.º 13
0
    def _(*args, **kwargs):
        # pylint: disable=invalid-name
        if SKIP_ONLINE_TESTS:
            raise unittest.SkipTest('Skipping online tests')

        # Cleanup the credentials, as this file is shared by the tests.
        from qiskit.wrapper import _wrapper
        _wrapper._DEFAULT_PROVIDER = DefaultQISKitProvider()

        # Attempt to read the standard credentials.
        account_name = get_account_name(IBMQProvider)
        discovered_credentials = discover_credentials()
        if account_name in discovered_credentials.keys():
            credentials = discovered_credentials[account_name]
            kwargs.update({
                'QE_TOKEN': credentials.get('token'),
                'QE_URL': credentials.get('url'),
                'hub': credentials.get('hub'),
                'group': credentials.get('group'),
                'project': credentials.get('project'),
            })
        else:
            raise Exception('Could not locate valid credentials')

        return func(*args, **kwargs)
Ejemplo n.º 14
0
    def test_local_backend_status(self):
        """Test backend_status.

        If all correct should pass the vaildation.
        """
        # FIXME: reintroduce in 0.6
        self.skipTest('Skipping due to available vs operational')

        local_provider = DefaultQISKitProvider()
        backend = local_provider.get_backend(name='local_qasm_simulator')
        status = backend.status
        schema_path = self._get_resource_path(
            'deprecated/backends/backend_status_schema_py.json', path=Path.SCHEMAS)
        with open(schema_path, 'r') as schema_file:
            schema = json.load(schema_file)

        jsonschema.validate(status, schema)
Ejemplo n.º 15
0
    def _wrapper(self, *args, **kwargs):
        if TEST_OPTIONS['skip_online']:
            raise unittest.SkipTest('Skipping online tests')

        # Cleanup the credentials, as this file is shared by the tests.
        from qiskit.wrapper import _wrapper as qiskit_wrapper
        qiskit_wrapper._DEFAULT_PROVIDER = DefaultQISKitProvider()
        kwargs.update(_get_credentials(self, TEST_OPTIONS))

        decorated_func = func
        if TEST_OPTIONS['rec'] or TEST_OPTIONS['mock_online']:
            # For recording or for replaying existing cassettes, the test should be decorated with
            # use_cassette.
            decorated_func = VCR.use_cassette()(decorated_func)

        return decorated_func(self, *args, **kwargs)
Ejemplo n.º 16
0
    def _(*args, **kwargs):
        # pylint: disable=invalid-name
        if SKIP_ONLINE_TESTS:
            raise unittest.SkipTest('Skipping online tests')

        # Cleanup the credentials, as this file is shared by the tests.
        from qiskit.wrapper import _wrapper
        _wrapper._DEFAULT_PROVIDER = DefaultQISKitProvider()

        if os.getenv('USE_ALTERNATE_ENV_CREDENTIALS', False):
            # Special case: instead of using the standard credentials mechanism,
            # load them from different environment variables. This assumes they
            # will always be in place, as is used by the Travis setup.
            kwargs.update({
                'QE_TOKEN': os.getenv('IBMQ_TOKEN'),
                'QE_URL': os.getenv('IBMQ_URL'),
                'hub': os.getenv('IBMQ_HUB'),
                'group': os.getenv('IBMQ_GROUP'),
                'project': os.getenv('IBMQ_PROJECT'),
            })
            args[0].using_ibmq_credentials = True
        else:
            # Attempt to read the standard credentials.
            account_name = get_account_name(IBMQProvider)
            discovered_credentials = discover_credentials()
            if account_name in discovered_credentials.keys():
                credentials = discovered_credentials[account_name]
                kwargs.update({
                    'QE_TOKEN': credentials.get('token'),
                    'QE_URL': credentials.get('url'),
                    'hub': credentials.get('hub'),
                    'group': credentials.get('group'),
                    'project': credentials.get('project'),
                })
                if (credentials.get('hub') and credentials.get('group')
                        and credentials.get('project')):
                    args[0].using_ibmq_credentials = True
            else:
                raise Exception('Could not locate valid credentials')

        return func(*args, **kwargs)
Ejemplo n.º 17
0
# 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.
"""Helper module for simplified QISKit usage."""

import logging
import warnings
from qiskit import transpiler, QISKitError
from qiskit.backends.ibmq import IBMQProvider
from qiskit.wrapper import credentials
from qiskit.wrapper.defaultqiskitprovider import DefaultQISKitProvider
from qiskit._util import _parse_ibmq_credentials
from ._circuittoolkit import circuit_from_qasm_file, circuit_from_qasm_string

# Default provider used by the rest of the functions on this module. Please
# note that this is a global object.
_DEFAULT_PROVIDER = DefaultQISKitProvider()

logger = logging.getLogger(__name__)


def register(*args, provider_class=IBMQProvider, **kwargs):
    """
    Authenticate against an online backend provider.
    This is a factory method that returns the provider that gets registered.

    Note that if no parameters are passed, this method will try to
    automatically discover the credentials for IBMQ in the following places,
    in order::

        1. in the `Qconfig.py` file in the current working directory.
        2. in the environment variables.
Ejemplo n.º 18
0
 def tearDown(self):
     # Reset the default provider, as in practice it acts as a singleton
     # due to importing the wrapper from qiskit.
     from qiskit.wrapper import _wrapper
     _wrapper._DEFAULT_PROVIDER = DefaultQISKitProvider()