mabuchilab / QNET

Computer algebra package for quantum mechanics and photonic quantum networks
https://qnet.readthedocs.io/
MIT License
71 stars 23 forks source link

Substitute on expression with Singletons crashes #49

Closed goerz closed 7 years ago

goerz commented 7 years ago

Calling the substitute method on any Singleton object should always return the same object. E.g. for the IdentityOperator (II), we would like

assert II.substitute({}) is II

However, since II._class is not II, the call to substitute fails:

self = IdentityOperator, var_map = {}

    def _substitute(self, var_map):
        if self in var_map:
            return var_map[self]
        #if isinstance(self.__class__, Singleton):
            #return self
        new_args = [substitute(arg, var_map) for arg in self.args]
        new_kwargs = {key: substitute(val, var_map)
                    for (key, val) in self.kwargs.items()}
>       return self.__class__.create(*new_args, **new_kwargs)
E       TypeError: create() missing 1 required positional argument: 'self'

qnet/algebra/abstract_algebra.py:280: TypeError