MCPcopy Create free account
hub / github.com/rtqichen/torchdiffeq / simulate

Method simulate

examples/bouncing_ball.py:73–100  ·  view source on GitHub ↗
(self, nbounces=1)

Source from the content-addressed store, hash-verified

71 return event_times
72
73 def simulate(self, nbounces=1):
74 event_times = self.get_collision_times(nbounces)
75
76 # get dense path
77 t0, state = self.get_initial_state()
78 trajectory = [state[0][None]]
79 velocity = [state[1][None]]
80 times = [t0.reshape(-1)]
81 for event_t in event_times:
82 tt = torch.linspace(
83 float(t0), float(event_t), int((float(event_t) - float(t0)) * 50)
84 )[1:-1]
85 tt = torch.cat([t0.reshape(-1), tt, event_t.reshape(-1)])
86 solution = odeint(self, state, tt, atol=1e-8, rtol=1e-8)
87
88 trajectory.append(solution[0][1:])
89 velocity.append(solution[1][1:])
90 times.append(tt[1:])
91
92 state = self.state_update(tuple(s[-1] for s in solution))
93 t0 = event_t
94
95 return (
96 torch.cat(times),
97 torch.cat(trajectory, dim=0).reshape(-1),
98 torch.cat(velocity, dim=0).reshape(-1),
99 event_times,
100 )
101
102
103def gradcheck(nbounces):

Callers 1

bouncing_ball.pyFile · 0.45

Calls 4

get_collision_timesMethod · 0.95
get_initial_stateMethod · 0.95
state_updateMethod · 0.95
odeintFunction · 0.90

Tested by

no test coverage detected