vimrc

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | Submodules

commit 0368224b11a93f5c2ce24c31c9d47dc8f55fc25a
parent 62ae1a691b21fde94c4c24882ab1a13ab78d9cf1
Author: Pablo Cárdenas <pablo.cardenas@imca.edu.pe>
Date:   Mon, 30 Jan 2023 19:09:12 -0500

Updated python snippets

Diffstat:
MUltiSnips/python.snippets | 36+++++++++++++++++++++++++++++++-----
1 file changed, 31 insertions(+), 5 deletions(-)

diff --git a/UltiSnips/python.snippets b/UltiSnips/python.snippets @@ -235,13 +235,12 @@ import torch.nn.functional as F $0 endsnippet -snippet gym "import gymnasium as gym" b -import gymnasium as gym -$0 -endsnippet - # --------------------------------------------- # +snippet torch.device "device = torch.device('cuda' if not torch.cuda.is_available() else 'cpu')" b +device = torch.device("cuda" if not torch.cuda.is_available() else "cpu") +endsnippet + snippet no_grad "with torch.no_grad()" b with torch.no_grad(): ${0:${VISUAL:pass}} @@ -253,6 +252,33 @@ loss.backward() optimizer.step() endsnippet +snippet gym "gym loop" b +from itertools import count + +import gymnasium as gym + + +env = gym.make("${1:LunarLander-v2}"`!p +snip.rv = ', render_mode="' if t[2] else "" +`${2:human}`!p +snip.rv = '"' if [2] else "" +`) + +for i_episode in count(): + observation, info = env.reset(`!p snip.rv = "seed=" if t[3] else ""`${3:42}) + for t in count(): + # Select an action + $0action = env.action_space.sample() + + # Perform action in the enviroment + observation, reward, terminated, truncated, info = env.step(action) + + if terminated or truncated: + break + +env.close() +endsnippet + # --------------------------------------------- # snippet if "If" b