-
Notifications
You must be signed in to change notification settings - Fork 94
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #126 from PKU-NIP-Lab/changes
fix bugs
- Loading branch information
Showing
6 changed files
with
186 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
__version__ = "2.1.2" | ||
__version__ = "2.1.3" | ||
|
||
|
||
try: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,155 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
|
||
import unittest | ||
|
||
import brainpy as bp | ||
import brainpy.math as bm | ||
|
||
|
||
class TestExplicitRKStateDelay(unittest.TestCase): | ||
def test_euler(self): | ||
xdelay = bm.TimeDelay(bm.zeros((1,)), 1., before_t0=-1., interp_method='round') | ||
|
||
@bp.ddeint(method='euler', state_delays={'x': xdelay}) | ||
def equation(x, t, ): | ||
return -xdelay(t - 1) | ||
|
||
runner = bp.integrators.IntegratorRunner(equation, monitors=['x']) | ||
runner.run(20.) | ||
|
||
bp.visualize.line_plot(runner.mon.ts, runner.mon['x'], show=True) | ||
|
||
def test_midpoint(self): | ||
xdelay = bm.TimeDelay(bm.zeros((1,)), 1., before_t0=-1., interp_method='round') | ||
|
||
@bp.ddeint(method='midpoint', state_delays={'x': xdelay}) | ||
def equation(x, t, ): | ||
return -xdelay(t - 1) | ||
|
||
runner = bp.integrators.IntegratorRunner(equation, monitors=['x']) | ||
runner.run(20.) | ||
|
||
bp.visualize.line_plot(runner.mon.ts, runner.mon['x'], show=True) | ||
|
||
def test_heun2(self): | ||
xdelay = bm.TimeDelay(bm.zeros((1,)), 1., before_t0=-1., interp_method='round') | ||
|
||
@bp.ddeint(method='heun2', state_delays={'x': xdelay}) | ||
def equation(x, t, ): | ||
return -xdelay(t - 1) | ||
|
||
runner = bp.integrators.IntegratorRunner(equation, monitors=['x']) | ||
runner.run(20.) | ||
|
||
bp.visualize.line_plot(runner.mon.ts, runner.mon['x'], show=True) | ||
|
||
def test_ralston2(self): | ||
xdelay = bm.TimeDelay(bm.zeros((1,)), 1., before_t0=-1., interp_method='round') | ||
|
||
@bp.ddeint(method='ralston2', state_delays={'x': xdelay}) | ||
def equation(x, t, ): | ||
return -xdelay(t - 1) | ||
|
||
runner = bp.integrators.IntegratorRunner(equation, monitors=['x']) | ||
runner.run(20.) | ||
|
||
bp.visualize.line_plot(runner.mon.ts, runner.mon['x'], show=True) | ||
|
||
def test_rk2(self): | ||
xdelay = bm.TimeDelay(bm.zeros((1,)), 1., before_t0=-1., interp_method='round') | ||
|
||
@bp.ddeint(method='rk2', | ||
state_delays={'x': xdelay}) | ||
def equation(x, t, ): | ||
return -xdelay(t - 1) | ||
|
||
runner = bp.integrators.IntegratorRunner(equation, monitors=['x']) | ||
runner.run(20.) | ||
|
||
bp.visualize.line_plot(runner.mon.ts, runner.mon['x'], show=True) | ||
|
||
def test_rk3(self): | ||
xdelay = bm.TimeDelay(bm.zeros((1,)), 1., before_t0=-1., interp_method='round') | ||
|
||
@bp.ddeint(method='rk3', state_delays={'x': xdelay}) | ||
def equation(x, t, ): | ||
return -xdelay(t - 1) | ||
|
||
runner = bp.integrators.IntegratorRunner(equation, monitors=['x']) | ||
runner.run(20.) | ||
|
||
bp.visualize.line_plot(runner.mon.ts, runner.mon['x'], show=True) | ||
|
||
def test_heun3(self): | ||
xdelay = bm.TimeDelay(bm.zeros((1,)), 1., before_t0=-1., interp_method='round') | ||
|
||
@bp.ddeint(method='heun3', state_delays={'x': xdelay}) | ||
def equation(x, t, ): | ||
return -xdelay(t - 1) | ||
|
||
runner = bp.integrators.IntegratorRunner(equation, monitors=['x']) | ||
runner.run(20.) | ||
|
||
bp.visualize.line_plot(runner.mon.ts, runner.mon['x'], show=True) | ||
|
||
def test_ralston3(self): | ||
xdelay = bm.TimeDelay(bm.zeros((1,)), 1., before_t0=-1., interp_method='round') | ||
|
||
@bp.ddeint(method='ralston3', state_delays={'x': xdelay}) | ||
def equation(x, t, ): | ||
return -xdelay(t - 1) | ||
|
||
runner = bp.integrators.IntegratorRunner(equation, monitors=['x']) | ||
runner.run(20.) | ||
|
||
bp.visualize.line_plot(runner.mon.ts, runner.mon['x'], show=True) | ||
|
||
def test_ssprk3(self): | ||
xdelay = bm.TimeDelay(bm.zeros((1,)), 1., before_t0=-1., interp_method='round') | ||
|
||
@bp.ddeint(method='ssprk3', state_delays={'x': xdelay}) | ||
def equation(x, t, ): | ||
return -xdelay(t - 1) | ||
|
||
runner = bp.integrators.IntegratorRunner(equation, monitors=['x']) | ||
runner.run(20.) | ||
|
||
bp.visualize.line_plot(runner.mon.ts, runner.mon['x'], show=True) | ||
|
||
def test_rk4(self): | ||
xdelay = bm.TimeDelay(bm.zeros((1,)), 1., before_t0=-1., interp_method='round') | ||
|
||
@bp.ddeint(method='rk4', state_delays={'x': xdelay}) | ||
def equation(x, t, ): | ||
return -xdelay(t - 1) | ||
|
||
runner = bp.integrators.IntegratorRunner(equation, monitors=['x']) | ||
runner.run(20.) | ||
|
||
bp.visualize.line_plot(runner.mon.ts, runner.mon['x'], show=True) | ||
|
||
def test_ralston4(self): | ||
xdelay = bm.TimeDelay(bm.zeros((1,)), 1., before_t0=-1., interp_method='round') | ||
|
||
@bp.ddeint(method='ralston4', state_delays={'x': xdelay}) | ||
def equation(x, t, ): | ||
return -xdelay(t - 1) | ||
|
||
runner = bp.integrators.IntegratorRunner(equation, monitors=['x']) | ||
runner.run(20.) | ||
|
||
bp.visualize.line_plot(runner.mon.ts, runner.mon['x'], show=True) | ||
|
||
def test_rk4_38rule(self): | ||
xdelay = bm.TimeDelay(bm.zeros((1,)), 1., before_t0=-1., interp_method='round') | ||
|
||
@bp.ddeint(method='rk4_38rule', state_delays={'x': xdelay}) | ||
def equation(x, t, ): | ||
return -xdelay(t - 1) | ||
|
||
runner = bp.integrators.IntegratorRunner(equation, monitors=['x']) | ||
runner.run(20.) | ||
|
||
bp.visualize.line_plot(runner.mon.ts, runner.mon['x'], show=True) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters