Rexster query returns "No such property: v for class: com.thinkaurelius.titan.graphdb.database.StandardTitanGraph" - groovy

I'm using TitanGraphDB + Cassandra. I'm starting Titan as follows
cd titan-cassandra-0.3.1
bin/titan.sh config/titan-server-rexster.xml config/titan-server-cassandra.properties
I have a Rexster shell that I can use to communicate to Titan + Cassandra above.
cd rexster-console-2.3.0
bin/rexster-console.sh
I'm attempting to model a network topology using Titan Graph DB. I want to program the Titan Graph DB from my python program. I'm using bulbs package for that.
I create five types of vertices
- switch
- port
- device
- flow
- flow_entry
I create edges between vertices that are connected logically. The edges are not labelled.
Let us say I want to test the connectivity between Vertex A and Vertex B
I have a groovy script is_connected.groovy
def isConnected (portA, portB) {
return portA.both().retain([portB]).hasNext()
}
Now from my rexster console
g = rexster.getGraph("graph")
==>titangraph[embeddedcassandra:null]
rexster[groovy]> g.V('type', 'flow')
==>v[116]
==>v[100]
rexster[groovy]> g.V('type', 'flow_entry')
==>v[120]
==>v[104]
As you can see above I have two vertices of type flow v[116] and v[100]
I have two vertices of type flow_entry v[120] and v[104]
I want to check for the connectivity between v[120] and v[116] for e.g
rexster[groovy]> ?e is_connected.groovy
==>null
rexster[groovy]> is_connected(g.v[116],g.v[120])
==>An error occurred while processing the script for language [groovy]. All transactions across all graphs in the session have been concluded with failure: java.util.concurrent.ExecutionException: javax.script.ScriptException: javax.script.ScriptException: groovy.lang.MissingPropertyException: No such property: v for class: com.thinkaurelius.titan.graphdb.database.StandardTitanGraph
Either I am doing something very wrong,or I am missing something obvious.It would be great if you could point me in the right direction.

This syntax is not valid groovy:
is_connected(g.v[116],g.v[120])
should be:
is_connected(g.v(116),g.v(120))

You're mixing up Python syntax with Gremlin-Groovy syntax:
You defined the Groovy script as:
def isConnected (portA, portB) {
return portA.both().retain([portB]).hasNext()
}
...so...
rexster[groovy]> is_connected(g.v[116], g.v[120])
...should be...
rexster[groovy]> isConnected(g.v(116), g.v(120))

Related

Confusion About Implementing LeafSystem With Vector Output Port Correctly

