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

Error in local compilation on apple silicon #9

Closed
tlambert03 opened this issue Nov 7, 2024 · 3 comments · Fixed by #7
Closed

Error in local compilation on apple silicon #9

tlambert03 opened this issue Nov 7, 2024 · 3 comments · Fixed by #7

Comments

@tlambert03
Copy link
Member

running creating a SpatialGraph instance failed for me locally after creating an environment and running:

import spatial_graph as sg
import numpy as np
import pytest


def test_node_access():
    graph = sg.SpatialGraph(
        ndims=3,
        node_dtype="uint64",
        node_attr_dtypes={"position": "double[3]"},
        edge_attr_dtypes={"score": "double"},
        position_attr="position",
    )
In file included from /Users/talley/Library/Caches/cython/witty/_witty_module_60cdc22c97a2c8c22d1fe4e1e910f7ac.cpp:1274:
/Users/talley/dev/self/spatial_graph/spatial_graph/graph/src/graph_lite.h:472:75: error: a template argument list is expected after a name prefixed by the template keyword [-Wmissing-template-arg-list-after-template-kw]
  472 |                     static_cast<const EdgePropGraphBase*>(this)->template edge_prop(
      |                                                                           ^
/Users/talley/dev/self/spatial_graph/spatial_graph/graph/src/graph_lite.h:1270:25: warning: unused variable 'num_tgt_removed' [-Wunused-variable]
 1270 |                     int num_tgt_removed = detail::container::erase_all(get_in_neighbors(tgt_pos), src_full);
      |                         ^~~~~~~~~~~~~~~
1 warning and 1 error generated.
In file included from /Users/talley/Library/Caches/cython/witty/_witty_module_60cdc22c97a2c8c22d1fe4e1e910f7ac.cpp:1274:
/Users/talley/dev/self/spatial_graph/spatial_graph/graph/src/graph_lite.h:472:75: error: a template argument list is expected after a name prefixed by the template keyword [-Wmissing-template-arg-list-after-template-kw]
  472 |                     static_cast<const EdgePropGraphBase*>(this)->template edge_prop(
      |                                                                           ^
/Users/talley/dev/self/spatial_graph/spatial_graph/graph/src/graph_lite.h:1270:25: warning: unused variable 'num_tgt_removed' [-Wunused-variable]
 1270 |                     int num_tgt_removed = detail::container::erase_all(get_in_neighbors(tgt_pos), src_full);
      |                         ^~~~~~~~~~~~~~~
1 warning and 1 error generated.
---------------------------------------------------------------------------
CalledProcessError                        Traceback (most recent call last)
File ~/dev/self/spatial_graph/.venv/lib/python3.12/site-packages/setuptools/_distutils/spawn.py:70, in spawn(cmd, search_path, verbose, dry_run, env)
     69 try:
---> 70     subprocess.check_call(cmd, env=_inject_macos_ver(env))
     71 except OSError as exc:

File ~/.local/share/uv/python/cpython-3.12.6-macos-aarch64-none/lib/python3.12/subprocess.py:413, in check_call(*popenargs, **kwargs)
    412         cmd = popenargs[0]
--> 413     raise CalledProcessError(retcode, cmd)
    414 return 0

CalledProcessError: Command '['/opt/homebrew/opt/llvm/bin/clang++', '-fno-strict-overflow', '-Wsign-compare', '-Wunreachable-code', '-DNDEBUG', '-g', '-O3', '-Wall', '-arch', 'arm64', '-mmacosx-version-min=11.0', '-Wno-nullability-completeness', '-Wno-expansion-to-defined', '-Wno-undef-prefix', '-fPIC', '-Werror=unguarded-availability-new', '-I/Users/talley/dev/self/spatial_graph/spatial_graph/graph', '-I/Users/talley/dev/self/spatial_graph/.venv/include', '-I/Users/talley/.local/share/uv/python/cpython-3.12.6-macos-aarch64-none/include/python3.12', '-c', '/Users/talley/Library/Caches/cython/witty/_witty_module_60cdc22c97a2c8c22d1fe4e1e910f7ac.cpp', '-o', '/Users/talley/Library/Caches/cython/witty/Users/talley/Library/Caches/cython/witty/_witty_module_60cdc22c97a2c8c22d1fe4e1e910f7ac.o', '-O3', '-std=c++20']' returned non-zero exit status 1.

The above exception was the direct cause of the following exception:

DistutilsExecError                        Traceback (most recent call last)
File ~/dev/self/spatial_graph/.venv/lib/python3.12/site-packages/setuptools/_distutils/unixccompiler.py:196, in UnixCCompiler._compile(self, obj, src, ext, cc_args, extra_postargs, pp_opts)
    195 if self.detect_language(src) == 'c++':
--> 196     self.spawn(
    197         compiler_so_cxx + cc_args + [src, '-o', obj] + extra_postargs
    198     )
    199 else:

File ~/dev/self/spatial_graph/.venv/lib/python3.12/site-packages/setuptools/_distutils/ccompiler.py:1045, in CCompiler.spawn(self, cmd, **kwargs)
   1044 def spawn(self, cmd, **kwargs):
-> 1045     spawn(cmd, dry_run=self.dry_run, **kwargs)

File ~/dev/self/spatial_graph/.venv/lib/python3.12/site-packages/setuptools/_distutils/spawn.py:76, in spawn(cmd, search_path, verbose, dry_run, env)
     75 except subprocess.CalledProcessError as err:
---> 76     raise DistutilsExecError(
     77         f"command {_debug(cmd)!r} failed with exit code {err.returncode}"
     78     ) from err

DistutilsExecError: command '/opt/homebrew/opt/llvm/bin/clang++' failed with exit code 1

During handling of the above exception, another exception occurred:

CompileError                              Traceback (most recent call last)
Cell In[5], line 1
----> 1 graph = sg.SpatialGraph(
      2     ndims=3,
      3     node_dtype="uint64",
      4     node_attr_dtypes={"position": "double[3]"},
      5     edge_attr_dtypes={"score": "double"},
      6     position_attr="position",
      7 )

File ~/dev/self/spatial_graph/spatial_graph/graph/graph.py:41, in Graph.__new__(cls, node_dtype, node_attr_dtypes, edge_attr_dtypes, directed, *args, **kwargs)
     38 wrapper_template.edge_attr_dtypes = edge_attr_dtypes
     39 wrapper_template.directed = directed
---> 41 wrapper = witty.compile_module(
     42     str(wrapper_template),
     43     source_files=[str(src_dir / "src" / "graph_lite.h")],
     44     extra_compile_args=["-O3", "-std=c++20"],
     45     include_dirs=[str(src_dir)],
     46     language="c++",
     47     quiet=True,
     48 )
     49 GraphType = type(cls.__name__, (cls, wrapper.Graph), {})
     50 return wrapper.Graph.__new__(GraphType)

File ~/dev/self/spatial_graph/.venv/lib/python3.12/site-packages/witty/compile_module.py:146, in compile_module(source_pyx, source_files, include_dirs, library_dirs, language, extra_compile_args, extra_link_args, name, force_rebuild, quiet)
    144     build_extension.build_temp = str(module_dir)
    145     build_extension.build_lib = str(module_dir)
--> 146     build_extension.run()
    148 return load_dynamic(module_name, module_lib)

File ~/dev/self/spatial_graph/.venv/lib/python3.12/site-packages/setuptools/_distutils/command/build_ext.py:359, in build_ext.run(self)
    356     self.compiler.set_link_objects(self.link_objects)
    358 # Now actually compile and link everything.
--> 359 self.build_extensions()

File ~/dev/self/spatial_graph/.venv/lib/python3.12/site-packages/setuptools/_distutils/command/build_ext.py:476, in build_ext.build_extensions(self)
    474     self._build_extensions_parallel()
    475 else:
--> 476     self._build_extensions_serial()

File ~/dev/self/spatial_graph/.venv/lib/python3.12/site-packages/setuptools/_distutils/command/build_ext.py:502, in build_ext._build_extensions_serial(self)
    500 for ext in self.extensions:
    501     with self._filter_build_errors(ext):
--> 502         self.build_extension(ext)

File ~/dev/self/spatial_graph/.venv/lib/python3.12/site-packages/setuptools/_distutils/command/build_ext.py:557, in build_ext.build_extension(self, ext)
    554 for undef in ext.undef_macros:
    555     macros.append((undef,))
--> 557 objects = self.compiler.compile(
    558     sources,
    559     output_dir=self.build_temp,
    560     macros=macros,
    561     include_dirs=ext.include_dirs,
    562     debug=self.debug,
    563     extra_postargs=extra_args,
    564     depends=ext.depends,
    565 )
    567 # XXX outdated variable, kept here in case third-part code
    568 # needs it.
    569 self._built_objects = objects[:]

File ~/dev/self/spatial_graph/.venv/lib/python3.12/site-packages/setuptools/_distutils/ccompiler.py:606, in CCompiler.compile(self, sources, output_dir, macros, include_dirs, debug, extra_preargs, extra_postargs, depends)
    604     except KeyError:
    605         continue
--> 606     self._compile(obj, src, ext, cc_args, extra_postargs, pp_opts)
    608 # Return *all* object filenames, not just the ones we just built.
    609 return objects

File ~/dev/self/spatial_graph/.venv/lib/python3.12/site-packages/setuptools/_distutils/unixccompiler.py:202, in UnixCCompiler._compile(self, obj, src, ext, cc_args, extra_postargs, pp_opts)
    200         self.spawn(compiler_so + cc_args + [src, '-o', obj] + extra_postargs)
    201 except DistutilsExecError as msg:
--> 202     raise CompileError(msg)

CompileError: command '/opt/homebrew/opt/llvm/bin/clang++' failed with exit code 1

so, @funkey, it does unfortunately look like there might be some host-platform idiosyncrasies with the well-in-time compilation.

I think in this case, we can fix it just by explicitly passing the template arguments:

static_cast<const EdgePropGraphBase*>(this)->template edge_prop<U, V>(

and hopefully that's all this amounts to :)

@tlambert03
Copy link
Member Author

interestingly, this error does not occur on macos-latest CI (which is working in #7). so that also means that we may not be able to fully test target platforms on CI

@tlambert03
Copy link
Member Author

I think in this case, we can fix it just by explicitly passing the template arguments:
static_cast<const EdgePropGraphBase*>(this)->template edge_prop<U, V>(

yes, that fixes it for my local macos use case. That fix is included in #7

@funkey
Copy link
Member

funkey commented Nov 19, 2024

Closing this in favor of the more general #10.

@funkey funkey closed this as completed Nov 19, 2024
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

Successfully merging a pull request may close this issue.

2 participants