How do I configure Dask distributed logging levels with an environment variable? - dask

It feels like I should be able to read between the lines of https://docs.dask.org/en/latest/how-to/debug.html and https://docs.dask.org/en/latest/configuration.html to craft an environment variable name and value, but none of
DASK_DISTRIBUTED__LOGGING=DEBUG
DASK_LOGGING_DISTRIBUTED=DEBUG
DASK__LOGGING__DISTRIBUTED=DEBUG
DASK__LOGGING__DISTRIBUTED__SCHEDULER=DEBUG
nor the equivalents with 10 instead of DEBUG, nor some other combinations of order and underscore seem to do the trick.

Related

Why do people put local vim = vim at the top of init.lua

I've seen in several places that people put at the top of their init.lua: local vim = vim. What is the purpose of this? I could understand aliasings like local v = vim or local g = vim.g but it appears like local vim = vim doesn't do anything.
local name = name is called a localization. There are multiple good reasons to localize variables:
Performance
Recall that for environmental (usually global) variables, name is just syntactic sugar for _ENV.name which in turn is syntactic sugar for _ENV["name"]; acessing a local variable on the other hand is practically a single array access where Lua knows the array index at compile-time (it's either an upvalue or a local, which get stored in different arrays; upvalues of functions are slightly slower).
The array/"register" access will be faster than accessing the hash part of _ENV and searching for "name" (hash map lookup is slower than array access). Technically Lua even has to first check the (implicit) _ENV upvalue (called "function environment" in Lua 5.1 / LuaJIT) to see which table to index.
In conclusion, local variables / upvalues are usually faster than environmental variables; JIT-compilers like LuaJIT might optimize this out, but even LuaJIT has to consider the possibility that _G.vim may be modified, which brings us to our second point:
Semantics
it appears like local vim = vim doesn't do anything
For the most part this is correct, but not quite: local vim = vim means "get the vim environmental (global) variable at the time this line of code is executed (the load time of the script if it's at the top), then store it in a 'private' variable"; without this line, later modifications of the environment (e.g. vim = nil) outside of the script will have an effect because the environment is reindexed. With this line, you get to keep your reference to the vim table no matter what happens later on, which also provides an assurance to Lua / presumably also LuaJIT that it won't change later on.
Additionally, if a metatable is set on _G, _G.name can return different results at different times based on the metamethod that returns it. Again localizing ensures that your local variable doesn't change (unless you explicitly change it).
Code Quality
Localizing all used environmentals makes your dependencies explicit, akin to the "import" statements of other languages. In Lua, require is not consistently used; some libraries are simply part of the global environment _G, such as vim in your example, whereas others have to be required. For require, you'd use local lib = require("lib"), then why not consistently do this for global variables as well, rather than redoing the indexing operation every time?
Environment Changing
This will probably rarely be the reason, but it's worth noting.
If you set a custom environment for your chunk, you will have to find a way to keep accessing global variables.
There are two options for this:
One is to use a metatable with __index = _G (or whatever the parent environment is to be), but this is inefficient and unpredictable; it practically means your environment inherits everything from its parent environment, so e.g. _ENV.math.floor would be _G.math.floor, which may be considered dirty if you want to export your _ENV as API table of a module.
The other is to localize all global variables you use. This doesn't have the drawbacks of the first solution; it is more performant, more predictable, and doesn't force you to have your environment inherit from the parent environment.

Lua 4 outermost variable scope

Should I explicitly declare a variable in the outermost scope of a Lua 4 script a
local variable versus a global variable? Should I avoid one or the other? Thanks.
For instance:
local foo = 5
versus
faa = 8
I believe you already know that local variables are variables where they exist only within a certain scope, while normal variables are global and are included within the _G table. However, according to Lua's Performance Guide, it also helps to make your code faster:
Lua precompiler is able to store all local variables in registers. The result is that access to local variables is very fast in Lua. For instance, if a and b are local variables, a Lua statement like a = a + b generates one single instruction.
So, it is easy to justify one of the most important rules to improve the performance of Lua programs: use locals!

Check values existence using spss syntax

I should check existence of values based on some conditions.
i.e. i have 3 variables, varA, varB and varC. varC should not be empty only if varA>varB (condition).
i normally use some syntax to check any of the variables and run a frequency of any of them to see if there are errors:
if missing(varC) and (varA>varB) ck_varC=1.
if not(missing(varC)) and not(varA>varB) ck_varC=2.
exe.
fre ck_varC.
exe.
I had some errors when the condition became complex and when in the condition there are missing() or other functions but i could have made a mistake.
do you think there is an easier way of doing this checks?
thanks in advance
EDIT: here an example of what i mean, think at a questionnaire with some routing, you ask age to anyone, if they are between 17 and 44 ask them if they work, if they work ask them how many hours.
i have an excel tool where i put down all variables with all conditions, then it will generate the syntax in the example, all with the same structure for all variables, considering both situations, we have a value that shouldn't be there or we don't have a value that should be there.
is there an easier way of doing that? is this structure always valid no matter what is the condition?
In SPSS, missing values are not numbers. You need to explicitly program those scenarios as well. you got varC covered (partially), but no scenario where varA or varB have missing data is covered.
(As good practice, maybe you should initialize your check variable as sysmis or 0, using syntax):
numeric ck_varC (f1.0).
compute ck_varC=0.
if missing(varC) and (varA>varB) ck_varC=1.
if not(missing(varC)) and not(varA>varB) ck_varC=2.
***additional conditional scenarios go here:.
if missing(varA) or missing(varB) ck_varC=3.
...
fre ck_varC.
By the way - you do not need any of the exe. commands if you are going to run your syntax as a whole.
Later Edit, after the poster updated the question:
Your syntax would be something like this. Note the use of the range function, which is not mandatory, but might be useful for you in the future.
I am also assuming that work is a string variable, so its values need to be referenced using quotation signs.
if missing(age) ck_age=1.
if missing(work) and range(age,17,44) ck_work=1.
if missing(hours) and work="yes" ck_hours=1.
if not (missing (age)) and not(1>0) ck_age=2. /*this will never happen because of the not(1>0).
if not(missing(work)) and (not range(age,17,44)) ck_work=2. /*note that if age is missing, this ck_work won't be set here.
if not(missing(hours)) and (not(work="yes")) ck_hours=2.
EXECUTE.
String variables are case sensitive
There is no missing equivalent in strings; an empty blank string ("") is still a string. not(work="yes") is True when work is blank ("").

lldb python basic - print value of a global array while inside a breakpoint in a function

(Some background: I am not experienced with lldb or python and don't work on them frequently, but currently need to make some basic scripts for debugging an iphone program)
I am currently stopped at a breakpoint in side a function, and want to check the value of an array that has been accessed inside this function
This array is declared as
Float32 my_array[128];
and has global scope. I can view the array using print command, but I would like to make a python script so that I have more control over the output formatting and possibly plot the array elements as a graph using matplolib later on.
I am looking at the sample python code given in this question, and using the python given there I have verified that I can view local variables in this function (where currently I am stopped at a break point). For example, if I change 'base' in base=frame.FindVariable('base') to my local variable 'k' (the local variable is not an array) ,
base=frame.FindVariable('k')
then print base I can see the value of k. However, if I try this,
base=frame.FindVariable('my_array')
and do print base it gives me No value. How can I write a python command to get the values of any kind of variable currently in scope? Preferably it works for normal variables (int, float), arrays, and pointers, but if not, finding values of arrays are more important at the moment.
SBFrame.FindVariable searches among the variables local to that frame. It doesn't search among the global variables.
For that you need to use a search with a wider scope. If you know that the global variable is in the binary image containing the your frame's code - lldb calls that binary image a Module - then you can find the module containing that frame and use SBModule.FindGlobalVariables. If that's not true, you can search the whole target using SBTarget.FindGlobalVariables. If you know that only one global variable of that name exists, you can use FindFirstGlobalVariable variant.
All these commands will find variables of any type, and they all consistently return SBValues so you can format them in a consistent manner regardless of how you find them. For statically allocated arrays, the array elements are its children, so you can fetch individual elements with SBValue.GetChildAtIndex.
You can get to a SBFrame's module like:
module = frame.module
and its target:
target = frame.thread.process.target
lldb separates the contexts in which to search for variables primarily for efficiency. If SBFrame.FindVariable searched for globals as well as locals, a mistyped variable name would be a much more expensive mistake. But it also makes the call more predictable since you will never get some random global from some shared library that the system loaded on your behalf.

f(var) only works in a shell session?

I'm needing to reset some variables in a loop in order to assign the new values (like finding the index of a substring) i cannot reuse the same var so i must unset it and as far as i know the f(var) only works in a shell?
so is there no way to do this in a script?
f() is a shell-only command.
Erlang as a language uses immutable variables, and as such does not allow the resetting of variables within the code itself. The recommendation is to get comfortable with recursion, list comprehensions, mapping, or folding in order to accomplish "loops" which don't exist in the procedural sense in Erlang.
If you must rely on variable state, the closest thing you get to mutable variables is the process dictionary: get/1 and put/2. These are generally discouraged unless there is a good reason for using them.

Resources