• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

WassimTenachi / PhySO / #13

10 Jun 2024 12:28AM UTC coverage: 52.052% (-30.3%) from 82.385%
#13

push

coveralls-python

WassimTenachi
Update requirements.txt

2980 of 5725 relevant lines covered (52.05%)

0.52 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

32.5
/physo/task/tests/sr_UnitTest.py
1
import numpy as np
1✔
2
import matplotlib.pyplot as plt
1✔
3
import torch
1✔
4
import warnings
×
5
# Internal code import
6
import physo
1✔
7
import physo.learn.monitoring as monitoring
×
8

9
import unittest
×
10

11
class Test_SR(unittest.TestCase):
1✔
12
    def test_SR_task(self):
×
13

14
        run_logger = lambda : monitoring.RunLogger(
1✔
15
                                      save_path = 'SR.log',
16
                                      do_save   = False)
17
        run_visualiser = lambda : monitoring.RunVisualiser (
1✔
18
                                      epoch_refresh_rate = 1,
19
                                      save_path = 'SR_curves.png',
20
                                      do_show   = False,
21
                                      do_prints = True,
22
                                      do_save   = False, )
23

24
        # Seed
25
        seed = 0
×
26
        np.random.seed(seed)
×
27
        torch.manual_seed(seed)
1✔
28

29
        # Dataset
30
        z = np.random.uniform(-10, 10, 50)
1✔
31
        v = np.random.uniform(-10, 10, 50)
×
32
        X = np.stack((z, v), axis=0)
×
33
        y = 1.234*9.807*z + 1.234*v**2
1✔
34

35
        # Running SR task
36
        expression, logs = physo.SR(X, y,
1✔
37
                                    # Giving names of variables (for display purposes)
38
                                    X_names = [ "z"       , "v"        ],
39
                                    # Giving units of input variables
40
                                    X_units = [ [1, 0, 0] , [1, -1, 0] ],
41
                                    # Giving name of root variable (for display purposes)
42
                                    y_name  = "E",
43
                                    # Giving units of the root variable
44
                                    y_units = [2, -2, 1],
45
                                    # Fixed constants
46
                                    fixed_consts       = [ 1.      ],
47
                                    # Units of fixed constants
48
                                    fixed_consts_units = [ [0,0,0] ],
49
                                    # Free constants names (for display purposes)
50
                                    free_consts_names = [ "m"       , "g"        ],
51
                                    # Units of free constants
52
                                    free_consts_units = [ [0, 0, 1] , [1, -2, 0] ],
53
                                    # Run config
54
                                    run_config = physo.config.config0.config0,
55

56
                                    # FOR TESTING
57
                                    get_run_logger     = run_logger,
58
                                    get_run_visualiser = run_visualiser,
59
                                    parallel_mode=False,
60
                                    epochs = 5,
61
        )
62

63
        # Inspecting pareto front expressions
64
        pareto_front_complexities, pareto_front_expressions, pareto_front_r, pareto_front_rmse = logs.get_pareto_front()
1✔
65

66
        # Assert that solution expression was found
67
        assert pareto_front_r.max() > 0.9999, "Solution expression was not found."
1✔
68

69

70
        return None
×
71

72
    # Testing that SR task runs with few operators (ie. operators mentioned in default priors missing)
73
    def test_prior_not_in_op_names (self):
×
74

75
        run_logger = lambda : monitoring.RunLogger(
×
76
                                      save_path = 'SR.log',
77
                                      do_save   = False)
78
        run_visualiser = lambda : monitoring.RunVisualiser (
×
79
                                      epoch_refresh_rate = 1,
80
                                      save_path = 'SR_curves.png',
81
                                      do_show   = False,
82
                                      do_prints = True,
83
                                      do_save   = False, )
84

85
        # Seed
86
        seed = 0
×
87
        np.random.seed(seed)
×
88
        torch.manual_seed(seed)
×
89

90
        # Dataset
91
        z = np.random.uniform(-10, 10, 50)
×
92
        v = np.random.uniform(-10, 10, 50)
×
93
        X = np.stack((z, v), axis=0)
×
94
        y = 1.234*9.807*z + 1.234*v**2
×
95

96
        # Running SR task
97
        # Avoiding expected warnings caused by priors referring to operators not in op_names
98
        # We still want to keep those priors for the sake of this test
99
        with warnings.catch_warnings():
×
100
            warnings.simplefilter("ignore")
×
101
            expression, logs = physo.SR(X, y,
×
102
                                        X_names = [ "z"       , "v"        ],
103
                                        X_units = [ [1, 0, 0] , [1, -1, 0] ],
104
                                        y_name  = "E",
105
                                        y_units = [2, -2, 1],
106
                                        fixed_consts       = [ 1.      ],
107
                                        fixed_consts_units = [ [0,0,0] ],
108
                                        free_consts_names = [ "m"       , "g"        ],
109
                                        free_consts_units = [ [0, 0, 1] , [1, -2, 0] ],
110
                                        op_names = ["mul", "add", "sub", "div"],
111
                                        # Run config
112
                                        run_config = physo.config.config0.config0,
113
                                        # FOR TESTING
114
                                        get_run_logger     = run_logger,
115
                                        get_run_visualiser = run_visualiser,
116
                                        parallel_mode = False,
117
                                        epochs = 5,
118
            )
119
        # Inspecting pareto front expressions
120
        pareto_front_complexities, pareto_front_expressions, pareto_front_r, pareto_front_rmse = logs.get_pareto_front()
×
121

122
        # Assert that solution expression was found
123
        assert pareto_front_r.max() > 0.9999, "Solution expression was not found."
×
124

125
        return None
×
126

127
if __name__ == '__main__':
×
128
    unittest.main()
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc