Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Examples not running on Python 3.6 #57

Open
douglase opened this issue May 10, 2018 · 1 comment
Open

Examples not running on Python 3.6 #57

douglase opened this issue May 10, 2018 · 1 comment

Comments

@douglase
Copy link

The following code works in Python 2.7 on in macOS 10.13:

y=np.ones([n,n])
x=2*np.ones([n,n])
z=1
out=np.ones_like(x)


@hope.jit
def hope_exp(X,Y,Z,A):
        A[:] = hope.exp((X**2+Y**2)/Z)

hope_exp(x,y,z,out)

but in Python 3.6.1 it returns the following error:


AttributeError Traceback (most recent call last)
/Users/edouglas/anaconda/envs/astroconda/lib/python3.6/site-packages/hope/_transformer.py in visit_Assign(self, node)
286
--> 287 target, value = self.visit(node.targets[0]), self.visit(node.value)
288

/Users/edouglas/anaconda/envs/astroconda/lib/python3.6/ast.py in visit(self, node)
252 visitor = getattr(self, method, self.generic_visit)
--> 253 return visitor(node)
254

/Users/edouglas/anaconda/envs/astroconda/lib/python3.6/site-packages/hope/_transformer.py in visit_Call(self, node)
577 elif isinstance(node.func, ast.Attribute):
--> 578 if not node.starargs is None or not node.kwargs is None:
579 raise UnsupportedFeatureException("Only arguments without default values are supported in calls")

AttributeError: 'Call' object has no attribute 'starargs'

During handling of the above exception, another exception occurred:

AttributeError Traceback (most recent call last)
/Users/edouglas/anaconda/envs/astroconda/lib/python3.6/site-packages/hope/_transformer.py in body_visit(self, stmts)
641 try:
--> 642 self.exprs.append(self.visit(stmt))
643 except Exception as ex:

/Users/edouglas/anaconda/envs/astroconda/lib/python3.6/ast.py in visit(self, node)
252 visitor = getattr(self, method, self.generic_visit)
--> 253 return visitor(node)
254

/Users/edouglas/anaconda/envs/astroconda/lib/python3.6/site-packages/hope/_transformer.py in visit_Assign(self, node)
318 from hope._tosource import tosource
--> 319 ex.args = ((ex.args[0] if ex.args else "") + "\nin line " + tosource(node),) + ex.args[1:]
320 raise

/Users/edouglas/anaconda/envs/astroconda/lib/python3.6/site-packages/hope/_tosource.py in tosource(node, indent_with, add_line_information)
77 generator = SourceGenerator(indent_with, add_line_information)
---> 78 generator.visit(node)
79

/Users/edouglas/anaconda/envs/astroconda/lib/python3.6/ast.py in visit(self, node)
252 visitor = getattr(self, method, self.generic_visit)
--> 253 return visitor(node)
254

/Users/edouglas/anaconda/envs/astroconda/lib/python3.6/site-packages/hope/_tosource.py in visit_Assign(self, node)
173 self.write(' = ')
--> 174 self.visit(node.value)
175

/Users/edouglas/anaconda/envs/astroconda/lib/python3.6/ast.py in visit(self, node)
252 visitor = getattr(self, method, self.generic_visit)
--> 253 return visitor(node)
254

/Users/edouglas/anaconda/envs/astroconda/lib/python3.6/site-packages/hope/_tosource.py in visit_Call(self, node)
440 self.visit(keyword.value)
--> 441 if node.starargs is not None:
442 write_comma()

AttributeError: 'Call' object has no attribute 'starargs'

During handling of the above exception, another exception occurred:

AttributeError Traceback (most recent call last)
in ()
9 def hope_exp(X,Y,Z,A):
10 A[:] = hope.exp((X2+Y2)/Z)
---> 11 hope_exp(x,y,z,out)
12 np.exp((x2 + y2)/z)

/Users/edouglas/anaconda/envs/astroconda/lib/python3.6/site-packages/hope/_wrapper.py in _hope_callback(*args)
69
70 def _hope_callback(*args):
---> 71 return self(*args) if self.cache is None else self.cache(*args)
72 self.callback = _hope_callback
73 setattr(cache, str(id(self.callback)), fkt)

/Users/edouglas/anaconda/envs/astroconda/lib/python3.6/site-packages/hope/_wrapper.py in call(self, *args)
75
76 def call(self, *args):
---> 77 ASTTransformer(self.modtoken).module_visit(self.fkt, args)
78
79 if config.optimize:

