Commit 0f74839a authored by theos's avatar theos
Browse files

Implemented DiagonalProber.

parent 4940efce
# -*- coding: utf-8 -*-
from nifty.operators import EndomorphicOperator
from operator_prober import OperatorProber
class DiagonalProber(OperatorProber):
# ---Mandatory properties and methods---
# --- ->Mandatory from OperatorProber---
@property
def is_inverse(self):
return False
@property
def valid_operator_class(self):
return EndomorphicOperator
# --- ->Mandatory from Prober---
def evaluate_probe(self, probe):
""" processes a probe """
return self.operator.times(probe[1])
def finish_probe(self, probe, pre_result):
return probe[1].conjugate()*pre_result
......@@ -2,6 +2,8 @@
import abc
from nifty.config import about
from prober import Prober
......@@ -17,6 +19,10 @@ class OperatorProber(Prober):
distribution_strategy=distribution_strategy,
compute_variance=compute_variance)
if not isinstance(operator, self.valid_operator_class):
raise TypeError(about._errors.cstring(
"WARNING: operator must be an instance of %s" %
str(self.valid_operator_class)))
self._operator = operator
# ---Mandatory properties and methods---
......
......@@ -67,7 +67,7 @@ class Prober(object):
def random_type(self, random_type):
if random_type not in ["pm1", "normal"]:
raise ValueError(about._errors.cstring(
"ERROR: unsupported random type: '" + str(random) + "'."))
"ERROR: unsupported random type: '" + str(random_type) + "'."))
else:
self._random_type = random_type
......@@ -81,7 +81,7 @@ class Prober(object):
for index in xrange(self.probe_count):
current_probe = self.get_probe(index)
pre_result = self.process_probe(current_probe, index)
result = self.finish_probe(pre_result)
result = self.finish_probe(current_probe, pre_result)
sum_of_probes += result
if self.compute_variance:
......@@ -111,8 +111,9 @@ class Prober(object):
""" processes a probe """
raise NotImplementedError
def finish_probe(self, probe):
return probe
@abc.abstractmethod
def finish_probe(self, probe, pre_result):
return pre_result
def finalize(self, sum_of_probes, sum_of_squares):
probe_count = self.probe_count
......
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