Commit 02647cdc authored by Theo Steininger's avatar Theo Steininger
Browse files

Optimized set_diagonal in DiagonalOperator.

parent cf834a3e
Pipeline #10198 passed with stages
in 16 minutes and 5 seconds
...@@ -90,7 +90,7 @@ class Field(Loggable, Versionable, object): ...@@ -90,7 +90,7 @@ class Field(Loggable, Versionable, object):
elif isinstance(val, Field): elif isinstance(val, Field):
distribution_strategy = val.distribution_strategy distribution_strategy = val.distribution_strategy
else: else:
self.logger.info("Datamodel set to default!") self.logger.debug("Datamodel set to default!")
distribution_strategy = gc['default_distribution_strategy'] distribution_strategy = gc['default_distribution_strategy']
elif distribution_strategy not in DISTRIBUTION_STRATEGIES['global']: elif distribution_strategy not in DISTRIBUTION_STRATEGIES['global']:
raise ValueError( raise ValueError(
......
...@@ -90,10 +90,15 @@ class DiagonalOperator(EndomorphicOperator): ...@@ -90,10 +90,15 @@ class DiagonalOperator(EndomorphicOperator):
@property @property
def symmetric(self): def symmetric(self):
if self._symmetric is None:
self._symmetric = (self._diagonal.val.imag == 0).all()
return self._symmetric return self._symmetric
@property @property
def unitary(self): def unitary(self):
if self._unitary is None:
self._unitary = (self._diagonal.val *
self._diagonal.val.conjugate() == 1).all()
return self._unitary return self._unitary
# ---Added properties and methods--- # ---Added properties and methods---
...@@ -134,11 +139,11 @@ class DiagonalOperator(EndomorphicOperator): ...@@ -134,11 +139,11 @@ class DiagonalOperator(EndomorphicOperator):
# Otherwise, inplace weightening would change the external field # Otherwise, inplace weightening would change the external field
f.weight(inplace=copy, power=-1) f.weight(inplace=copy, power=-1)
# check if the operator is symmetric: # Reset the symmetric property:
self._symmetric = (f.val.imag == 0).all() self._symmetric = None
# check if the operator is unitary: # Reset the unitarity property
self._unitary = (f.val * f.val.conjugate() == 1).all() self._unitary = None
# store the diagonal-field # store the diagonal-field
self._diagonal = f self._diagonal = f
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment