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

View File

@ -140,9 +140,6 @@ const active_rl_eval_pub = new ROS.Topic({
watch( watch(
() => cstore.getSendWeights, () => cstore.getSendWeights,
() => { () => {
const metric = cstore.getMetric;
if (metric === "active BO") {
if (!pendingRequest.value) { if (!pendingRequest.value) {
return; return;
} }
@ -159,7 +156,6 @@ watch(
console.log("New Policy/ Weights published"); console.log("New Policy/ Weights published");
pendingRequest.value = false; pendingRequest.value = false;
} }
}
); );
const rl_service = new ROS.Service({ const rl_service = new ROS.Service({
@ -168,11 +164,11 @@ const rl_service = new ROS.Service({
serviceType: "active_bo_msgs/srv/RLRollOut", serviceType: "active_bo_msgs/srv/RLRollOut",
}); });
const bo_service = new ROS.Service({ // const bo_service = new ROS.Service({
ros: ros, // ros: ros,
name: "/bo_srv", // name: "/bo_srv",
serviceType: "active_bo_msgs/srv/BO", // serviceType: "active_bo_msgs/srv/BO",
}); // });
const active_bo_pending = ref(false); const active_bo_pending = ref(false);
@ -199,41 +195,9 @@ active_bo_response.subscribe((msg) => {
watch( watch(
() => cstore.getRunner, () => cstore.getRunner,
() => { () => {
const usr_mode = cstore.getMetric;
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({ const request_msg = new ROS.Message({
env: cstore.env, env: cstore.env,
metric: cstore.metric,
fixed_seed: cstore.fixed_seed, fixed_seed: cstore.fixed_seed,
nr_weights: pstore.nr_weights, nr_weights: pstore.nr_weights,
max_steps: pstore.max_steps, max_steps: pstore.max_steps,
@ -242,40 +206,23 @@ watch(
acquisition_function: cstore.acq_fun, acquisition_function: cstore.acq_fun,
metric_parameter: cstore.metric_parameter, metric_parameter: cstore.metric_parameter,
}); });
active_bo_pending.value = true;
active_bo_request.publish(request_msg); active_bo_request.publish(request_msg);
}
);
watch(
() => active_bo_pending.value,
() => {
if (active_bo_pending.value) {
return;
}
const rl_request = new ROS.ServiceRequest({ const rl_request = new ROS.ServiceRequest({
env: cstore.env, env: cstore.env,
policy: pstore.policy, policy: pstore.policy,
}); });
rl_service.callService(rl_request, () => {}); 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, () => {});
}
} }
); );
</script> </script>

View File

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