Runtime Error while using the class:SellarMDAPromoteConnect, as given in the OpenMDAO tutorial - connect

I am just getting started with the tutorials of OpenMDAO, I was trying out the Sellar - A Two-Discipline Problem with a Nonlinear Solver tutorial and soon ran into an error. There are three ways included in the website to promote and connect input-output variables, the third method titled "Variable Promotion and Connect Statements" has the class named SellarMDAPromoteConnect. When I try to run the optimization setup, the code throws a runtime error
<model> <class SellarMDAPromoteConnect>: Output not found for response 'obj'
I ran the following in the console:
!openmdao check -c all <_file name_>.py
which shows the first error:
File "D:\softwares\anaconda\anaconda3\lib\site-packages\openmdao\core\system.py", line 3250, in get_responses
key = in_abs = prom2abs_in[name][0]
KeyError: 'obj'
Can anyone kindly explain why this error pops up and how to fix it while using the same class SellarMDAPromoteConnect? I cannot come up with any convincing reason(s) to explain this error. Every line of the code I used is same as given in the website (link attached here), I have attached a screenshot of the code snippet used to run the optimization problem setup, just incase you want to have a look at it
Optimization setup code snippet

Your run script has a namespace detail incorrect. The example you pulled from used a mixture of promotion and connection to be illustrative. The obj variable is computed and owned by the obj_cmp ExecComp. Only two of the inputs (x and z) were promoted. The other two inputs (y1 and y2) were not and neither was the output objective (obj).
To add the objective you would do the following:
# prob.model.add_objective('obj') # wrong scope
prob.model.add_objective('obj_cmp.obj') # correct scope
There are a few ways to easily determine the correct names for variables:
Use the list_outputs method on a group that owns the variables in question.
prob.model.list_outputs(prom_name=True)
gives:
varname val prom_name
-------- ---- -------------
cycle
d1
y1 [1.] d1.y1
d2
y2 [1.] d2.y2
obj_cmp
obj [1.] obj_cmp.obj
con_cmp1
con1 [1.] con_cmp1.con1
con_cmp2
con2 [1.] con_cmp2.con2
If you prefer a more visual layout, the N2 also has the information you want:

Related

Snakemake: Parameter as wildcard used in parallel script runs

I'm fairly new to snakemake and inherited a kind of huge worflow that consists in a sequence of 17 rules that run in serial.
Each rule takes outputs from the previous rules and uses them to run a python script. Everything has worked great so far except that now I'm trying to improve the worflow since some of the rules can be run in parallel.
A rough example of what I'm trying to achieve, my understanding is that wildcards should allow me to solve this.
grid = [ 10 , 20 ]
rule all:
input:
expand("path/to/C/{grid}/file_C" ,grid = grid)
rule process_A:
input:
path_A = "path/to/A/file_A"
path_B = "path/to/B/{grid}/file_B" # A rule further in the worflow could need a file from a previous rule saved with this structure
params:
grid = lambda wc: wc.get(grid)
output:
path_C = "path/to/C/{grid}/file_C"
script:
"script_A.py"
And inside the script I retrieve the grid size parameter:
grid = snakemake.params.grid
In the end the whole rule process_A should be rerun with grid = 10 and with grid = 20 and save each result to a folder whose path depends on grid also.
I know there are several things wrong with this, but I can't seem to find were to start from to figure this out. The error I'm getting now is:
name 'params' is not defined
Any help as to where to start from?
It would be useful to post the error stack trace of name 'params' is not defined to know exactly what is causing it. For now...
And inside the script I retrieve the grid size parameter:
grid = snakemake.params.grid
I suspect you are mixing the script directive with the shell directive. Probably you want something like:
rule process_A:
input: ...
output: ...
params: ...
script:
"script_A.py"
inside script_A.py snakemake will replace snakemake.params.grid with the actual param value.
Alternatively, write a standalone python script that parses command line arguments and you execute like any other program using the shell directive. (I tend to prefer this solution as it makes things more explicit and easier to debug but it also means more boiler-plate code to write a standalone script).

How to merge nodes and relationships using py2neo v4 and Neo4j

