# This code is part of Qiskit.
#
# (C) Copyright IBM 2020.
#
# 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.

"""
This module implements the abstract base class for algorithm results.
"""

from abc import ABC
import inspect
from collections import OrderedDict
import pprint


class AlgorithmResult(ABC):
    """ Abstract Base Class for algorithm results."""

    def __str__(self) -> str:
        result = OrderedDict()
        for name, value in inspect.getmembers(self):
            if not name.startswith('_') and \
                    not inspect.ismethod(value) and not inspect.isfunction(value) and \
                    hasattr(self, name):

                result[name] = value

        return pprint.pformat(result, indent=4)

    def combine(self, result: 'AlgorithmResult') -> None:
        """
        Any property from the argument that exists in the receiver is
        updated.
        Args:
            result: Argument result with properties to be set.
        Raises:
            TypeError: Argument is None
        """
        if result is None:
            raise TypeError('Argument result expected.')
        if result == self:
            return

        # find any result public property that exists in the receiver
        for name, value in inspect.getmembers(result):
            if not name.startswith('_') and \
                    not inspect.ismethod(value) and not inspect.isfunction(value) and \
                    hasattr(self, name):
                setattr(self, name, value)

@@ -50,16 +50,22 @@
 IBM 2020
+, 2021
 .%0A#%0A# Th
@@ -595,44 +595,8 @@
 ect%0A
-from collections import OrderedDict%0A
 impo
@@ -741,21 +741,10 @@
 t = 
-OrderedDict()
+%7B%7D
 %0A   
@@ -1789,16 +1789,41 @@
  name):%0A
+                try:%0A    
         
@@ -1857,8 +1857,127 @@
  value)%0A
+                except AttributeError:%0A                    # some attributes may be read only%0A                    pass%0A

Improve AlgorithmResult string representation and combine (#6181)