I'm a student teaching myself Drake, specifically pydrake with Dr. Russ Tedrake's excellent Underactuated Robotics course. I am trying to write a combined energy shaping and lqr controller for keeping a cartpole system balanced upright. I based the diagram on the cartpole example found in Chapter 3 of Underactuated Robotics [http://underactuated.mit.edu/acrobot.html], and the SwingUpAndBalanceController on Chapter 2: [http://underactuated.mit.edu/pend.html].
I have found that due to my use of the cart_pole.sdf model I have to create an abstract input port due receive FramePoseVector from the cart_pole.get_output_port(0). From there I know that I have to create a control signal output of type BasicVector to feed into a Saturation block before feeding into the cartpole's actuation port.
The problem I'm encountering right now is that I'm not sure how to get the system's current state data in the DeclareVectorOutputPort's callback function. I was under the assumption I would use the LeafContext parameter in the callback function, OutputControlSignal, obtaining the BasicVector continuous state vector. However, this resulting vector, x_bar is always NaN. Out of desperation (and testing to make sure the rest of my program worked) I set x_bar to the controller's initialization cart_pole_context and have found that the simulation runs with a control signal of 0.0 (as expected). I can also set output to 100 and the cartpole simulation just flies off into endless space (as expected).
TL;DR: What is the proper way to obtain the continuous state vector in a custom controller extending LeafSystem with a DeclareVectorOutputPort?
Thank you for any help! I really appreciate it :) I've been teaching myself so it's been a little arduous haha.
# Combined Energy Shaping (SwingUp) and LQR (Balance) Controller
# with a simple state machine
class SwingUpAndBalanceController(LeafSystem):
def __init__(self, cart_pole, cart_pole_context, input_i, ouput_i, Q, R, x_star):
LeafSystem.__init__(self)
self.DeclareAbstractInputPort("state_input", AbstractValue.Make(FramePoseVector()))
self.DeclareVectorOutputPort("control_signal", BasicVector(1),
self.OutputControlSignal)
(self.K, self.S) = BalancingLQRCtrlr(cart_pole, cart_pole_context,
input_i, ouput_i, Q, R, x_star).get_LQR_matrices()
(self.A, self.B, self.C, self.D) = BalancingLQRCtrlr(cart_pole, cart_pole_context,
input_i, ouput_i,
Q, R, x_star).get_lin_matrices()
self.energy_shaping = EnergyShapingCtrlr(cart_pole, x_star)
self.energy_shaping_context = self.energy_shaping.CreateDefaultContext()
self.cart_pole_context = cart_pole_context
def OutputControlSignal(self, context, output):
#xbar = copy(self.cart_pole_context.get_continuous_state_vector())
xbar = copy(context.get_continuous_state_vector())
xbar_ = np.array([xbar[0], xbar[1], xbar[2], xbar[3]])
xbar_[1] = wrap_to(xbar_[1], 0, 2.0*np.pi) - np.pi
# If x'Sx <= 2, then use LQR ctrlr. Cost-to-go J_star = x^T * S * x
threshold = np.array([2.0])
if (xbar_.dot(self.S.dot(xbar_)) < 2.0):
#output[:] = -self.K.dot(xbar_) # u = -Kx
output.set_value(-self.K.dot(xbar_))
else:
self.energy_shaping.get_input_port(0).FixValue(self.energy_shaping_context,
self.cart_pole_context.get_continuous_state_vector())
output_val = self.energy_shaping.get_output_port(0).Eval(self.energy_shaping_context)
output.set_value(output_val)
print(output)
Here are two things that might help:
If you want to get the state of the cart-pole from MultibodyPlant, you probably want to be connecting to the continuous_state output port, which gives you a normal vector instead of the abstract-type FramePoseVector. In that case, your call to get_input_port().Eval(context) should work just fine.
If you do really want to read the FramePoseVector, then you have to evaluate the input port slightly differently. You can find an example of that here.

Use *.pth model in C++

I want to run inference in C++ using a yolo3 model I trained with pytorch. I am unable to make the conversions using tracing and scripting provided by pytorch. I have this error during conversion
First diverging operator:
Node diff:
- %2 : __torch__.torch.nn.modules.container.ModuleList = prim::GetAttr[name="module_list"](%self.1)
+ %2 : __torch__.torch.nn.modules.container.___torch_mangle_139.ModuleList = prim::GetAttr[name="module_list"](%self.1)
? ++++++++++++++++++++
ERROR: Tensor-valued Constant nodes differed in value across invocations. This often indicates that the tracer has encountered untraceable code.
Node:
%358 : Tensor = prim::Constant[value=<Tensor>](), scope: __module.module_list.16.yolo_16

what is the value of mlflow nested runs?

What is the value of nested runs in mlflow? I thought it would be that a child run inherits params of the parent, but I dont see that
with mlflow.start_run(run_name='myrun'):
mlflow.log_param('kl', '0p0')
mlflow.log_param('name', 'ios')
mlflow.log_metric('mu', 1.0)
with mlflow.start_run(run_name='myrun2', nested=True):
mlflow.log_param('name', 'weighted')
mlflow.log_metric('mu', 2.0)
if I collect the run info in python
df = mlflow.search_runs()
then we have
df['params.kl']
giving
0 None
1 0p0
Name: params.kl, dtype: object
From my understanding, the reason for nested runs are to track a collection of model training within a single run. This would have the structure: experiment --> run 1, run 2, run 3, ... --> run 1-1, run 1-2, run 2-1, run 2-2, run 3-1, run 3-2,...
In other words, the parent/outer mlflow.start_run generates a mlflow experiment entry (first-level run); the child/nested mlflow.start_run generates run-entry (second-level run).

Bulbs: How to check if two vertices are connected by an edge in Titan

