clean up for metric implementation

This commit is contained in:
Niko Feith 2023-05-30 15:55:00 +02:00
parent 5c28ceab9d
commit 3132214a36
3 changed files with 49 additions and 137 deletions

View File

@ -39,7 +39,6 @@
:min="10"
:max="200"
thumb-label
:disabled="episodeRef"
/>
<v-slider
class="control-slider"
@ -49,13 +48,11 @@
:min="1"
:max="50"
thumb-label
:disabled="runRef"
/>
<v-select
:items="acq_funs"
label="Acquisition Function"
v-model="acqSelector"
:disabled="acqRef"
></v-select>
<v-slider
class="control-slider"
@ -65,7 +62,6 @@
:min="0"
:max="1"
thumb-label
:disabled="epsilonRef"
/>
<v-checkbox v-model="cstore.fixed_seed" label="fixed seed" />
<v-row class="d-flex justify-space-evenly mb-1">
@ -81,7 +77,7 @@
<script setup>
import { usePStore } from "@/store/PolicyStore";
import { useCStore } from "@/store/ControlStore";
import { computed, watch, ref } from "vue";
import { computed } from "vue";
const pstore = usePStore();
const cstore = useCStore();
@ -90,11 +86,6 @@ const envs = cstore.envs;
const metrics = cstore.metircs;
const acq_funs = cstore.acq_funs;
const episodeRef = ref(true);
const runRef = ref(true);
const acqRef = ref(true);
const epsilonRef = ref(true);
const maxStepComp = computed({
get: () => pstore.max_steps,
set: (value) => pstore.setMaxSteps(value),
@ -119,32 +110,6 @@ const acqSelector = computed({
get: () => cstore.acq_fun,
set: (value) => cstore.setAcq(value),
});
watch(
() => cstore.getMetric,
() => {
const usrMode = cstore.getMetric;
if (usrMode === "manually") {
episodeRef.value = true;
runRef.value = true;
acqRef.value = true;
epsilonRef.value = true;
}
if (usrMode === "BO") {
episodeRef.value = false;
runRef.value = false;
acqRef.value = false;
epsilonRef.value = true;
}
if (usrMode === "active BO") {
episodeRef.value = false;
runRef.value = false;
acqRef.value = false;
epsilonRef.value = false;
}
}
);
</script>
<style scoped>

View File

@ -140,25 +140,21 @@ const active_rl_eval_pub = new ROS.Topic({
watch(
() => cstore.getSendWeights,
() => {
const metric = cstore.getMetric;
if (metric === "active BO") {
if (!pendingRequest.value) {
return;
}
console.log("Button pressed!");
const active_eval_response = new ROS.Message({
policy: pstore.policy,
weights: pstore.weights,
});
console.log(active_eval_response);
active_rl_eval_pub.publish(active_eval_response);
// await sleep(1000);
console.log("New Policy/ Weights published");
pendingRequest.value = false;
if (!pendingRequest.value) {
return;
}
console.log("Button pressed!");
const active_eval_response = new ROS.Message({
policy: pstore.policy,
weights: pstore.weights,
});
console.log(active_eval_response);
active_rl_eval_pub.publish(active_eval_response);
// await sleep(1000);
console.log("New Policy/ Weights published");
pendingRequest.value = false;
}
);
@ -168,11 +164,11 @@ const rl_service = new ROS.Service({
serviceType: "active_bo_msgs/srv/RLRollOut",
});
const bo_service = new ROS.Service({
ros: ros,
name: "/bo_srv",
serviceType: "active_bo_msgs/srv/BO",
});
// const bo_service = new ROS.Service({
// ros: ros,
// name: "/bo_srv",
// serviceType: "active_bo_msgs/srv/BO",
// });
const active_bo_pending = ref(false);
@ -199,83 +195,34 @@ active_bo_response.subscribe((msg) => {
watch(
() => cstore.getRunner,
() => {
const usr_mode = cstore.getMetric;
const request_msg = new ROS.Message({
env: cstore.env,
metric: cstore.metric,
fixed_seed: cstore.fixed_seed,
nr_weights: pstore.nr_weights,
max_steps: pstore.max_steps,
nr_episodes: cstore.nr_episodes,
nr_runs: cstore.nr_runs,
acquisition_function: cstore.acq_fun,
metric_parameter: cstore.metric_parameter,
});
active_bo_pending.value = true;
active_bo_request.publish(request_msg);
}
);
if (usr_mode === "manually") {
const rl_request = new ROS.ServiceRequest({
env: cstore.env,
policy: pstore.policy,
});
rl_service.callService(rl_request, function (rl_response) {
rstore.addMeanManually(rl_response.reward);
});
} else if (usr_mode === "BO") {
const bo_request = new ROS.ServiceRequest({
nr_weights: pstore.nr_weights,
max_steps: pstore.max_steps,
nr_episodes: cstore.nr_episodes,
nr_runs: cstore.nr_runs,
acquisition_function: cstore.acq_fun,
});
bo_service.callService(bo_request, function (bo_response) {
pstore.setPolicy(bo_response.best_policy);
pstore.setWeights(bo_response.best_weights);
rstore.setMean(bo_response.reward_mean);
rstore.setStd(bo_response.reward_std);
});
const rl_request = new ROS.ServiceRequest({
env: cstore.env,
policy: pstore.policy,
});
rl_service.callService(rl_request, () => {});
} else if (usr_mode === "active BO" && !active_bo_pending.value) {
const request_msg = new ROS.Message({
env: cstore.env,
fixed_seed: cstore.fixed_seed,
nr_weights: pstore.nr_weights,
max_steps: pstore.max_steps,
nr_episodes: cstore.nr_episodes,
nr_runs: cstore.nr_runs,
acquisition_function: cstore.acq_fun,
metric_parameter: cstore.metric_parameter,
});
active_bo_request.publish(request_msg);
const rl_request = new ROS.ServiceRequest({
env: cstore.env,
policy: pstore.policy,
});
rl_service.callService(rl_request, () => {});
active_bo_pending.value = true;
// const active_bo_request = new ROSLIB.ServiceRequest({
// nr_weights: pstore.nr_weights,
// max_steps: pstore.max_steps,
// nr_episodes: cstore.nr_episodes,
// nr_runs: cstore.nr_runs,
// acquisition_function: cstore.acq_fun,
// epsilon: cstore.epsilon,
// });
//
// active_bo_service.callService(
// active_bo_request,
// function (active_bo_response) {
// pstore.setPolicy(active_bo_response.best_policy);
// pstore.setWeights(active_bo_response.best_weights);
// rstore.setMean(active_bo_response.reward_mean);
// rstore.setStd(active_bo_response.reward_std);
// }
// );
// const rl_request = new ROSLIB.ServiceRequest({
// policy: pstore.policy,
// });
//
// rl_service.callService(rl_request, () => {});
watch(
() => active_bo_pending.value,
() => {
if (active_bo_pending.value) {
return;
}
const rl_request = new ROS.ServiceRequest({
env: cstore.env,
policy: pstore.policy,
});
rl_service.callService(rl_request, () => {});
}
);
</script>

View File

@ -5,8 +5,8 @@ export const useCStore = defineStore("Control Store", {
return {
env: "Mountain Car",
envs: ["Mountain Car", "Cartpole", "Acrobot", "Pendulum"],
metric: "manually",
metircs: ["manually", "BO", "active BO"],
metric: "random",
metircs: ["random", "regular", "max acquisition", "improvement"],
acq_fun: "Expected Improvement",
acq_funs: [
"Expected Improvement",
@ -15,7 +15,7 @@ export const useCStore = defineStore("Control Store", {
],
nr_episodes: 50,
nr_runs: 10,
metric_parameter: 0,
metric_parameter: 0.5,
sendWeights: false,
runner: false,
fixed_seed: false,