how do I write module and its arguments to launch.json in VS Code?
The codes in shell file are:
CUDA_VISIBLE_DEVICES=2,3 python3 -m torch.distributed.launch --nproc_per_node=2 --master_port=${MASTER_PORT} ../../train.py \
$data \
--selected-cols=${selected_cols} \
--bpe-dir=${bpe_dir} \
and so on.
I wrote the codes above into launch.json file like:
"version": "0.2.0",
"configurations": [
{
"name": "train",
"type": "python",
"request": "launch",
"program": "${workspaceFolder}/OFA/train.py",
"console": "integratedTerminal",
"justMyCode": true,
"module": "torch.distributed.launch",
"args": [
"--selected-cols", "1,4,2",
"--bpe-dir", "../../utils/BPE",
and so on.
The problem I am facing is I have no clue how to write --proc_per_node=2 and --master_port=${MASTER_PORT} into this launch.json file. To my opinion they belong to "module" since they appear after -m torch.distributed.launch.
Does anyone know the way to integrate these extra arguments into "module"?? If they are not the part of "module", how should I write them??
great thanks to anyone answering my question
do you know?
how many words do you know
See also questions close to this topic
-
Python File Tagging System does not retrieve nested dictionaries in dictionary
I am building a file tagging system using Python. The idea is simple. Given a directory of files (and files within subdirectories), I want to filter them out using a filter input and tag those files with a word or a phrase.
If I got the following contents in my current directory:
data/ budget.xls world_building_budget.txt a.txt b.exe hello_world.dat world_builder.spec
and I execute the following command in the shell:
py -3 tag_tool.py -filter=world -tag="World-Building Tool"
My output will be:
These files were tagged with "World-Building Tool": data/ world_building_budget.txt hello_world.dat world_builder.spec
My current output isn't exactly like this but basically, I am converting all files and files within subdirectories into a single dictionary like this:
def fs_tree_to_dict(path_): file_token = '' for root, dirs, files in os.walk(path_): tree = {d: fs_tree_to_dict(os.path.join(root, d)) for d in dirs} tree.update({f: file_token for f in files}) return tree
Right now, my dictionary looks like this:
key:''
.In the following function, I am turning the empty values
''
into empty lists (to hold my tags):def empty_str_to_list(d): for k,v in d.items(): if v == '': d[k] = [] elif isinstance(v, dict): empty_str_to_list(v)
When I run my entire code, this is my output:
hello_world.dat ['World-Building Tool'] world_builder.spec ['World-Building Tool']
But it does not see
data/world_building_budget.txt
. This is the full dictionary:{'data': {'world_building_budget.txt': []}, 'a.txt': [], 'hello_world.dat': [], 'b.exe': [], 'world_builder.spec': []}
This is my full code:
import os, argparse def fs_tree_to_dict(path_): file_token = '' for root, dirs, files in os.walk(path_): tree = {d: fs_tree_to_dict(os.path.join(root, d)) for d in dirs} tree.update({f: file_token for f in files}) return tree def empty_str_to_list(d): for k, v in d.items(): if v == '': d[k] = [] elif isinstance(v, dict): empty_str_to_list(v) parser = argparse.ArgumentParser(description="Just an example", formatter_class=argparse.ArgumentDefaultsHelpFormatter) parser.add_argument("--filter", action="store", help="keyword to filter files") parser.add_argument("--tag", action="store", help="a tag phrase to attach to a file") parser.add_argument("--get_tagged", action="store", help="retrieve files matching an existing tag") args = parser.parse_args() filter = args.filter tag = args.tag get_tagged = args.get_tagged current_dir = os.getcwd() files_dict = fs_tree_to_dict(current_dir) empty_str_to_list(files_dict) for k, v in files_dict.items(): if filter in k: if v == []: v.append(tag) print(k, v) elif isinstance(v, dict): empty_str_to_list(v) if get_tagged in v: print(k, v)
-
Actaully i am working on a project and in it, it is showing no module name pip_internal plz help me for the same. I am using pycharm(conda interpreter
File "C:\Users\pjain\AppData\Local\Programs\Python\Python310\lib\runpy.py", line 196, in _run_module_as_main return _run_code(code, main_globals, None, File "C:\Users\pjain\AppData\Local\Programs\Python\Python310\lib\runpy.py", line 86, in _run_code exec(code, run_globals) File "C:\Users\pjain\AppData\Local\Programs\Python\Python310\Scripts\pip.exe\__main__.py", line 4, in <module> File "C:\Users\pjain\AppData\Local\Programs\Python\Python310\lib\site-packages\pip\_internal\__init__.py", line 4, in <module> from pip_internal.utils import _log
I am using pycharm with conda interpreter.
-
Looping the function if the input is not string
I'm new to python (first of all) I have a homework to do a function about checking if an item exists in a dictionary or not.
inventory = {"apple" : 50, "orange" : 50, "pineapple" : 70, "strawberry" : 30} def check_item(): x = input("Enter the fruit's name: ") if not x.isalpha(): print("Error! You need to type the name of the fruit") elif x in inventory: print("Fruit found:", x) print("Inventory available:", inventory[x],"KG") else: print("Fruit not found") check_item()
I want the function to loop again only if the input written is not string. I've tried to type return Under print("Error! You need to type the name of the fruit") but didn't work. Help
-
How to convert String having key=value pairs to Json
myString =
{AcquirerName=abc, AcquiringBankCode=0.2, ApprovalCode=00};
I want to convert it to the following string.
{"AcquirerName": "abc", "AcquiringBankCode": 0.2, "ApprovalCode": 0};
How can I do it in java?
-
Fetch doesn't retrive data
I am currently building a login form which will be using a restAPI for the registration/Auth but I'm receiving a 401 error when using fetch to test the retrieved data.
console.log(fetch('http://localhost:5000/users/'), { method: 'get', headers: { 'Content-Type': 'application/json' }, })
.then(res => res.json()) .then(json => console.log(json))</code>
-
NextJS: Error serializing `.data.data` returned from `getServerSideProps`
I'm new to NextJS. I'm working on a simple page in which I need to retrieve data from my backend app. My backend app is a totally separate app written in go. My undestanding is that I must use
getServerSideProps
to get data from the server on load, so I've got the following:myProject/pages/category/new.js
:export default function AddNewCategory(data) { ... } export const getServerSideProps = async () => { const data = await getAllCategories(); console.log(await data) return { props: { data: { data } } }; };
myProject/api/category.js
:import axios from "axios"; // getAllCategories returns a list of all active categories export const getAllCategories = async() => { axios.get("http://127.0.0.1:8080/api/v1/categories") .then(function (response) { console.log(response.data) return response.data; }) .catch(error => { console.error("error") console.log(error) }) }
As you can see I've got a print statement in
getAllCategories
which prints:{ data: [ { id: 1, name: 'Pop', slug: 'pop', description: 'Pop', parent: 0, active: true, created_at: '2022-05-03T19:50:00-04:00', updated_at: '2022-05-03T19:50:00-04:00', deleted_at: null }, { id: 3, name: 'Pop 2', slug: 'pop-2', description: 'Pop', parent: 0, active: true, created_at: '2022-05-03T19:50:24-04:00', updated_at: '2022-05-03T19:50:24-04:00', deleted_at: null } ] }
yet I'm getting the following error:
error - Error: Error serializing
.data.data
returned fromgetServerSideProps
in "/category/new". Reason:undefined
cannot be serialized as JSON. Please usenull
or omit this value.I saw around that I should try to convert the data to string and then back to json:
return { props: { data: JSON.parse(JSON.stringify(data)) } };
but when I do this I'm getting a different error:
error - SyntaxError: Unexpected token u in JSON at position 0
I'm using
next@12.1.5
Any idea what's going on?
-
Appending values to existing values of environment variables in go
How can I append another value to an existing value of a go environment variable?
If CGO_CXXFLAGS has the value "-I/blah/blah"
Since the following doesn't work
$ go env -w CGO_CXXFLAGS="$CGO_CXXFLAGS -I/foo/bar"
I want to find a proper way to CGO_CXXFLAGS have the value "-I/blah/blah -I/foo/bar"
by avoiding to simply re-set all the values plus the new one, such as in:
$ go env -w CGO_CXXFLAGS="-I/blah/blah -I/foo/bar"
-
Update global variable from while loop
Having trouble updating my global variable in this shell script. I have read that the variables inside the loops run on a sub shell. Can someone clarify how this works and what steps I should take.
USER_NonRecursiveSum=0.0 while [ $lineCount -le $(($USER_Num)) ] do thisTime="$STimeDuration.$NTimeDuration" USER_NonRecursiveSum=`echo "$USER_NonRecursiveSum + $thisTime" | bc` done
-
How do you use mktemp to create directory in Makefile?
edit:
Solved by awesome answer below. Expand the variables using := instead of =
mktemp: TEST:=$(shell mktemp -d) mktemp: echo $(TEST) touch $(TEST)/test.txt ls $(TEST) cat $(TEST)/test.txt rm -rf $(TEST)
original question:
This is a Makefile piece of code of how someone may use mktemp in a Makefile
TEST=$(shell mktemp -d) mktemp: echo $(TEST) touch $(TEST)/test.txt ls $(TEST) cat $(TEST)/test.txt rm -rf $(TEST)
This is an example output
❯ make mktemp echo /var/folders/62/wkysd_4n0w57ljl9ycfsd9cc0000gn/T/tmp.tQI5EeyW /var/folders/62/wkysd_4n0w57ljl9ycfsd9cc0000gn/T/tmp.tQI5EeyW touch /var/folders/62/wkysd_4n0w57ljl9ycfsd9cc0000gn/T/tmp.lVL3N8Rp/test.txt ls /var/folders/62/wkysd_4n0w57ljl9ycfsd9cc0000gn/T/tmp.sBW9FzgD cat /var/folders/62/wkysd_4n0w57ljl9ycfsd9cc0000gn/T/tmp.Ti53SWSw/test.txt cat: /var/folders/62/wkysd_4n0w57ljl9ycfsd9cc0000gn/T/tmp.Ti53SWSw/test.txt: No such file or directory make: *** [mktemp] Error 1
The expectation is that
cat /var/folders/62/wkysd_4n0w57ljl9ycfsd9cc0000gn/T/tmp.Ti53SWSw/test.txt
would not error.How can mktemp be used in this case?
-
"Core Dump" analogue for Python scripts?
Say, my script runs on server and has failed at some moment of time.
Except for the error messages in the logs - I would like to have some image file on server side - representing the state of python process in the moment of failure.
I would be able then to move it to my local machine, load into debugger, examine the call stack and what data in what function did really cause the exception.
Is there a way to do that?
-
How do I position Eclipse type hierarchy while editing
Eclipse for Windows 64-bit machine - Version: 2022-03 (4.23.0).
I am used to having the Type Hierarchy (?) in a tab on the right side of my screen. It was like that through a number of Eclipse releases, and it worked for me! I seem to have lost that, and can't seem to get it back!
Now the nearest I can get to that layout is to do CTL-O, but the methods are in alphabetical order, and I can't seem to get the display over to the right side of the screen (alpha order is sort of OK - I am not keen on it, but it's better than nothing!). Plus it seems to be a popup, and doesn't last long enough! I have seen posts saying I can grab the CTL-O (?) tab and drag it over, but I can't find the tab.
It's probably something dumb, but I can't figure it out! Maybe a more general question would be: what's the best tool in Eclipse for navigating around a complex type hierarchy? Help would be appreciated!
-
How to set, list, get breakpoints in classdef in octave?
Suppose I have a classdef in a MyClass.m file with properties and methods like in the polynomial2 example found here https://octave.org/doc/v7.1.0/Creating-a-classdef-Class.html
I've confirmed that it's possible to set breakpoints in class methods using
dbstop in MyClass at MyClassMethod
as described here https://octave.org/doc/v7.1.0/Breakpoints.html
My questions are:
Is it possible to use a line number instead of the method name?
Is is possible to list the breakpoints in the class file?
Is it possible to clear breakpoints only in that class file?
Since all of the above are possible for functions, I would suppose it should also be possible for classes.
Thank you
-
Is it possible to use input variables in keybindings in VS Codium?
In Visual Studio Codium I want to define a command that has a variable parameter.
I want the IDE to open specific file, which name is written in another file. Assume I have the following project structure:
/home/user/myproject/ /home/user/myproject/dir1/ /home/user/myproject/dir1/problem1.py /home/user/myproject/dir1/problem2.py /home/user/myproject/dir2/problem1.py ... /home/user/myproject/pointer.txt
The
pointer.txt
contains path to the file I want to work on. For example, it contains:dir1/problem1
.I have read the documentation here. Now I created the following construction:
keybindings.json
:{ "key": "numpad3", "command": "htmlRelatedLinks.openFile", "args": { "file": "${workspaceFolder}/${input:mycatinput}.py", "method": "vscode.open", "viewColumn": 2, } },
tasks.json
:{ "version": "2.0.0", "tasks": [ { "label": "mycat", "type": "shell", "command": "cat /home/user/myproject/pointer.txt" }, ], "inputs": [ { "id": "mycatinput", "type": "command", "command": "workbench.action.tasks.runTask", "args": "mycat" } ] }
But when I press numpad3, I get an error notification with text:
Unable to open '${input:mycatinput}.py': File not found.
Am I missing something? How do I specify a variable in keybindings.json command, which itself is a result of another command (a shell command, not a vscode command).
-
Can I use multiple different commands for a single file type in coderunner?
"code-runner.executorMap": { "cpp": "cd $dir && g++ -Wall -Wextra -O2 -std=c++14 $fileName -o $fileNameWithoutExt && $dir$fileNameWithoutExt" },
Coderunner has a command to run .cpp code, but if I want to use another command, such as adding " < input.txt", I would have to go to settings.json to change it. Is there a way to set up multiple commands on vscode for a single kind of file so I can just simply switch without having to change settings.json?
-
How do I set the default c# file in my Visual Studio Code c# Project?
I am new to using Visual Studio Code. I have always used Visual Studio IDE in Windows. I am trying to run a simple Hello World Program on Mac with VS Code. I ran the following command
dotnet new console
which successfully created the csProj file and Program.cs file with the code
Console.WriteLine("Hello, World!");
Now by issuing dotnet run command I can get the output from this Program as well. But I have a different cs file called "Hello.cs" in the same Project location. How do I get the Hello.cs to run instead of the default "Program.cs" created bydotnet new console
command. I tried giving the following property group in the .csproj file but VS Code reports error this is reserved property.<PropertyGroup><StartupObject>Hello.HelloWorld</StartupObject></PropertyGroup>
Is there another way to choose your default startup CS File if you have multiple CS files in your Project.