/Users/edouglas/anaconda/envs/astroconda/lib/python3.6/site-packages/hope/_transformer.py in module_visit(self, fkt, args, argid)
690 if argid is None or not argid in self.modtoken.functions[fkt.name]:
691 #Create the HOPE AST from the builtin AST
--> 692 parsed = self.visit(fktast)
693 if not parsed.getId() in [arg.getId() for arg in self.modtoken.functions[fkt.name]]:
694 self.modtoken.functions[fkt.name].append(parsed)

/Users/edouglas/anaconda/envs/astroconda/lib/python3.6/ast.py in visit(self, node)
251 method = 'visit_' + node.class.name
252 visitor = getattr(self, method, self.generic_visit)
--> 253 return visitor(node)
254
255 def generic_visit(self, node):

/Users/edouglas/anaconda/envs/astroconda/lib/python3.6/site-packages/hope/_transformer.py in visit_FunctionDef(self, node)
627
628 # TODO: how do we parse recursive subfuncitons?
--> 629 self.token.body = self.body_visit(node.body)
630 AllocateVisitor(self.variables).visit(self.token.body)
631 merged = {}

/Users/edouglas/anaconda/envs/astroconda/lib/python3.6/site-packages/hope/_transformer.py in body_visit(self, stmts)
644 if "\nin body " not in (ex.args[0] if ex.args else ""):
645 from hope._tosource import tosource
--> 646 ex.args = ((ex.args[0] if ex.args else "") + "\nin body " + tosource(stmt),) + ex.args[1:]
647 raise
648 for expr in self.exprs:

/Users/edouglas/anaconda/envs/astroconda/lib/python3.6/site-packages/hope/_tosource.py in tosource(node, indent_with, add_line_information)
76
77 generator = SourceGenerator(indent_with, add_line_information)
---> 78 generator.visit(node)
79
80 return ''.join(generator.result)

/Users/edouglas/anaconda/envs/astroconda/lib/python3.6/ast.py in visit(self, node)
251 method = 'visit_' + node.class.name
252 visitor = getattr(self, method, self.generic_visit)
--> 253 return visitor(node)
254
255 def generic_visit(self, node):

/Users/edouglas/anaconda/envs/astroconda/lib/python3.6/site-packages/hope/_tosource.py in visit_Assign(self, node)
172 self.visit(target)
173 self.write(' = ')
--> 174 self.visit(node.value)
175
176 def visit_AugAssign(self, node):

/Users/edouglas/anaconda/envs/astroconda/lib/python3.6/ast.py in visit(self, node)
251 method = 'visit_' + node.class.name
252 visitor = getattr(self, method, self.generic_visit)
--> 253 return visitor(node)
254
255 def generic_visit(self, node):

/Users/edouglas/anaconda/envs/astroconda/lib/python3.6/site-packages/hope/_tosource.py in visit_Call(self, node)
439 self.write(keyword.arg + '=')
440 self.visit(keyword.value)
--> 441 if node.starargs is not None:
442 write_comma()
443 self.write('*')

AttributeError: 'Call' object has no attribute 'starargs'

Readme example:

Additionally, the standard sum example from the readme gives this error in 3.6.1 but works in 2.7:


TypeError Traceback (most recent call last)
in ()
4 def sums(x, y):
5 return x + y
----> 6 sums(x,y)

/Users/edouglas/anaconda/envs/astroconda/lib/python3.6/site-packages/hope/_wrapper.py in _hope_callback(*args)
69
70 def _hope_callback(*args):
---> 71 return self(*args) if self.cache is None else self.cache(*args)
72 self.callback = _hope_callback
73 setattr(cache, str(id(self.callback)), fkt)

/Users/edouglas/anaconda/envs/astroconda/lib/python3.6/site-packages/hope/_wrapper.py in call(self, *args)
102 fp.write(code)
103
--> 104 so_filename = _compile(tempfolder, localfilename, self.fkt.name)
105
106 self._store_state(tempfolder, localfilename)

/Users/edouglas/anaconda/envs/astroconda/lib/python3.6/site-packages/hope/_wrapper.py in _compile(target, localfilename, fkt_name)
271 try:
272 #trying to encode utf-8 to support AstroPy
--> 273 warnings.warn("A warning has been issued during compilation:\n{0}".format(out).encode('utf-8'))
274 except UnicodeError:
275 #encoding fails on Linux

TypeError: cannot use a string pattern on a bytes-like object

@jakeret
Copy link
Owner

jakeret commented May 12, 2018

Hope doesn't support python3.6 and is no longer officially supported. However, there is an incomplete PR that attempts to support the lastest python release: #56

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants