Skip to content

Commit

Permalink
Add unit test for new FPR scheme
Browse files Browse the repository at this point in the history
Add some basic unit tests for the new per-germ global FPR scheme. At the moment this only tests for running to completion. Need to eventually assert correctness. Also adds coverage for new per-germ FPR greedy search heuristics which were added in 0.9.11 but didn't have tests covering them yet.
  • Loading branch information
Corey Ostrove committed Sep 14, 2023
1 parent 6a01133 commit d158976
Showing 1 changed file with 38 additions and 51 deletions.
89 changes: 38 additions & 51 deletions test/unit/algorithms/test_fiducialpairreduction.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import pygsti.algorithms.fiducialpairreduction as fpr
from pygsti.algorithms.germselection import germ_set_spanning_vectors
import pygsti.circuits as pc
from pygsti.circuits import Circuit
import numpy as _np
from . import fixtures
from ..util import BaseCase

Expand Down Expand Up @@ -46,55 +48,6 @@ def setUp(self):
Circuit(('Gx','Gx','Gy','Gx','Gy','Gy')): [(0, 0), (0, 1), (0, 2), (0, 3), (0, 4)]
}


#self.fiducial_pairs_per_germ_old = {
# Circuit(('Gi',)): [(0, 0), (0, 1), (0, 2), (1, 0), (1, 1), (1, 2), (2, 0), (2, 1), (2, 2)],
# Circuit(('Gx',)): [(0, 0), (0, 1), (2, 2)],
# Circuit(('Gy',)): [(0, 0), (0, 2), (1, 4)],
# Circuit(('Gx', 'Gy')): [(0, 0), (0, 1), (1, 3)],
# Circuit(('Gx', 'Gx', 'Gy')): [(0, 0), (0, 1), (0, 2), (1, 0), (1, 4)],
# Circuit(('Gx', 'Gy', 'Gy')): [(0, 0), (0, 1), (0, 2), (2, 0), (2, 2)],
# Circuit(('Gx', 'Gy', 'Gi')): [(0, 0), (0, 1), (1, 3)],
# Circuit(('Gx', 'Gi', 'Gy')): [(0, 0), (0, 1), (1, 3)],
# Circuit(('Gx', 'Gi', 'Gi')): [(0, 0), (0, 1), (2, 2)],
# Circuit(('Gy', 'Gi', 'Gi')): [(0, 0), (0, 2), (1, 4)],
# Circuit(('Gx', 'Gy', 'Gy', 'Gi')): [(0, 0), (0, 1), (0, 2), (2, 0), (2, 2)],
# Circuit(('Gx', 'Gx', 'Gy', 'Gx', 'Gy', 'Gy')): [(0, 0), (0, 1), (1, 3)]
#}

#self.fiducial_pairs_per_germ_old1 = {
# Circuit(('Gi',)): [(0, 0), (1, 1), (2, 2)],
# Circuit(('Gx',)): [(0, 0), (0, 1), (0, 2), (2, 2)],
# Circuit(('Gy',)): [(0, 0), (0, 1), (0, 2), (1, 1)],
# Circuit(('Gx', 'Gy')): [(0, 0), (0, 1), (0, 2), (2, 0)],
# Circuit(('Gx', 'Gx', 'Gy')): [(0, 0), (0, 1), (0, 2), (1, 0), (1, 1), (1, 2)],
# Circuit(('Gx', 'Gy', 'Gy')): [(0, 0), (0, 1), (0, 2), (2, 0), (2, 1), (2, 2)],
# Circuit(('Gx', 'Gy', 'Gi')): [(0, 0), (0, 1), (0, 2), (2, 0)],
# Circuit(('Gx', 'Gi', 'Gy')): [(0, 0), (0, 1), (0, 2), (2, 0)],
# Circuit(('Gx', 'Gi', 'Gi')): [(0, 0), (0, 1), (0, 2), (2, 2)],
# Circuit(('Gy', 'Gi', 'Gi')): [(0, 0), (0, 1), (0, 2), (1, 1)],
# Circuit(('Gx', 'Gy', 'Gy', 'Gi')): [(0, 0), (0, 1), (0, 2), (2, 0), (2, 1), (2, 2)],
# Circuit(('Gx', 'Gx', 'Gy', 'Gx', 'Gy', 'Gy')): [(0, 0), (0, 1), (0, 2), (1, 0)]
#}
#
##I think this alternate set is due to a slightly different search ordering - it
## still looks like a correct output (there are many), so we'll call this OK for now:
#self.fiducial_pairs_per_germ_old2 = {
# Circuit(('Gi',)): [(0, 0), (1, 1), (2, 2)],
# Circuit(('Gx',)): [(0, 0), (0, 1), (0, 2), (2, 0)], # 2,2 => 2,0
# Circuit(('Gy',)): [(0, 0), (0, 1), (0, 2), (1, 0)], # 1,1 => 1,0
# Circuit(('Gx', 'Gy')): [(0, 0), (0, 1), (0, 2), (2, 0)],
# Circuit(('Gx', 'Gx', 'Gy')): [(0, 0), (0, 1), (0, 2), (1, 0), (1, 1), (1, 2)],
# Circuit(('Gx', 'Gy', 'Gy')): [(0, 0), (0, 1), (0, 2), (2, 0), (2, 1), (2, 2)],
# Circuit(('Gx', 'Gy', 'Gi')): [(0, 0), (0, 1), (0, 2), (2, 0)],
# Circuit(('Gx', 'Gi', 'Gy')): [(0, 0), (0, 1), (0, 2), (2, 0)],
# Circuit(('Gx', 'Gi', 'Gi')): [(0, 0), (0, 1), (0, 2), (2, 0)], # 2,2 => 2,0
# Circuit(('Gy', 'Gi', 'Gi')): [(0, 0), (0, 1), (0, 2), (1, 0)], # 1,1 => 1,0
# Circuit(('Gx', 'Gy', 'Gy', 'Gi')): [(0, 0), (0, 1), (0, 2), (2, 0), (2, 1), (2, 2)],
# Circuit(('Gx', 'Gx', 'Gy', 'Gx', 'Gy', 'Gy')): [(0, 0), (0, 1), (0, 2), (1, 0)]
#}


