Exemple #1
0
    def test_ye_ratio(self):
        # TODO: use ye curve from examples ?
        good_proto = Proto(dim=2, div=5, cubes=[
            (0, 0), (0, 1), (1, 1), (1, 0), (2, 0),
            (2, 1), (2, 2), (1, 2), (0, 2), (0, 3),
            (0, 4), (1, 4), (1, 3), (2, 3), (2, 4),
            (3, 4), (4, 4), (4, 3), (3, 3), (3, 2),
            (4, 2), (4, 1), (3, 1), (3, 0), (4, 0),
        ])
        # in new version we have (0,0)->(0,1) gate
        good_proto = BaseMap.parse('ji') * good_proto

        paths_gen = PathsGenerator(dim=2, div=5, hdist=1, max_cdist=1)
        for paths in paths_gen.generate_paths():
            if paths[0].proto == good_proto:
                path0 = paths[0]
                break

        path0 = CurvePath(path0.proto, path0.portals)  # legacy
        pcurve = PathFuzzyCurve.init_from_paths([path0])
        estimator = Estimator(utils.ratio_l2_squared)
        curve = estimator.estimate_ratio(pcurve, rel_tol_inv=10000, verbose=False)['curve']
        ratio = estimator.estimate_ratio(curve, rel_tol_inv=10000, use_vertex_brkline=True, verbose=False, max_depth=5)

        assert ratio['lo'] == (Rational(408, 73) ** 2)
Exemple #2
0
    def test_55_ratio(self):
        good_proto = Proto(dim=2,
                           div=5,
                           cubes=[
                               (0, 0),
                               (0, 1),
                               (1, 1),
                               (1, 0),
                               (2, 0),
                               (2, 1),
                               (2, 2),
                               (1, 2),
                               (0, 2),
                               (0, 3),
                               (0, 4),
                               (1, 4),
                               (1, 3),
                               (2, 3),
                               (2, 4),
                               (3, 4),
                               (4, 4),
                               (4, 3),
                               (3, 3),
                               (3, 2),
                               (4, 2),
                               (4, 1),
                               (3, 1),
                               (3, 0),
                               (4, 0),
                           ])
        # in new version we have (0,0)->(0,1) gate
        good_proto = BaseMap.from_basis('ji') * good_proto

        paths_gen = PathsGenerator(dim=2,
                                   div=5,
                                   hdist=1,
                                   max_cdist=1,
                                   verbose=1)
        for paths in paths_gen.generate_paths():
            if paths[0].proto == good_proto:
                path0 = paths[0]
                break

        pcurve = PathFuzzyCurve.init_from_paths([path0])
        estimator = Estimator(utils.ratio_l2_squared)
        curve = estimator.estimate_ratio(pcurve,
                                         rel_tol_inv=10000,
                                         verbose=False)['curve']
        ratio = estimator.estimate_ratio(curve,
                                         rel_tol_inv=10000,
                                         use_vertex_brkline=True,
                                         verbose=False)

        assert ratio['lo'] == (FastFraction(408, 73)**2)