Skip to content

Commit

Permalink
CI Fix (#138)
Browse files Browse the repository at this point in the history
  • Loading branch information
cpnota committed May 6, 2020
1 parent 68d355a commit e7d668e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 11 deletions.
4 changes: 2 additions & 2 deletions all/approximation/v_network_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ def test_multi_reinforce(self):
mask=torch.tensor([1, 1, 0, 1, 0, 0])
)
result1 = self.v(states[0:2])
result2 = self.v(states[2:4])
result3 = self.v(states[4:6])
self.v.reinforce(loss(result1, torch.tensor([1, 2])).float())
result2 = self.v(states[2:4])
self.v.reinforce(loss(result2, torch.tensor([1, 1])).float())
result3 = self.v(states[4:6])
self.v.reinforce(loss(result3, torch.tensor([1, 2])).float())
with self.assertRaises(Exception):
self.v.reinforce(loss(result3, torch.tensor([1, 2])).float())
Expand Down
14 changes: 5 additions & 9 deletions all/policies/deterministic_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,28 +57,24 @@ def test_target(self):
self.space,
target=FixedTarget(3)
)

# choose initial action
state = State(torch.ones(1, STATE_DIM))
action = self.policy(state)
tt.assert_equal(action, torch.zeros(1, ACTION_DIM))

# run update step, make sure target network doesn't change
action.sum().backward(retain_graph=True)
self.policy(state).sum().backward()
self.policy.step()
tt.assert_equal(self.policy.target(state), torch.zeros(1, ACTION_DIM))

# again...
action.sum().backward(retain_graph=True)
self.policy(state).sum().backward()
self.policy.step()
tt.assert_equal(self.policy.target(state), torch.zeros(1, ACTION_DIM))

# third time, target should be updated
action.sum().backward(retain_graph=True)
self.policy(state).sum().backward()
self.policy.step()
tt.assert_allclose(
self.policy.eval(state),
torch.tensor([[-0.595883, -0.595883, -0.595883]]),
self.policy.target(state),
torch.tensor([[-0.574482, -0.574482, -0.574482]]),
atol=1e-4,
)

Expand Down

0 comments on commit e7d668e

Please sign in to comment.