I am trying to modify a model by adding variables/constraints and re-solving the updated model, following the guide.
The problem is that both cases fail with attribute errors, for a variable:
Traceback (most recent call last):
File "seqdesign.py", line 98, in <module>
main()
File "seqdesign.py", line 71, in main
problem._solver.add_var(problem._model.McBernoulliTrials)
File "/home/edo/miniconda3/envs/spacers/lib/python3.7/site-packages/pyomo/solvers/plugins/solvers/persistent_solver.py", line 153, in add_var
self._add_var(var)
File "/home/edo/miniconda3/envs/spacers/lib/python3.7/site-packages/pyomo/solvers/plugins/solvers/gurobi_direct.py", line 208, in _add_var
vtype = self._gurobi_vtype_from_var(var)
File "/home/edo/miniconda3/envs/spacers/lib/python3.7/site-packages/pyomo/solvers/plugins/solvers/gurobi_direct.py", line 377, in _gurobi_vtype_from_var
if var.is_binary():
AttributeError: 'IndexedVar' object has no attribute 'is_binary'
And for a constraint:
Traceback (most recent call last):
File "seqdesign.py", line 98, in <module>
main()
File "seqdesign.py", line 71, in main
problem._solver.add_constraint(problem._model.McBernoulliTrialsSetPositive)
File "/home/edo/miniconda3/envs/spacers/lib/python3.7/site-packages/pyomo/solvers/plugins/solvers/persistent_solver.py", line 132, in add_constraint
self._add_constraint(con)
File "/home/edo/miniconda3/envs/spacers/lib/python3.7/site-packages/pyomo/solvers/plugins/solvers/gurobi_direct.py", line 272, in _add_constraint
if is_fixed(con.body):
AttributeError: 'IndexedConstraint' object has no attribute 'body'
Is the problem that I am using indexed variables and constraints? How to make this work without migrating all code from pyomo.environ to pyomo.core?
You cannot pass an IndexedVar or and IndexedConstraint into the add_var and add_constraint methods. You have to loop over the individual variables and constraints and add them one at a time:
for v in my_var.values():
solver.add_var(v)
for c in my_con.values():
solver.add_constraint(c)
Additionally, you can check if a variable or constraint is indexed with my_var.is_indexed() or my_con.is_indexed().
Related
I am running the code from this repository Link with dgl==0.1.3 and I am facing this error. I am not sure why its coming. I have attached the code snippet and the error below.
code snippet
def _prepare_subgraphs(self, nodes, r_label, n_labels):
subgraph = dgl.DGLGraph(self.graph.subgraph(nodes))
Error
Traceback (most recent call last):
File "train.py", line 222, in <module>
main(params)
File "train.py", line 32, in main
kge_model=params.kge_model, file_name=params.train_file)
File "/home2/harsha.vasamsetti/SumGNN-master_olddgl/subgraph_extraction/datasets.py", line 142, in __init__
self.__getitem__(0)
File "/home2/harsha.vasamsetti/SumGNN-master_olddgl/subgraph_extraction/datasets.py", line 150, in __getitem__
subgraph_pos = self._prepare_subgraphs(nodes_pos, r_label_pos, n_labels_pos)
File "/home2/harsha.vasamsetti/SumGNN-master_olddgl/subgraph_extraction/datasets.py", line 159, in _prepare_subgraphs
subgraph = dgl.DGLGraph(self.graph.subgraph(nodes))
File "/home2/harsha.vasamsetti/.miniconda3/envs/sumgnn=0.1.3/lib/python3.7/site-packages/dgl/graph.py", line 181, in __init__
self._graph = create_graph_index(graph_data, multigraph, readonly)
File "/home2/harsha.vasamsetti/.miniconda3/envs/sumgnn=0.1.3/lib/python3.7/site-packages/dgl/graph_index.py", line 925, in create_graph_index
% type(graph_data))
dgl._ffi.base.DGLError: Error while creating graph from input of type "<class 'dgl.subgraph.DGLSubGraph'>".
When I run python on cmd I get this weird error:
Failed calling sys.__interactivehook__
Traceback (most recent call last):
File "C:\Users\Khaled\AppData\Local\Programs\Python\Python310\lib\site.py", line 446, in register_readline
import readline
File "C:\Users\Khaled\AppData\Local\Programs\Python\Python310\lib\site-packages\readline.py", line 34, in <module>
rl = Readline()
File "C:\Users\Khaled\AppData\Local\Programs\Python\Python310\lib\site-packages\pyreadline\rlmain.py", line 422, in __init__
BaseReadline.__init__(self)
File "C:\Users\Khaled\AppData\Local\Programs\Python\Python310\lib\site-packages\pyreadline\rlmain.py", line 62, in __init__
mode.init_editing_mode(None)
File "C:\Users\Khaled\AppData\Local\Programs\Python\Python310\lib\site-packages\pyreadline\modes\emacs.py", line 633, in init_editing_mode
self._bind_key('space', self.self_insert)
File "C:\Users\Khaled\AppData\Local\Programs\Python\Python310\lib\site-packages\pyreadline\modes\basemode.py", line 162, in _bind_key
if not callable(func):
File "C:\Users\Khaled\AppData\Local\Programs\Python\Python310\lib\site-packages\pyreadline\py3k_compat.py", line 8, in callable
return isinstance(x, collections.Callable)
AttributeError: module 'collections' has no attribute 'Callable'
But then I continue using python normally:
>>>
I did not find any effects of this problem python is running normally but I do not want it to appear and to know what does it do.
I'm having a problem with deleting ADUser.
pyad.set_defaults(ldap_server="dc1.domain.com", username="service_account", password="mypassword")
user = aduser.ADUser.from_dn("cn=myuser, ou=staff, dc=domain, dc=com")
user.delete()
Unfortunately I could not figure out how to format this text to look like a real traceback
Traceback (most recent call last):
File "C:/Automation/qa/robot2/python_lib/keywords/AD/unittest.py", line 34,
in <module>
ad_connect.bg_ad_user_remove(user_login='vasya.oconnor#test-acme.com',dn_string= dn_string)
File "C:\Automation\qa\robot2\python_lib\keywords\AD\_bg_ad_general.py", line 156, in bg_ad_user_remove
user.delete()
File "C:\Python27\lib\site-packages\pyad\adobject.py", line 537, in delete
if not parent:
File "C:\Python27\lib\site-packages\future\types\newobject.py", line 90, in __nonzero__
return type(self).__len__(self)
AttributeError: type object 'ADContainer' has no attribute '__len__'
I am trying to setup openstack dynamic inventory,when I am trying execute this command it's throwing me this error.
command: etc/ansible/hosts --list
Traceback (most recent call last):
File "/etc/ansible/hosts", line 263, in <module>
main()
File "/etc/ansible/hosts", line 249, in main
inventory = shade.inventory.OpenStackInventory(**inventory_args)
File "/usr/local/lib/python2.7/dist-packages/shade/inventory.py", line 35, in __init__
config_files=os_client_config.config.CONFIG_FILES + config_files)
File "/usr/local/lib/python2.7/dist-packages/os_client_config/config.py", line 221, in __init__
self.cloud_config['clouds'] = {}
TypeError: list indices must be integers, not str
By using biopython library, I would like to add chains ids in my pdb file.
I'm using
p = PDBParser()
structure=p.get_structure('mypdb',mypdb.pdb)
model=structure[0]
model.child_list=["A","B"]
But I got this error:
Traceback (most recent call last):
File "../../principal_axis_v3.py", line 319, in <module>
main()
File "../../principal_axis_v3.py", line 310, in main
protA=read_PDB(struct,ch1,s1,e1)
File "../../principal_axis_v3.py", line 104, in read_PDB
chain=model[ch]
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/Bio/PDB/Entity.py", line 38, in __getitem__
return self.child_dict[id]
KeyError: 'A'
I tried to changes the keys in th child.dict, butI got another error:
Traceback (most recent call last):
File "../../principal_axis_v3.py", line 319, in <module>
main()
File "../../principal_axis_v3.py", line 310, in main
protA=read_PDB(struct,ch1,s1,e1)
File "../../principal_axis_v3.py", line 102, in read_PDB
model.child_dict.keys=["A","B"]
AttributeError: 'dict' object attribute 'keys' is read-only
How can I add chains ids ?
Your error is that child_list is not a list with chain IDs, but of Chain objects (Bio.PDB.Chain.Chain). You have to create Chain objects and then add them to the structure. A lame example:
from Bio.PDB.Chain import Chain
my_chain = Chain("C")
model.add(my_chain)
Now you can access the model child_dict:
>>> model.child_dict
{'A': <Chain id=A>, 'C': <Chain id=C>}
>>> model.child_dict["C"]
<Chain id=C>