class FiducialPairReductionSmallData(FiducialPairReductionStdData):
def setUp(self):
super(FiducialPairReductionSmallData, self).setUp()
Expand Down Expand Up @@ -129,9 +82,8 @@ def test_find_sufficient_fiducial_pairs_per_germ_sequential(self):
search_mode='sequential', retry_for_smaller=False,
min_iterations=1, verbosity=0
)
print("Found per-germ pairs:\n", fiducial_pairs)
#print("Found per-germ pairs:\n", fiducial_pairs)
self.assertTrue((fiducial_pairs == self.fiducial_pairs_per_germ) or (fiducial_pairs == self.fiducial_pairs_per_germ_windows_38))
# or fiducial_pairs == self.fiducial_pairs_per_germ_alt)

def test_find_sufficient_fiducial_pairs_per_germ_random(self):
fiducial_pairs = fpr.find_sufficient_fiducial_pairs_per_germ(
Expand All @@ -141,6 +93,41 @@ def test_find_sufficient_fiducial_pairs_per_germ_random(self):
# TODO assert correctness


class FindSufficientFiducialPairsPerGermGreedy(object):
def test_find_sufficient_fiducial_pairs_per_germ_greedy_random(self):
fiducial_pairs = fpr.find_sufficient_fiducial_pairs_per_germ_greedy(
self.model, self.preps, self.effects, self.germs,
initial_seed_mode='random', seed=_SEED, check_complete_fid_set=False)
#TODO assert correctness


def test_find_sufficient_fiducial_pairs_per_germ_greedy_greedy(self):
fiducial_pairs = fpr.find_sufficient_fiducial_pairs_per_germ_greedy(
self.model, self.preps, self.effects, self.germs,
initial_seed_mode='greedy', seed=_SEED, check_complete_fid_set=False)
#TODO assert correctness

class FindSufficientFiducialPairsPerGermGlobal(object):

def test_germ_set_spanning_vectors_greedy(self):
spanning_vec_set = germ_set_spanning_vectors(self.model, self.germs,
assume_real=True, float_type=_np.double,
verbosity=0, mode = 'greedy', final_test = True)

#TODO assert correctness

def test_germ_set_spanning_vectors_rrqr(self):
spanning_vec_set = germ_set_spanning_vectors(self.model, self.germs,
assume_real=True, float_type=_np.double,
verbosity=0, mode = 'rrqr', final_test = True)


def test_find_sufficient_fiducial_pairs_per_germ_global(self):
fiducial_pairs = fpr.find_sufficient_fiducial_pairs_per_germ_global(
self.model, self.preps, self.effects, germs= self.germs,
initial_seed_mode='greedy')
#TODO assert correctness

class StdDataFindSufficientFiducialPairsTester(FindSufficientFiducialPairsBase,
FindSufficientFiducialPairsPerGermBase,
FiducialPairReductionStdData,
Expand Down

0 comments on commit d158976

Please sign in to comment.