Is it possible to replace an axis with a parasiteaxis? - matplotlib

I have code that requires a ParasiteAxis instance, or at least something with a toggle_axisline method, in order to function properly. I'd like to be able to pass it any arbitrary axis created in any way (e.g., through a simple plot call).
How can I convert any given axis instance into a ParasiteAxis or HostAxis instance?
(for a specific use-case, see issue https://github.com/aplpy/aplpy/pull/88 and specifically the workaround implemented in commit https://github.com/keflavich/aplpy/commit/02ecd5386f7d3a93ca8e60c3db2b34ff3216060a)

Related

Checking to see if an image format supports a usage in Vulkan?

If I want to see what an image format can be used for I can do the vkGetPhysicalDeviceImageFormatProperties2() and set the usage flag for the image format. I've noticed if the format isn't supported for those usages and settings the structure I pass in is set to all zero, and I can know if the format supports those uses. So if I want to know if VK_FORMAT_R8G8B8_UINT supports sampling from a shader I set the VK_IMAGE_USAGE_SAMPLED_BIT in the usage flags and call that function.
What I wanted to know is if that's equivalent to calling another function, called vkGetPhysicalDeviceFormatProperties2(), exactly the same name but without 'image' in the name, give that function the format, and check whether the VK_IMAGE_USAGE_SAMPLED_BIT is set.
So using the first method I give the format and usages I want from it, and then check if the values returned are zero max width, max height, etc, meaning those usages aren't supported, versus the second method of passing the format, getting back the flags and then checking the flags.
Are these two methods equivalent?
TL;DR: Do your image format checking properly: ask how you can use the format, then ask what functionality is available from usable format&usage combinations.
If you call vkGetPhysicalDeviceImageFormatProperties2 with usage flags and the like that don't correspond to a supported image type, you get an error: VK_ERROR_FORMAT_NOT_SUPPORTED. It inherits this due to the fact that it is said to "behave similarly to vkGetPhysicalDeviceImageFormatProperties", which has an explicit statement about this error:
If format is not a supported image format, or if the combination of format, type, tiling, usage, and flags is not supported for images, then vkGetPhysicalDeviceImageFormatProperties returns VK_ERROR_FORMAT_NOT_SUPPORTED.
Now normally, a function which gives rise to an error will yield undefined values in any return values. But there is a weird exception:
If the combination of parameters to vkGetPhysicalDeviceImageFormatProperties2 is not supported by the implementation for use in vkCreateImage, then all members of imageFormatProperties will be filled with zero.
However, there's an explicit note saying that this was old, bad behavior and is only preserved for compatibility's sake. Being a compatibility feature means that you can rely on it, but you shouldn't. Also, it only applies to the imageFormatProperties data and not any of the extension structures you can pass.
So it's best to just ignore this and ask your questions in the right order.

Best way to use edge_is_constrained_map with make_mesh_3?

I would like to pass on an edge_is_constrained_map obtained from the corefine_and_compute_intersection to make_mesh_3 so that the edges are preserved during meshing. I have tried to find the best way to do this but have not found anything on the subject. The only mechanism to pass on protected features manually to make_mesh_3 I could find is trough polylines, but I sort of expect there to also be a mechanism to pass on constrained maps as is the case for tetrahedral_isotropic_remeshing. Is there otherwise a function to convert an edge_is_constrained_map containing multiple line segments into valid polylines? Or is there another way of passing an edge_is_constrained_map to make_mesh_3?

TFAgents: how to take into account invalid actions

I'm using TF-Agents library for reinforcement learning,
and I would like to take into account that, for a given state,
some actions are invalid.
How can this be implemented?
Should I define a "observation_and_action_constraint_splitter" function when
creating the DqnAgent?
If yes: do you know any tutorial on this?
Yes you need to define the function, pass it to the agent and also appropriately change the environment output so that the function can work with it. I am not aware on any tutorials on this, however you can look at this repo I have been working on.
Note that it is very messy and a lot of the files in there actually are not being used and the docstrings are terrible and often wrong (I forked this and didn't bother to sort everything out). However it is definetly working correctly. The parts that are relevant to your question are:
rl_env.py in the HanabiEnv.__init__ where the _observation_spec is defined as a dictionary of ArraySpecs (here). You can ignore game_obs, hand_obs and knowledge_obs which are used to run the environment verbosely, they are not fed to the agent.
rl_env.py in the HanabiEnv._reset at line 110 gives an idea of how the timestep observations are constructed and returned from the environment. legal_moves are passed through a np.logical_not since my specific environment marks legal_moves with 0 and illegal ones with -inf; whilst TF-Agents expects a 1/True for a legal move. My vector when cast to bool would therefore result in the exact opposite of what it should be for TF-agents.
These observations will then be fed to the observation_and_action_constraint_splitter in utility.py (here) where a tuple containing the observations and the action constraints is returned. Note that game_obs, hand_obs and knowledge_obs are implicitly thrown away (and not fed to the agent as previosuly mentioned.
Finally this observation_and_action_constraint_splitter is fed to the agent in utility.py in the create_agent function at line 198 for example.

Run-State values within shape script EA

Enterprise Architect 13.5.
I made MDG technology extending Object metatype. I have a shape script for my stereotype working well. I need to print several predefined run-state parameters for element. Is it possible to access to run-state params within Shape ?
As Geert already commented there is no direct way to get the runstate variables from an object. You might send a feature request to Sparx. But I'm pretty sure you can't hold your breath long enough to see it in time (if at all).
So if you really need the runstate in the script the only way is to use an add-in. It's actually not too difficult to create one and Geert has a nice intro how to create it in 10 minutes. In your shape script you can print a string restult returned from an operation like
print("#addin:myAddIn,pFunc1#")
where myAddIn is the name of the registered operation and pFunc1 is a parameter you pass to it. In order to control the script flow you can use
hasproperty('addin:myAddIn,pFunc2','1')
which evaluates the returned string to match or not match the string 1.
I once got that to work with no too much hassle. But until now I never had the real need to use it somewhere in production. Know that the addin is called from the interpreted script for each shaped element on the diagram and might (dramatically) affect rendering times.

RangeTool update on event in bokeh

I'm trying to compute some statistics on a given range of data from a plot using a bokeh app. For selecting the range I am using RangeTool. However I cannot find the way to detect the event. I'm using as base this example:
https://docs.bokeh.org/en/latest/docs/gallery/range_tool.html
Then I tried:
def func():
print(range_rool._property_values['x_range'].start)
return
def func_e(event):
print('event detected')
return
range_rool.on_event(ButtonClick,func_e)
range_rool.on_event(Press,func)
range_rool.on_change("x_range",func)
but when I move the slider I don't see any difference. Any idea very welcome. Thanks
The RangeTool updates the range it is configured with, you can (and should) just add callbacks on the range itself, e.g.:
range_tool.x_range.on_change('start', ...)
Regarding the line range_rool.on_change("x_range",func) that you have, it's worth explaining that that instructs Bokeh to run func when the range object itself is wholesale replaced, i.e.
range_tool.x_range = some_new_Range1d
would trigger that callback. But the range is never normally replaced liked that. Instead, the start and end values of a single range are updated over time.
Also, as an aside, there is never any valid reason at all to access _properties. It is a private API and subject to change at any time.