I am trying to perform a basic merge operation to add nonexistent nodes and relationships to my graph by going through a csv file row by row. I'm using py2neo v4, and because there is basically no documentation or examples of how to use py2neo, I can't figure out how to actually get it done. This isn't my real code (it's very complicated to handle many different cases) but its structure is basically like this:
import py2neo as pn
graph = pn.Graph("bolt://localhost:###/", user="neo4j", password="py2neoSux")
matcher = pn.NodeMatcher(graph)
tx = graph.begin()
if (matcher.match("Prefecture", name="foo").first()) == None):
previousNode = pn.Node("Type1", name="fo0", yc=1)
else:
previousNode = matcher.match("Prefecture", name="foo").first())
thisNode = pn.Node("Type2", name="bar", yc=1)
tx.merge(previousNode)
tx.merge(thisNode)
theLink = pn.Relationship(thisNode, "PARTOF", previousNode)
tx.merge(theLink)
tx.commit()
Currently this throws the error
ValueError: Primary label and primary key are required for MERGE operation
the first time it needs to merge a node that it hasn't found (i.e., when creating a node). So then I change the line to:
tx.merge(thisNode,primary_label=list(thisNode.labels)[0], primary_key="name")
Which gives me the error IndexError: list index out of range from somewhere deep in the py2neo source code (....site-packages\py2neo\internal\operations.py", line 168, in merge_subgraph at node = nodes[i]). I tried to figure out what was going wrong there, but I couldn't decipher where the nodes list come from through various connections to other commands.
So, it currently matches and creates a few nodes without problem, but at some point it will match until it needs to create and then fails in trying to create that node (even though it is using the same code and doing the same thing under the same circumstances in a loop). It made it through all 20 rows in my sample once, but usually stops on the row 3-5.
I thought it had something to do with the transactions (see comments), but I get the same problem when I merge directly on the graph. Maybe it has to do with the py2neo merge function finding more identities for nodes than nodes. Maybe there is something wrong with how I specified my primarily label and/or key.
Because this error and code are opaque I have no idea how to move forward.
Anybody have any advice or instructions on merging nodes with py2neo?
Of course I'd like to know how to fix my current problem, but more generally I'd like to learn how to use this package. Examples, instructions, real documentation?
I am having a similar problem and just got done ripping my hair out to figure out what was wrong! SO! What I learned was that at least in my case.. and maybe yours too since we got similar error messages and were doing similar things. The problem lied for me in that I was trying to create a Node with a __primarykey__ field that had a different field name than the others.
PSEUDO EXAMPLE:
# in some for loop or complex code
node = Node("Example", name="Test",something="else")
node.__primarykey__ = "name"
<code merging or otherwise creating the node>
# later on in the loop you might have done something like this cause the field was null
node = Node("Example", something="new")
node.__primarykey__ = "something"
I hope this helps and was clear I'm still recovering from wrapping my head around things. If its not clear let me know and I'll revise.
Good luck.

Take mean of feature set using openSMILE audio feature extractor

My problem is taking mean of all features from different frames in one sample .wav file. I am trying cFunctionals in "chroma_fft.conf" file which belongs to latest OpenEar framework. For best explanation, i am writing these essential codes which i wrote in "chroma_fft.conf" and it is shown below;
[componentInstances:cComponentManager]
instance[functL1].type = cFunctionals
[functL1:cFunctional]
reader.dmLevel = chroma
writer.dmLevel = func
frameMode = full
frameSize=0
frameStep=0
functionalsEnabled = Means
Means.amean = 1
[csvSink:cCsvSink]
reader.dmLevel = func
..NOT-IMPORTANT......
..NOT-IMPORTANT......
However, when i run from command prompt in windows, i got error;
"(ERROR) [1] in configManager : base instance of field 'functL1.reader.dmInstance' not found in configmanager!"
Very similar code is running succesfully from "emo_large.conf" but this code got error. If any body knows how to use OpenSmile audio feature extractor, can give advice or answer why it has error and how to use "cFunctionals" properly to take mean, variance, moments etc. of large feature sets.
Thanks!
In this case you have a typo in
[functL1:cFunctional]
which should be
[functL1:cFunctionals]
I admit the error message
"(ERROR) [1] in configManager : base instance of field 'functL1.reader.dmInstance' not found in configmanager!"
is not intutive, but it refers to the fact that openSMILE expects a configuration section functL1 of type cFunctionals in the config to read the mandatory (sub-)field functL1.reader.dmInstance, which it then cannot find, because the section (due to the typo) is not defined.
Cheers,
Florian

2 Sequential Transactions, setting Detail Number (Revit API / Python)

Currently, I made a tool to rename view numbers (“Detail Number”) on a sheet based on their location on the sheet. Where this is breaking is the transactions. Im trying to do two transactions sequentially in Revit Python Shell. I also did this originally in dynamo, and that had a similar fail , so I know its something to do with transactions.
Transaction #1: Add a suffix (“-x”) to each detail number to ensure the new numbers won’t conflict (1 will be 1-x, 4 will be 4-x, etc)
Transaction #2: Change detail numbers with calculated new number based on viewport location (1-x will be 3, 4-x will be 2, etc)
Better visual explanation here: https://www.docdroid.net/EP1K9Di/161115-viewport-diagram-.pdf.html
Py File here: http://pastebin.com/7PyWA0gV
Attached is the python file, but essentially what im trying to do is:
# <---- Make unique numbers
t = Transaction(doc, 'Rename Detail Numbers')
t.Start()
for i, viewport in enumerate(viewports):
setParam(viewport, "Detail Number",getParam(viewport,"Detail Number")+"x")
t.Commit()
# <---- Do the thang
t2 = Transaction(doc, 'Rename Detail Numbers')
t2.Start()
for i, viewport in enumerate(viewports):
setParam(viewport, "Detail Number",detailViewNumberData[i])
t2.Commit()
Attached is py file
As I explained in my answer to your comment in the Revit API discussion forum, the behaviour you describe may well be caused by a need to regenerate between the transactions. The first modification does something, and the model needs to be regenerated before the modifications take full effect and are reflected in the parameter values that you query in the second transaction. You are accessing stale data. The Building Coder provides all the nitty gritty details and numerous examples on the need to regenerate.
Summary of this entire thread including both problems addressed:
http://thebuildingcoder.typepad.com/blog/2016/12/need-for-regen-and-parameter-display-name-confusion.html
So this issue actually had nothing to do with transactions or doc regeneration. I discovered (with some help :) ), that the problem lied in how I was setting/getting the parameter. "Detail Number", like a lot of parameters, has duplicate versions that share the same descriptive param Name in a viewport element.
Apparently the reason for this might be legacy issues, though im not sure. Thus, when I was trying to get/set detail number, it was somehow grabbing the incorrect read-only parameter occasionally, one that is called "VIEWER_DETAIL_NUMBER" as its builtIn Enumeration. The correct one is called "VIEWPORT_DETAIL_NUMBER". This was happening because I was trying to get the param just by passing the descriptive param name "Detail Number".Revising how i get/set parameters via builtIn enum resolved this issue. See images below.
Please see pdf for visual explanation: https://www.docdroid.net/WbAHBGj/161206-detail-number.pdf.html

