cvxgrp / qcml

A Python parser for generating Python/C/Matlab solver interfaces
Other
42 stars 9 forks source link

TypeError: 'NotImplementedType' object is not callable, in codegen("C") #42

Closed alexvoronov closed 10 years ago

alexvoronov commented 10 years ago

Hi,

I get the following error when running codegen for C:

Traceback (most recent call last):
  File "bug_report.py", line 13, in <module>
    p.codegen("C")
  File "/usr/local/lib/python2.7/site-packages/qcml/helpers.py", line 29, in wrap
    result = func(*args, **kwargs)
  File "/usr/local/lib/python2.7/site-packages/qcml/qc_lang.py", line 103, in codegen
    self.__codegen.codegen()
  File "/usr/local/lib/python2.7/site-packages/qcml/codegens/base_codegen.py", line 132, in codegen
    self.prob2socp.create()
  File "/usr/local/lib/python2.7/site-packages/qcml/codes/function.py", line 86, in create
    self.__source = self._generate_source(self.code)
  File "/usr/local/lib/python2.7/site-packages/qcml/codes/function.py", line 92, in code
    body = list(chain.from_iterable(self.__body))
  File "/usr/local/lib/python2.7/site-packages/qcml/codes/function.py", line 67, in <genexpr>
    self.__body.append("{:}{:}".format(self.indent, line).rstrip() for line in iterable_line(lines))
  File "/usr/local/lib/python2.7/site-packages/qcml/codegens/C/codegen.py", line 315, in stuff_c
    yield "for(i = 0; i < %s; ++i) data->c[i + %s] = %s%s" % (end-start, start, toC(expr), tag)
  File "/usr/local/lib/python2.7/site-packages/qcml/codes/encoders/encoder.py", line 6, in encode
    return lookup[x.__class__](x)
TypeError: 'NotImplementedType' object is not callable

It might be related to #41, since minimal example where I get it is the same:

#!/usr/bin/env python
from qcml import QCML

if __name__ == '__main__':

    s = ("""variables x(2)
    minimize sum(3*x)""")

    p = QCML()
    p.parse(s)

    p.canonicalize()
    p.codegen("C")
echu commented 10 years ago

Thanks! I'll take a look at this,

Eric

On Mon, Jun 23, 2014 at 3:33 AM, alexvoronov notifications@github.com wrote:

Hi,

I get the following error when running codegen for C:

Traceback (most recent call last): File "bug_report.py", line 13, in p.codegen("C") File "/usr/local/lib/python2.7/site-packages/qcml/helpers.py", line 29, in wrap result = func(_args, *_kwargs) File "/usr/local/lib/python2.7/site-packages/qcml/qc_lang.py", line 103, in codegen self.codegen.codegen() File "/usr/local/lib/python2.7/site-packages/qcml/codegens/base_codegen.py", line 132, in codegen self.prob2socp.create() File "/usr/local/lib/python2.7/site-packages/qcml/codes/function.py", line 86, in create self.__source = self._generate_source(self.code) File "/usr/local/lib/python2.7/site-packages/qcml/codes/function.py", line 92, in code body = list(chain.from_iterable(self.body)) File "/usr/local/lib/python2.7/site-packages/qcml/codes/function.py", line 67, in self.__body.append("{:}{:}".format(self.indent, line).rstrip() for line in iterable_line(lines)) File "/usr/local/lib/python2.7/site-packages/qcml/codegens/C/codegen.py", line 315, in stuff_c yield "for(i = 0; i < %s; ++i) data->c[i + %s] = %s%s" % (end-start, start, toC(expr), tag) File "/usr/local/lib/python2.7/site-packages/qcml/codes/encoders/encoder.py", line 6, in encode return lookupx.class TypeError: 'NotImplementedType' object is not callable

It might be related to #41 https://github.com/cvxgrp/qcml/issues/41, since minimal example where I get it is the same:

!/usr/bin/env python

from qcml import QCML

if name == 'main':

s = ("""variables x(2)
minimize sum(3*x)""")

p = QCML()
p.parse(s)

p.canonicalize()
p.codegen("C")

— Reply to this email directly or view it on GitHub https://github.com/cvxgrp/qcml/issues/42.

echu commented 10 years ago

Okay, give it a shot now; I should have fixed it.

Eric

On Mon, Jun 23, 2014 at 8:09 AM, Eric Chu eytchu@gmail.com wrote:

Thanks! I'll take a look at this,

Eric

On Mon, Jun 23, 2014 at 3:33 AM, alexvoronov notifications@github.com wrote:

Hi,

I get the following error when running codegen for C:

Traceback (most recent call last): File "bug_report.py", line 13, in p.codegen("C") File "/usr/local/lib/python2.7/site-packages/qcml/helpers.py", line 29, in wrap result = func(_args, *_kwargs) File "/usr/local/lib/python2.7/site-packages/qcml/qc_lang.py", line 103, in codegen self.codegen.codegen() File "/usr/local/lib/python2.7/site-packages/qcml/codegens/base_codegen.py", line 132, in codegen self.prob2socp.create() File "/usr/local/lib/python2.7/site-packages/qcml/codes/function.py", line 86, in create self.__source = self._generate_source(self.code) File "/usr/local/lib/python2.7/site-packages/qcml/codes/function.py", line 92, in code body = list(chain.from_iterable(self.body)) File "/usr/local/lib/python2.7/site-packages/qcml/codes/function.py", line 67, in self.__body.append("{:}{:}".format(self.indent, line).rstrip() for line in iterable_line(lines)) File "/usr/local/lib/python2.7/site-packages/qcml/codegens/C/codegen.py", line 315, in stuff_c yield "for(i = 0; i < %s; ++i) data->c[i + %s] = %s%s" % (end-start, start, toC(expr), tag) File "/usr/local/lib/python2.7/site-packages/qcml/codes/encoders/encoder.py", line 6, in encode return lookupx.class TypeError: 'NotImplementedType' object is not callable

It might be related to #41 https://github.com/cvxgrp/qcml/issues/41, since minimal example where I get it is the same:

!/usr/bin/env python

from qcml import QCML

if name == 'main':

s = ("""variables x(2)
minimize sum(3*x)""")

p = QCML()
p.parse(s)

p.canonicalize()
p.codegen("C")

— Reply to this email directly or view it on GitHub https://github.com/cvxgrp/qcml/issues/42.

alexvoronov commented 10 years ago

Thanks Eric, now it works with a vector. It does not work with a matrix though:

#!/usr/bin/env python
from qcml import QCML

if __name__ == '__main__':

    s = ("""variable x(2)
        parameter D(2,2)
        minimize sum(D*x)""")

    p = QCML(debug=False)
    p.parse(s)

    p.canonicalize()
    p.codegen("C")

results in

...
  File "/usr/local/lib/python2.7/site-packages/qcml/codegens/C/codegen.py", line 315, in stuff_c
    yield "for(i = 0; i < %s; ++i) data->c[i + %s] = %s%s" % (end-start, start, toC(expr), tag)
  File "/usr/local/lib/python2.7/site-packages/qcml/codes/encoders/encoder.py", line 7, in encode
    return lookup[x.__class__](x)
TypeError: 'NotImplementedType' object is not callable
echu commented 10 years ago

okay. i pushed something; give it a shot and let me know if it works.

eric

On Mon, Jun 23, 2014 at 1:30 PM, alexvoronov notifications@github.com wrote:

Thanks Eric, now it works with a vector. It does not work with a matrix though:

!/usr/bin/env python

from qcml import QCML

if name == 'main':

s = ("""variable x(2)
    parameter D(2,2)
    minimize sum(D*x)""")

p = QCML(debug=False)
p.parse(s)

p.canonicalize()
p.codegen("C")

results in

... File "/usr/local/lib/python2.7/site-packages/qcml/codegens/C/codegen.py", line 315, in stuff_c yield "for(i = 0; i < %s; ++i) data->c[i + %s] = %s%s" % (end-start, start, toC(expr), tag) File "/usr/local/lib/python2.7/site-packages/qcml/codes/encoders/encoder.py", line 7, in encode return lookupx.class TypeError: 'NotImplementedType' object is not callable

— Reply to this email directly or view it on GitHub https://github.com/cvxgrp/qcml/issues/42#issuecomment-46897692.

alexvoronov commented 10 years ago

Thanks a lot, now codegen produces the output! But it seems like the output of the codegen is not entirely perfect. For the example above, it uses undeclared variable result, here is a snippet:

    /* allocate A matrix */
    nnzA = 1*result->nnz + 2;

So when I try to compile it, I get a compilation error:

error: use of undeclared identifier 'result'

Am I missing some include that has this result declared somewhere globally, or is it just the declaration of a qc_matrix result = ... missing in the beginning of the function? I looked through generated code for python to get inspiration how such matrix can look like, but there is no result variable in Python...

Alex

echu commented 10 years ago

sorry for the slow response, i've been traveling.

so, what's your problem spec? on that same line, i have

1*params->D->nnz + 2;

On Fri, Jun 27, 2014 at 7:52 AM, alexvoronov notifications@github.com wrote:

Thanks a lot, now codegen produces the output! But it seems like the output of the codegen is not entirely perfect. For the example above, it uses undeclared variable result, here is a snippet:

/* allocate A matrix */
nnzA = 1**result*->nnz + 2;

So when I try to compile it, I get a compilation error:

error: use of undeclared identifier 'result'

Am I missing some include that has this result declared somewhere globally, or is it just the declaration of a qc_matrix result = ... missing in the beginning of the function? I looked through generated code for python to get inspiration how such matrix can look like, but there is no result variable in Python...

Alex

— Reply to this email directly or view it on GitHub https://github.com/cvxgrp/qcml/issues/42#issuecomment-47354760.

alexvoronov commented 10 years ago

Very strange... I will open a new issue and post my source and generated code there