Skip to content
This repository has been archived by the owner on Jul 24, 2024. It is now read-only.

Commit

Permalink
Fixed bug in deepcopy of IBMBackend (#658)
Browse files Browse the repository at this point in the history
* Fixed recursion in deepcopy of IBMBackend.

* Release note

---------

Co-authored-by: Kevin Tian <kevin.tian@ibm.com>
  • Loading branch information
merav-aharoni and kt474 authored Jun 8, 2023
1 parent d0a39b2 commit 38fa725
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
2 changes: 1 addition & 1 deletion qiskit_ibm_provider/ibm_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ def __getattr__(self, name: str) -> Any:
does not yet exist on IBMBackend class.
"""
# Prevent recursion since these properties are accessed within __getattr__
if name in ["_properties", "_defaults", "_target"]:
if name in ["_properties", "_defaults", "_target", "_configuration"]:
raise AttributeError(
"'{}' object has no attribute '{}'".format(
self.__class__.__name__, name
Expand Down
5 changes: 5 additions & 0 deletions releasenotes/notes/backend_deepcopy-032282246b52e391.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
fixes:
- |
Fixed infinite recursion when attempting to deepcopy an IBMBackend.
8 changes: 7 additions & 1 deletion test/unit/test_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
# that they have been altered from the originals.

"""Tests for the backend functions."""

import copy
from datetime import datetime
from unittest import mock
import warnings
Expand Down Expand Up @@ -318,3 +318,9 @@ def test_multi_openqasm3_submission(self):
backend.run(circuits=qasm3_circs, dynamic=True)

mock_run.assert_called_once()

def test_deepcopy(self):
"""Test that deepcopy of a backend works properly"""
backend = self._create_dc_test_backend()
backend_copy = copy.deepcopy(backend)
self.assertEqual(backend_copy.name, backend.name)

0 comments on commit 38fa725

Please sign in to comment.