<commit_before>from __future__ import absolute_import, division, print_function, unicode_literals

import desolver as de
@de.rhs_prettifier("""[vx, x]""")
def rhs(t, state, **kwargs):
    x,vx = state

    dx  = vx
    dvx = -x

    return de.numpy.array([dx, dvx])

y_init = de.numpy.array([1., 0.])

a = de.OdeSystem(rhs, y0=y_init, n=y_init.shape, t=(0, 2*de.numpy.pi), stpsz=0.01, rtol=1e-1, atol=1e-3)

a.set_end_time(a.get_end_time())
a.set_step_size(a.get_step_size())
a.set_start_time(a.get_start_time())
a.set_current_time(a.get_current_time())
a.set_method(a.get_method())
# a.set_dimensions(a.get_dimensions())
a.record_trajectory(True)
print(a.get_rtol(), a.get_atol(), a.get_trajectory())
a.show_system()

print("")

with de.BlockTimer(section_label="Integrator Tests") as sttimer:
    for i in de.OdeSystem.available_methods(suppress_print=True):
        print("Testing {}".format(str(i)))
        try:
            a.set_method(i)
            a.integrate()
            max_diff = de.numpy.max(de.numpy.abs(a.get_trajectory()[0] - a.get_trajectory()[-1]).ravel())
            if de.OdeSystem.available_methods(suppress_print=True)[i].__adaptive__:
                assert(max_diff < a.atol * 10)
            print("{} Succeeded with max_diff = {}".format(str(i), max_diff))
            print()
            a.reset()
        except:<commit_msg>Modified test script to cover more of the code branches and available functionality.<commit_after>from __future__ import absolute_import, division, print_function, unicode_literals

import desolver as de

@de.rhs_prettifier("""[vx, x]""")
def rhs(t, state, **kwargs):
    x,vx = state

    dx  = vx
    dvx = -x + t

    return de.numpy.array([dx, dvx])

def analytic_soln(t, initial_conditions):
    c1 =  initial_conditions[0]
    c2 =  initial_conditions[1] - 1.0
    return de.numpy.array([
        c2 * de.numpy.sin(t) + c1 * de.numpy.cos(t) + t,
        c2 * de.numpy.cos(t) - c1 * de.numpy.sin(t) + 1.
    ])

def kbinterrupt_cb(ode_sys):
    if ode_sys.t[-1] > de.numpy.pi:
        raise KeyboardInterrupt("Test Interruption and Catching")

y_init = de.numpy.array([1., 0.])

a = de.OdeSystem(rhs, y0=y_init, n=y_init.shape, eta=True, dense_output=True, t=(0, 2*de.numpy.pi), dt=0.01, rtol=1e-6, atol=1e-12)

a.set_end_time(a.get_end_time())
a.set_step_size(a.get_step_size())
a.set_start_time(a.get_start_time())
a.set_end_time(a.get_end_time())
a.set_method(a.method_name)
a.set_dimensions(a.dim)
print(a.get_rtol(), a.get_atol(), a.y)
a.show_system()

print("")

with de.BlockTimer(section_label="Integrator Tests") as sttimer:
    for i in sorted(de.OdeSystem.available_methods(suppress_print=True)):
        print("Testing {}".format(str(i)))
        try:
            a.set_method(i)
            try:
                a.integrate(callback=kbinterrupt_cb)
            except KeyboardInterrupt as e:
                print("")
                print(e)
                print("")
            a.integrate()

            max_diff = de.numpy.max(de.numpy.abs(analytic_soln(a.t[-1], a.y[0])-a.y[-1]))
            if de.OdeSystem.available_methods(suppress_print=True)[i].__adaptive__:
                assert(max_diff < a.atol * 10)
            print("{} Succeeded with max_diff from analytical solution = {}".format(str(i), max_diff))
            print()
            a.reset()
        except:
{'fraction_non_alphanumeric': 0.1555223880597015, 'fraction_numerical': 0.01373134328358209, 'mean_word_length': 3.081607795371498, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3900614', 'n_tokens_mistral': 1313, 'n_tokens_neox': 1276, 'n_words': 217}