Error in get("hulls2iso.rgeos", 1) : object 'hulls2iso.rgeos' not found

I created an lhs object using the function as follows:
am321.lhs <- lxy.lhs(am321.lxy.every4th, k=24, s=0.07, kmin=12, save.hulls=TRUE)
However, when I try to create isopleths by the following call I get an error. I have pasted the console output below:
am321.lhs <- lhs.iso.add(am321.lhs)
Using nearest-neighbor selection mode: Fixed-k
Constructing hulls and hull metrics...
am321.pts26934.k24.s0.07.kmin12
Found a suitable set of nearest neighbors
Identifying the boundary points for each parent point
|++++++++++++++++++++++++++++++++++++++++++++++++++| 100%
Converting boundary points into polygons
|++++++++++++++++++++++++++++++++++++++++++++++++++| 100%
Calculating area and perimeter...Done.
Calculating the time span of each hull...Done.
Identifying enclosed points...Done.
Computing density isopleths
Error in get("hulls2iso.rgeos", 1) : object 'hulls2iso.rgeos' not found
I would be grateful for any help on this.
Thank you
Karpa
I encountered the same error recently and got the following advice from Andy Lyons:
You've encountered a bug in the package. Please update the package to version 1.40 (or later), and it should work.
Check package version
packageVersion("tlocoh")
Update package (if the package is already loaded, you may need to detach it or restart R to update)
update.packages(oldPkgs="tlocoh", repos="http://R-Forge.R-project.org")

Resources