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

Rename get_backend to backend #85

Merged
merged 1 commit into from
Jan 10, 2022
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ pip install qiskit-ibm-runtime
print(service.backends())

# get IBM's simulator backend
simulator_backend = service.get_backend('ibmq_qasm_simulator')
simulator_backend = service.backend('ibmq_qasm_simulator')
```

### Load Account from Environment Variables
Expand Down
2 changes: 1 addition & 1 deletion qiskit_ibm_runtime/hub_group_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def _discover_remote_backends(self) -> Dict[str, "ibm_backend.IBMBackend"]:
)
return ret

def get_backend(self, name: str) -> Optional["ibm_backend.IBMBackend"]:
def backend(self, name: str) -> Optional["ibm_backend.IBMBackend"]:
"""Get backend by name."""
return self._backends.get(name, None)

Expand Down
12 changes: 6 additions & 6 deletions qiskit_ibm_runtime/ibm_runtime_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@ def _get_hgp(
f"Hub/group/project {instance} "
"could not be found for this account."
)
if backend_name and not self._hgps[instance].get_backend(backend_name):
if backend_name and not self._hgps[instance].backend(backend_name):
raise QiskitBackendNotFoundError(
f"Backend {backend_name} cannot be found in "
f"hub/group/project {instance}"
Expand All @@ -441,7 +441,7 @@ def _get_hgp(
return list(self._hgps.values())[0]

for hgp in self._hgps.values():
if hgp.get_backend(backend_name):
if hgp.backend(backend_name):
return hgp

raise QiskitBackendNotFoundError(
Expand Down Expand Up @@ -590,7 +590,7 @@ def saved_accounts(
),
)

def get_backend(
def backend(
self,
name: str = None,
instance: Optional[str] = None,
Expand Down Expand Up @@ -810,12 +810,12 @@ def run(
)
# Find the right hgp
hgp = self._get_hgp(instance=instance, backend_name=backend_name)
backend = hgp.get_backend(backend_name)
backend = hgp.backend(backend_name)
hgp_name = hgp.name
else:
# TODO Support instance for cloud
# TODO Support optional backend name when fully supported by server
backend = self.get_backend(backend_name)
backend = self.backend(backend_name)

result_decoder = result_decoder or ResultDecoder
try:
Expand Down Expand Up @@ -1216,7 +1216,7 @@ def _decode_job(self, raw_data: Dict) -> RuntimeJob:
)
# Try to find the right backend
try:
backend = self.get_backend(raw_data["backend"], instance=instance)
backend = self.backend(raw_data["backend"], instance=instance)
except (IBMProviderError, QiskitBackendNotFoundError):
backend = ibm_backend.IBMRetiredBackend.from_name(
backend_name=raw_data["backend"],
Expand Down
2 changes: 1 addition & 1 deletion qiskit_ibm_runtime/jupyter/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
import qiskit_ibm_runtime.jupyter

service = IBMRuntimeService()
backend = service.get_backend('ibmq_vigo')
backend = service.backend('ibmq_vigo')

.. jupyter-execute::
:hide-code:
Expand Down
2 changes: 1 addition & 1 deletion qiskit_ibm_runtime/test/ibm_provider_mock.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,6 @@ def mock_get_backend(backend):
"The specified backend name is not a valid mock from qiskit.test.mock"
)
fake_backend = getattr(backend_mocks, backend)()
mock_ibm_provider.get_backend.return_value = fake_backend
mock_ibm_provider.backend.return_value = fake_backend
mock_ibm_provider.return_value = mock_ibm_provider
qiskit_ibm_runtime.IBMRuntimeService = mock_ibm_provider
2 changes: 1 addition & 1 deletion qiskit_ibm_runtime/visualization/interactive/error_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def iplot_error_map(
from qiskit_ibm_runtime.visualization import iplot_error_map

service = IBMRuntimeService()
backend = service.get_backend('ibmq_vigo')
backend = service.backend('ibmq_vigo')

iplot_error_map(backend, as_widget=True)
"""
Expand Down
2 changes: 1 addition & 1 deletion qiskit_ibm_runtime/visualization/interactive/gate_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def iplot_gate_map(
from qiskit_ibm_runtime.visualization import iplot_gate_map

service = IBMRuntimeService()
backend = service.get_backend('ibmq_vigo')
backend = service.backend('ibmq_vigo')

iplot_gate_map(backend, as_widget=True)
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ features:
from qiskit.test.reference_circuits import ReferenceCircuits

provider = IBMQ.load_account()
backend = provider.get_backend('ibmq_vigo')
backend = provider.backend('ibmq_vigo')
circuits = transpile(ReferenceCircuits.bell(), backend=backend)
default_shots = backend.options.shots # Returns the backend default of 1024 shots.
backend.set_options(shots=2048) # All jobs will now have use 2048 shots.
Expand Down
12 changes: 6 additions & 6 deletions test/test_backend_retrieval.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,35 +200,35 @@ class TestGetBackend(IBMTestCase):
def test_get_common_backend(self):
"""Test getting a backend that is in default and non-default hgp."""
service = FakeRuntimeService(auth="legacy", token="my_token")
backend = service.get_backend(FakeRuntimeService.DEFAULT_COMMON_BACKEND)
backend = service.backend(FakeRuntimeService.DEFAULT_COMMON_BACKEND)
self.assertEqual(backend._api_client.hgp, list(service._hgps.keys())[0])

def test_get_unique_backend_default_hgp(self):
"""Test getting a backend in the default hgp."""
service = FakeRuntimeService(auth="legacy", token="my_token")
backend_name = FakeRuntimeService.DEFAULT_UNIQUE_BACKEND_PREFIX + "0"
backend = service.get_backend(backend_name)
backend = service.backend(backend_name)
self.assertEqual(backend._api_client.hgp, list(service._hgps.keys())[0])

def test_get_unique_backend_non_default_hgp(self):
"""Test getting a backend in the non default hgp."""
service = FakeRuntimeService(auth="legacy", token="my_token")
backend_name = FakeRuntimeService.DEFAULT_UNIQUE_BACKEND_PREFIX + "1"
backend = service.get_backend(backend_name)
backend = service.backend(backend_name)
self.assertEqual(backend._api_client.hgp, list(service._hgps.keys())[1])

def test_get_phantom_backend(self):
"""Test getting a phantom backend."""
service = FakeRuntimeService(auth="legacy", token="my_token")
with self.assertRaises(QiskitBackendNotFoundError):
service.get_backend("phantom")
service.backend("phantom")

def test_get_backend_by_hgp(self):
"""Test getting a backend by hgp."""
hgp = FakeRuntimeService.DEFAULT_HGPS[1]
backend_name = FakeRuntimeService.DEFAULT_COMMON_BACKEND
service = FakeRuntimeService(auth="legacy", token="my_token")
backend = service.get_backend(backend_name, instance=hgp)
backend = service.backend(backend_name, instance=hgp)
self.assertEqual(backend._api_client.hgp, hgp)

def test_get_backend_by_bad_hgp(self):
Expand All @@ -237,4 +237,4 @@ def test_get_backend_by_bad_hgp(self):
backend_name = FakeRuntimeService.DEFAULT_UNIQUE_BACKEND_PREFIX + "0"
service = FakeRuntimeService(auth="legacy", token="my_token")
with self.assertRaises(QiskitBackendNotFoundError):
_ = service.get_backend(backend_name, instance=hgp)
_ = service.backend(backend_name, instance=hgp)
2 changes: 1 addition & 1 deletion test/test_integration_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def test_backends(self, service):
def test_get_backend(self, service):
"""Test getting a backend."""
backends = service.backends()
backend = service.get_backend(backends[0].name())
backend = service.backend(backends[0].name())
self.assertTrue(backend)


Expand Down