Skip to content
This repository was archived by the owner on Jul 28, 2023. It is now read-only.
Merged
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
9 changes: 1 addition & 8 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,8 @@ sudo: false
stage_generic: &stage_generic
install:
# Install step for jobs that require compilation and qa.
# TODO: until terra 0.8 is released, install a terra branch and this
# package dependencies manually.
# - pip install -U -r requirements.txt
- pip install "requests>=2.19"
- pip install "requests-ntlm>=1.1.0"
- pip install "websockets>=7,<8"
- git clone https://github.com/Qiskit/qiskit-terra.git
- pip install cython
- pip install -e qiskit-terra
- pip install -U -r requirements.txt
- pip install -U -r requirements-dev.txt
script:
# Run the tests.
Expand Down
27 changes: 27 additions & 0 deletions qiskit/providers/ibmq/api/ibmqconnector.py
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,33 @@ def available_backends(self):

return response

def circuit_run(self, name, **kwargs):
"""Execute a Circuit.

Args:
name (str): name of the Circuit.
**kwargs (dict): arguments for the Circuit.

Returns:
dict: json response.

Raises:
CredentialsError: if the user was not authenticated.
"""
if not self.check_credentials():
raise CredentialsError('credentials invalid')

url = '/QCircuitApiModels'

payload = {
'name': name,
'params': kwargs
}

response = self.req.post(url, data=json.dumps(payload))

return response

def websocket_client(self):
"""Return a websocket client for interacting with IBMQ.

Expand Down
7 changes: 6 additions & 1 deletion qiskit/providers/ibmq/api_v2/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@

class ApiError(ApiErrorV1):
"""Generic IBM Q API error."""
def __init__(self, *args, original_exception=None, **kwargs):
pass


class RequestsApiError(ApiError):
"""Exception re-raising a RequestException."""
def __init__(self, original_exception, *args, **kwargs):
self.original_exception = original_exception
super().__init__(*args, **kwargs)
12 changes: 12 additions & 0 deletions qiskit/providers/ibmq/api_v2/ibmqclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,18 @@ def api_version(self):
"""
return self.api_client.version()

def circuit_run(self, name, **kwargs):
"""Execute a Circuit.

Args:
name (str): name of the Circuit.
**kwargs (dict): arguments for the Circuit.

Returns:
dict: json response.
"""
return self.api_client.circuit(name, **kwargs)

# Endpoints for compatibility with classic IBMQConnector. These functions
# are meant to facilitate the transition, and should be removed moving
# forward.
Expand Down
5 changes: 2 additions & 3 deletions qiskit/providers/ibmq/api_v2/rest/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,8 @@ def user_info(self):
# Revise the URL.
try:
api_url = response['urls']['http']
if api_url.endswith('.com?private=true'):
response['urls']['http'] = '{}/api'.format(
api_url.split('?')[0])
if not api_url.endswith('/api'):
response['urls']['http'] = '{}/api'.format(api_url)
except KeyError:
pass

Expand Down
28 changes: 25 additions & 3 deletions qiskit/providers/ibmq/api_v2/rest/root.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class Api(RestAdapterBase):
'hubs': '/Network',
'jobs': '/Jobs',
'jobs_status': '/Jobs/status',
'circuit': '/QCircuitApiModels',
'version': '/version'
}

Expand Down Expand Up @@ -100,9 +101,30 @@ def run_job(self, backend_name, qobj_dict):
"""
url = self.get_url('jobs')

payload = {'qObject': qobj_dict,
'backend': {'name': backend_name},
'shots': qobj_dict.get('config', {}).get('shots', 1)}
payload = {
'qObject': qobj_dict,
'backend': {'name': backend_name},
'shots': qobj_dict.get('config', {}).get('shots', 1)
}

return self.session.post(url, json=payload).json()

def circuit(self, name, **kwargs):
"""Execute a Circuit.

Args:
name (str): name of the Circuit.
**kwargs (dict): arguments for the Circuit.

Returns:
dict: json response.
"""
url = self.get_url('circuit')

payload = {
'name': name,
'params': kwargs
}

return self.session.post(url, json=payload).json()

Expand Down
6 changes: 2 additions & 4 deletions qiskit/providers/ibmq/api_v2/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@
from requests.adapters import HTTPAdapter
from urllib3.util.retry import Retry

from .exceptions import ApiError

from .exceptions import RequestsApiError

STATUS_FORCELIST = (
500, # Internal Server Error
Expand Down Expand Up @@ -116,7 +115,6 @@ def request(self, method, url, **kwargs):
if self.access_token:
message = message.replace(self.access_token, '[redacted]')

raise ApiError(message,
original_exception=ex)
raise RequestsApiError(ex, message) from None

return response
17 changes: 17 additions & 0 deletions qiskit/providers/ibmq/circuits/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# -*- coding: utf-8 -*-

# This code is part of Qiskit.
#
# (C) Copyright IBM 2018, 2019.
#
# This code is licensed under the Apache License, Version 2.0. You may
# obtain a copy of this license in the LICENSE.txt file in the root directory
# of this source tree or at http://www.apache.org/licenses/LICENSE-2.0.
#
# Any modifications or derivative works of this code must retain this
# copyright notice, and modified files need to carry a notice indicating
# that they have been altered from the originals.

"""Module for interacting with Circuits."""

from .manager import CircuitsManager
48 changes: 48 additions & 0 deletions qiskit/providers/ibmq/circuits/exceptions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# -*- coding: utf-8 -*-

# This code is part of Qiskit.
#
# (C) Copyright IBM 2018, 2019.
#
# This code is licensed under the Apache License, Version 2.0. You may
# obtain a copy of this license in the LICENSE.txt file in the root directory
# of this source tree or at http://www.apache.org/licenses/LICENSE-2.0.
#
# Any modifications or derivative works of this code must retain this
# copyright notice, and modified files need to carry a notice indicating
# that they have been altered from the originals.

"""Exceptions related to Circuits."""

from qiskit.providers.ibmq.exceptions import IBMQError


CIRCUIT_NOT_ALLOWED = 'Circuit support is not available yet in this account'
CIRCUIT_SUBMIT_ERROR = 'Circuit could not be submitted: {}'
CIRCUIT_RESULT_ERROR = 'Circuit result could not be returned: {}'


class CircuitError(IBMQError):
"""Generic Circuit exception."""
pass


class CircuitAvailabilityError(CircuitError):
"""Error while accessing a Circuit."""

def __init__(self, message=''):
super().__init__(message or CIRCUIT_NOT_ALLOWED)


class CircuitSubmitError(CircuitError):
"""Error while submitting a Circuit."""

def __init__(self, message):
super().__init__(CIRCUIT_SUBMIT_ERROR.format(message))


class CircuitResultError(CircuitError):
"""Error during the results of a Circuit."""

def __init__(self, message):
super().__init__(CIRCUIT_RESULT_ERROR.format(message))
Loading