LuchnikovI / QGOpt

Riemannian optimization for quantum technologies
Apache License 2.0
56 stars 6 forks source link

Some childs of class Manifold(ABC) do not invoke super constructor #27

Open user-vi opened 4 years ago

user-vi commented 4 years ago

While in StiefelManifold super constructor is used, in some other childs there is no super(). It leads to emptiness of properties of super class(retraction, metric).

from QGOpt/manifolds/stiefel.py from class StiefelManifold method __init__ :

    def __init__(self, retraction='svd',
                 metric='euclidean'):

        self.rank = 2
        list_of_metrics = ['euclidean', 'canonical']
        list_of_retractions = ['svd', 'cayley', 'qr']

        if metric not in list_of_metrics:
            raise ValueError("Incorrect metric")
        if retraction not in list_of_retractions:
            raise ValueError("Incorrect retraction")

        super(StiefelManifold, self).__init__(retraction, metric)

and it has super invocation:

        super(StiefelManifold, self).__init__(retraction, metric)

but in QGOpt/manifolds/hermitian.py in class HermitianMatrix there is no super invocation:

    def __init__(self, metric='euclidean'):

        self.rank = 2
        list_of_metrics = ['euclidean']

        if metric not in list_of_metrics:
            raise ValueError("Incorrect metric")

Checking emptiness of properties of super class

if add to QGOpt/manifolds/base_manifold.py this method

    @property
    def get_metric(self):
        return self._metric

and then execute these tests:

def test_StiefelManifold():
    assert 'euclidean' == manifolds.HermitianMatrix(metric='euclidean').get_metric
def test_StiefelManifold():
    assert 'euclidean' == manifolds.StiefelManifold(metric='euclidean').get_metric

We see that test_StiefelManifold() throws error: E AttributeError: 'HermitianMatrix' object has no attribute '_metric'

but test_StiefelManifold() does not throw any error