I am using TitanGraphDB + Cassandra.I am starting Titan as follows
cd titan-cassandra-0.3.1
bin/titan.sh config/titan-server-rexster.xml config/titan-server-cassandra.properties
I have a Rexster shell that I can use to communicate to Titan+Cassandra above.
cd rexster-console-2.3.0
bin/rexster-console.sh
I am attempting to model a network topology using Titan Graph DB.I want to program the Titan Graph DB from my python program.I am using bulbs package for that.
I create three types of vertices
- switch
- port
- device
I create labelled edges between ports that are connected physically.The label that I use is "link".
Let us say I have two port vertices portA and portB.
I want to write a function as below
def is_connected(portA, portB):
...
...
...
How do I find if two vertices are "connected by a labelled edge"?
I have two graph vertices
src_sw_other_ports
<Vertex: http://localhost:8182/graphs/graph/vertices/48>
dst_sw_other_ports
<Vertex: http://localhost:8182/graphs/graph/vertices/72>
I have tried
link_exists = src_sw_other_ports.out.retain([dst_sw_other_ports]).hasNext()
It is giving me the following error.
File "/home/karthik/Projects/ryu/ryu/app/simple_switch.py", line 238, in compute_path
link_exists = src_sw_other_ports.out.retain([dst_sw_other_ports]).hasNext()
File "/usr/local/lib/python2.7/dist-packages/bulbs/element.py", line 209, in __getattr__
raise AttributeError(name)
AttributeError: out
espeed's answer is good. Here's another alternative:
gremlin> g = TinkerGraphFactory.createTinkerGraph()
==>tinkergraph[vertices:6 edges:6]
gremlin> v1 = g.v(1)
==>v[1]
gremlin> v3 = g.v(3)
==>v[3]
gremlin> v6 = g.v(6)
==>v[6]
gremlin> v1.out.retain([v3]).hasNext()
==>true
gremlin> v1.out.retain([v6]).hasNext()
==>false
A little better than using count as if you just want "existence" of an edge, you don't have to iterate the entire pipe to do so.
def is_connected(portA, portB):
return portA.both("link").retain([portB]).hasNext()
See http://gremlindocs.com/#recipes/finding-edges-between-vertices
NB: I used your function definition in the code above; however, your function definition uses Python syntax, not Groovy, so the above example will only work if you are calling the Gremlin code from Jython.
The Gremlin-Groovy definition would be:
def isConnected (portA, portB) {
return portA.both("link").retain([portB]).hasNext()
}

actions=[[type=ACTION_OUTPUT action=[port=1 maxLen=0]];], as keywords to get_or_create in Bulbs

I am using TitanGraphDB + Cassandra.I am starting Titan as follows
cd titan-cassandra-0.3.1
bin/titan.sh config/titan-server-rexster.xml config/titan-server-cassandra.properties
I have a Rexster shell that I can use to communicate to Titan+Cassandra above.
cd rexster-console-2.3.0
bin/rexster-console.sh
I want to program the Titan Graph DB from my python program.I am using bulbs package for that.
I create a vertex from python using bulbs as given below.
fe1 = self.g.vertices.get_or_create('switch_dpid',switch_dpid,
{'actionOutputPort':actionOutputPort,
'switch_state':'FE_SWITCH_UPDATED',
'matchInPort': MatchInPort,
'type': 'flow_entry',
'user_state':'FE_USER_ADD',
'actions': ['type':'ACTION_OUTPUT', 'action':[port=actionOutputPort maxLen=0];]})
This is giving me an error
'actions': ['type':'ACTION_OUTPUT', 'action':[port=actionOutputPort maxLen=0];]})
SyntaxError: invalid syntax
The output that I would expect from the Rexster console is as follows.
switch_dpid=00:00:00:00:00:00:02:05,
actionOutputPort=1,
switch_state=FE_SWITCH_UPDATED,
matchInPort=2,
flow_entry_id=0x4ee30a9400000012,
type=flow_entry,
actions=[[type=ACTION_OUTPUT action=[port=1 maxLen=0]];],
user_state=FE_USER_ADD
How do I program actions so that it is as above.?
You're mixing up Groovy syntax with Python.
actions is a dictionary and action is a dictionary so in Python it should be:
'actions': {'type': 'ACTION_OUTPUT',
'action': {port: actionOutputPort,
maxLen: 0}}
Note it is usually more convenient (less quotes) to create Python dictionaries using the dict function:
'actions' = dict(type = 'ACTION_OUTPUT',
action = dict(port = actionOutputPort,
maxLen = 0))

Resources