-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTest.cpp
More file actions
75 lines (61 loc) · 1.92 KB
/
Copy pathTest.cpp
File metadata and controls
75 lines (61 loc) · 1.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#include "Agent.h"
#include "Environment.h"
#include <iostream>
#include <cstdlib>
#include <cuda_runtime.h>
#include <filesystem>
#include <ctime>
#include "Modes.h"
using std::cout, std::endl;
void test(std::string load_path) {
// check if load_path exists
if (!std::filesystem::exists(load_path)) {
cout << "Load path does not exist!" << endl;
return;
}
cudaSetDevice(0);
srand(time(nullptr));
int seed = rand() % 100000;
cout << "Setting seed to " << seed << endl;
srand(seed);
torch::manual_seed(seed);
EnvConfig envConfig{
.width = 800,
.height = 600,
.bounds = 50.0f,
.ballDensity = 1.0f,
.numSubsteps = 5,
.manualControl = false,
.headless = false,
.maxSteps = 256, // 1024
.threshold = 0.1f,
.bonusAchievedReward = 1.0f,
.num_envs = 12,
.actionPenalty = 0.001f,
};
AgentConfig agentConfig{
.num_epochs = 1000,
.horizon_length = 256,
.mini_batch_size = 8192,
.mini_epochs = 8,
.learning_rate = 1e-4,
.clip_param = 0.2,
.value_loss_coef = 0.5,
.bound_loss_coef = 0.0001,
.gamma = 0.99,
.tau = 0.95,
.reward_multiplier = 1.0,
};
Environment environment(envConfig);
environment.Reset();
// load_path contains 'weights' so we need to remove it to get the log_path
std::string log_path = load_path.substr(0, load_path.find_last_of('/') - 8) + "_test/";
// create the missing folders
std::filesystem::create_directory(log_path);
std::filesystem::create_directory(log_path + "summaries");
std::filesystem::create_directory(log_path + "weights");
Agent agent = Agent(agentConfig, &environment, log_path);
agent.Test(load_path);
// Clean up
environment.CleanUp();
}