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

Add Apple Silicon builds #34

Closed
bnavigator opened this issue Nov 9, 2021 · 38 comments
Closed

Add Apple Silicon builds #34

bnavigator opened this issue Nov 9, 2021 · 38 comments

Comments

@bnavigator
Copy link
Contributor

@sawyerbfuller mentions in python-control/python-control#670 (comment) that he can't get Slycot on his Mac M1. The files on conda-forge are over 1 year old. I guess the procedure described here needs to be executed:

https://conda-forge.org/blog/posts/2020-10-29-macos-arm64/

bnavigator added a commit to bnavigator/conda-forge-pinning-feedstock that referenced this issue Nov 9, 2021
@murrayrm
Copy link
Contributor

FWIW, I have slycot working on my Mac M1. I'm pretty sure I just did a standard install (via conda) and it worked (presumably via Rosetta).

@sawyerbfuller
Copy link

Tried it again with no luck. Standard 64-bit Anaconda (presumably running under Rosetta2). For now I'd be happy with just running under Rosetta2. After installing Anaconda using the graphical installer, the following happens:

(base) minster@Sawyers-MacBook-Pro-2 ~ % conda install -c conda-forge slycot control
Collecting package metadata (current_repodata.json): done
Solving environment: failed with initial frozen solve. Retrying with flexible solve.
Solving environment: failed with repodata from current_repodata.json, will retry with next repodata source.
Collecting package metadata (repodata.json): done
Solving environment: / 

(.. wait for awhile lots of conflicts reported, after which control and slycot still don't import)

@murrayrm
Copy link
Contributor

@sawyerbfuller Slycot has now been rebuilt to include an ARM version. Can you try it out and see if it is working now?

@sawyerbfuller
Copy link

Hi @murrayrm thanks for letting me know. Installation of slycot seems to have worked using the installation shell script provided at the top of the page here: https://conda-forge.org/blog/posts/2020-10-29-macos-arm64/ and subsequent installation using conda-forge.

Related: control doesn't install now through conda-forge. Perhaps something isn't configured correctly? (see below)

(base) minster@Sawyers-MacBook-Pro-2 ~ % conda install -c conda-forge control
Collecting package metadata (current_repodata.json): done
Solving environment: failed with initial frozen solve. Retrying with flexible solve.
Collecting package metadata (repodata.json): done
Solving environment: failed with initial frozen solve. Retrying with flexible solve.

PackagesNotFoundError: The following packages are not available from current channels:

  - control

Current channels:

  - https://conda.anaconda.org/conda-forge/osx-arm64
  - https://conda.anaconda.org/conda-forge/noarch

To search for alternate channels that may provide the conda package you're
looking for, navigate to

    https://anaconda.org

and use the search bar at the top of the page.``` 

@bnavigator
Copy link
Contributor Author

Ah the control-feedstock is missing the osx migrator PR.

@bnavigator
Copy link
Contributor Author

@bnavigator
Copy link
Contributor Author

..,which is actually dumb because control is pure python and should be a noarch package ...

@bnavigator
Copy link
Contributor Author

@sawyerbfuller conda-forge now has a platform independent control package:

https://anaconda.org/conda-forge/control/files

Does that work for you?

@sawyerbfuller
Copy link

Installs! There is a wrinkle:

Python 3.9.7 | packaged by conda-forge | (default, Sep 29 2021, 19:24:02) 
[Clang 11.1.0 ] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import control
zsh: segmentation fault  python

@sawyerbfuller
Copy link

Here is printout from the install procedure:

(base) minster@Sawyers-MacBook-Pro-2 ~ % conda install -c conda-forge control
Collecting package metadata (current_repodata.json): done
Solving environment: done

## Package Plan ##

  environment location: /Users/minster/miniforge3

  added / updated specs:
    - control


The following packages will be downloaded:

    package                    |            build
    ---------------------------|-----------------
    control-0.9.1              |     pyhd8ed1ab_2         262 KB  conda-forge
    scipy-1.7.3                |   py39h5060c3b_0        19.4 MB  conda-forge
    ------------------------------------------------------------
                                           Total:        19.6 MB

The following NEW packages will be INSTALLED:

  control            conda-forge/noarch::control-0.9.1-pyhd8ed1ab_2
  scipy              conda-forge/osx-arm64::scipy-1.7.3-py39h5060c3b_0

@bnavigator
Copy link
Contributor Author

Does the segmentation fault also occur with import slycot or import scipy ?

@sawyerbfuller
Copy link

Good point. Looks like it's slycot:

Python 3.9.7 | packaged by conda-forge | (default, Sep 29 2021, 19:24:02) 
[Clang 11.1.0 ] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import scipy
>>> import matplotlib
>>> import numpy
>>> import slycot
zsh: segmentation fault  python

@bnavigator
Copy link
Contributor Author

Installation of slycot seems to have worked using the installation shell script provided at the top of the page here:

I am not sure if I understand this statement. Did you compile it yourself or did you use the package from conda-forge?

@sawyerbfuller
Copy link

@bnavigator my apologies for the incorrect wording.

  • installation of slycot using conda-forge completed. My understanding of this is that this was a binary package. No compilation
  • I had not yet tried to import it when I wrote that message, so it did not actually “work”

@bnavigator
Copy link
Contributor Author

Hmm, seems like the conda-forge compiled slycot package is broken then.

For testing, I would recommend cleaning your (base) environment and check installations in a dedicated conda env first.

Are you able to step through a debugger or inspect the stack trace at the segmentation fault?
https://lldb.llvm.org/use/tutorial.html

@murrayrm
Copy link
Contributor

murrayrm commented Jan 6, 2022

I tried installing on my Mac (MacOS 12.1, M1 Macbook Air) and it worked OK, but I can't tell if I am running the arm64 version of the non-ARM version (with Rosetta2). Specific sequence that worked:

conda create -n test python=3.9
conda activate test
conda install -c conda-forge control
python -c "import control; print(control.__version__)"
0.9.1
python -c "import slycot; print(slycot.__version__)"
0.4.0.0

For me, there is a pretty long delay (15 seconds) before the version for control prints, which is often an indication that Rosetta is doing translation. Printing the version for slycot is instantaneous.

@bnavigator
Copy link
Contributor Author

bnavigator commented Jan 6, 2022

@murrayrm the delay would come because control imports slycot. The second call then uses the already translated slycot. Can you try without importing control first?

I guess you would see the used package in the name of the egg-info directory. Check slycot.__path__ and look for the egg-info next to it.

  • arm64: slycot-0.4.0.0-py3.9-macosx-11.0-arm64.egg-info
  • x86_64: slycot-0.4.0.0-py3.9-macosx-10.9-x86_64.egg-info

Also (on my linux system):

[ben@skylab:~/tmp]% file slycot-mac_x86/_wrapper.cpython-39-darwin.so                                                            [0]
slycot-mac_x86/_wrapper.cpython-39-darwin.so: Mach-O 64-bit x86_64 bundle, flags:<NOUNDEFS|DYLDLINK|TWOLEVEL>
[ben@skylab:~/tmp]% file slycot-mac_arm64/_wrapper.cpython-39-darwin.so                                                          [0]
slycot-mac_arm64/_wrapper.cpython-39-darwin.so: Mach-O 64-bit arm64 dynamically linked shared library, flags:<NOUNDEFS|DYLDLINK|TWOLEVEL|NO_REEXPORTED_DYLIBS>

@murrayrm
Copy link
Contributor

murrayrm commented Jan 6, 2022

Indeed, I am getting slycot-0.4.0.0-py3.9-macosx-10.9-x86_64.egg-info

@repagh
Copy link
Contributor

repagh commented Jan 6, 2022 via email

@sawyerbfuller
Copy link

@bnavigator Debugging slycot binary is probably beyond my abilities/time availability. I will keep fiddling to see if I can get things to work under Rosetta2 (no idea why that doesn't work for me)

@sawyerbfuller
Copy link

Update: I am back to running anaconda using Rosetta2 (osx-64). When I created a new environment, slycot and control installed their own dependencies and ran successfully.

So it looks like the problem is a conflict between the default osx-64 anaconda distribution and slycot.

One question: right now control depends on installing slycot (see below) but given that slycot has more constrained depencies, and a lot of control can work without it, have we considered removing it as a dependency?

(base) minster@Sawyers-MacBook-Pro-2 ~ % conda search control --info 
...
control 0.9.1 py38h50d1736_1
----------------------------
file name   : control-0.9.1-py38h50d1736_1.tar.bz2
name        : control
version     : 0.9.1
build       : py38h50d1736_1
build number: 1
size        : 542 KB
license     : BSD-3-Clause
subdir      : osx-64
url         : https://conda.anaconda.org/conda-forge/osx-64/control-0.9.1-py38h50d1736_1.tar.bz2
md5         : 85438141e5197f04a5525ed2fdc576cf
timestamp   : 2021-12-31 21:49:06 UTC
dependencies: 
  - matplotlib-base
  - numpy
  - python >=3.8,<3.9.0a0
  - python_abi 3.8.* *_cp38
  - scipy
  - slycot 
...
(and other versions continue)   ```

@murrayrm
Copy link
Contributor

murrayrm commented Jan 8, 2022

If/when we get this right, there should be no problem having control depend on slycot in terms of conda/conda-forge: they will both be available on all of the same platforms. And there is some advantage, I think, in just having to do one install and getting all of the dependencies.

Note that there are still quite a few important things that won't work without slycot. Many operations won't work without slycot: state space realizations of a transfer function, any type of Hinf synthesis, balanced truncations.

@murrayrm
Copy link
Contributor

murrayrm commented Jan 8, 2022

I created a conda environment using arm64 using the following command

CONDA_SUBDIR=osx-arm64 conda create -n arm64 -c conda-forge python=3.9

When I install slycot using conda in that environment and try to import slycot, I get a segfault.

Output from otool -L _wrapper.cpython-39-darwin.so (@repagh request)

(arm64) murray@evaluna python % otool -L /Users/murray/anaconda3/envs/arm64/lib/python3.9/site-packages/slycot/_wrapper.cpython-39-darwin.so
/Users/murray/anaconda3/envs/arm64/lib/python3.9/site-packages/slycot/_wrapper.cpython-39-darwin.so:
	@rpath/python3.9/site-packages/slycot/_wrapper.cpython-39-darwin.so (compatibility version 0.0.0, current version 0.0.0)
	@rpath/liblapack.3.dylib (compatibility version 0.0.0, current version 0.0.0)
	@rpath/libblas.3.dylib (compatibility version 0.0.0, current version 0.0.0)
	@rpath/libpython3.9.dylib (compatibility version 3.9.0, current version 3.9.0)
	@rpath/libgfortran.5.dylib (compatibility version 6.0.0, current version 6.0.0)
	/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1292.0.0)

Running with lldb I get the following output:

>>> import slycot
Process 13457 stopped
* thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0x10)
    frame #0: 0x00000001041a0ce4 libpython3.9.dylib`PyModule_Create2 + 24
libpython3.9.dylib`PyModule_Create2:
->  0x1041a0ce4 <+24>: ldr    x9, [x9, #0x10]
    0x1041a0ce8 <+28>: ldr    x9, [x9, #0x358]
    0x1041a0cec <+32>: cbz    x9, 0x1041a0d00           ; <+52>
    0x1041a0cf0 <+36>: ldp    x29, x30, [sp, #0x20]
Target 0: (python) stopped.

Backtrace:

* thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0x10)
  * frame #0: 0x00000001041a0ce4 libpython3.9.dylib`PyModule_Create2 + 24
    frame #1: 0x0000000103a69c14 _wrapper.cpython-39-darwin.so`PyInit__wrapper + 36
    frame #2: 0x000000010019f290 python`_imp_create_dynamic + 2376
    frame #3: 0x00000001000b3c20 python`cfunction_vectorcall_FASTCALL + 208
    frame #4: 0x000000010016bc0c python`_PyEval_EvalFrameDefault + 29264
    frame #5: 0x0000000100164374 python`_PyEval_EvalCode + 2968
    frame #6: 0x000000010005f9e0 python`_PyFunction_Vectorcall + 240
    frame #7: 0x000000010016edc8 python`call_function + 572
    frame #8: 0x000000010016b8e4 python`_PyEval_EvalFrameDefault + 28456
    frame #9: 0x000000010005fa60 python`function_code_fastcall + 116
    frame #10: 0x000000010016edc8 python`call_function + 572
    frame #11: 0x000000010016b8c0 python`_PyEval_EvalFrameDefault + 28420
    frame #12: 0x000000010005fa60 python`function_code_fastcall + 116
    frame #13: 0x000000010016edc8 python`call_function + 572
    frame #14: 0x000000010016b960 python`_PyEval_EvalFrameDefault + 28580
    frame #15: 0x000000010005fa60 python`function_code_fastcall + 116
    frame #16: 0x000000010016edc8 python`call_function + 572
    frame #17: 0x000000010016b960 python`_PyEval_EvalFrameDefault + 28580
    frame #18: 0x000000010005fa60 python`function_code_fastcall + 116
    frame #19: 0x000000010016edc8 python`call_function + 572
    frame #20: 0x000000010016b960 python`_PyEval_EvalFrameDefault + 28580
    frame #21: 0x000000010005fa60 python`function_code_fastcall + 116
    frame #22: 0x0000000100060c84 python`object_vacall + 376
    frame #23: 0x0000000100060e74 python`_PyObject_CallMethodIdObjArgs + 132
    frame #24: 0x000000010019951c python`PyImport_ImportModuleLevelObject + 1564
    frame #25: 0x000000010015bef0 python`builtin___import__ + 124
    frame #26: 0x00000001000b32b0 python`cfunction_call + 80
    frame #27: 0x000000010005f7b0 python`_PyObject_Call + 156
    frame #28: 0x000000010016bc0c python`_PyEval_EvalFrameDefault + 29264
    frame #29: 0x0000000100164374 python`_PyEval_EvalCode + 2968
    frame #30: 0x000000010005f9e0 python`_PyFunction_Vectorcall + 240
    frame #31: 0x000000010016edc8 python`call_function + 572
    frame #32: 0x000000010016b960 python`_PyEval_EvalFrameDefault + 28580
    frame #33: 0x0000000100164374 python`_PyEval_EvalCode + 2968
    frame #34: 0x000000010005f9e0 python`_PyFunction_Vectorcall + 240
    frame #35: 0x0000000100060c84 python`object_vacall + 376
    frame #36: 0x0000000100060e74 python`_PyObject_CallMethodIdObjArgs + 132
    frame #37: 0x00000001001998d4 python`PyImport_ImportModuleLevelObject + 2516
    frame #38: 0x0000000100169f54 python`_PyEval_EvalFrameDefault + 21912
    frame #39: 0x0000000100164374 python`_PyEval_EvalCode + 2968
    frame #40: 0x000000010015eeec python`builtin_exec + 1032
    frame #41: 0x00000001000b3c20 python`cfunction_vectorcall_FASTCALL + 208
    frame #42: 0x000000010016bc0c python`_PyEval_EvalFrameDefault + 29264
    frame #43: 0x0000000100164374 python`_PyEval_EvalCode + 2968
    frame #44: 0x000000010005f9e0 python`_PyFunction_Vectorcall + 240
    frame #45: 0x000000010016edc8 python`call_function + 572
    frame #46: 0x000000010016b8e4 python`_PyEval_EvalFrameDefault + 28456
    frame #47: 0x000000010005fa60 python`function_code_fastcall + 116
    frame #48: 0x000000010016edc8 python`call_function + 572
    frame #49: 0x000000010016b8c0 python`_PyEval_EvalFrameDefault + 28420
    frame #50: 0x000000010005fa60 python`function_code_fastcall + 116
    frame #51: 0x000000010016edc8 python`call_function + 572
    frame #52: 0x000000010016b960 python`_PyEval_EvalFrameDefault + 28580
    frame #53: 0x000000010005fa60 python`function_code_fastcall + 116
    frame #54: 0x000000010016edc8 python`call_function + 572
    frame #55: 0x000000010016b960 python`_PyEval_EvalFrameDefault + 28580
    frame #56: 0x000000010005fa60 python`function_code_fastcall + 116
    frame #57: 0x0000000100060c84 python`object_vacall + 376
    frame #58: 0x0000000100060e74 python`_PyObject_CallMethodIdObjArgs + 132
    frame #59: 0x000000010019951c python`PyImport_ImportModuleLevelObject + 1564
    frame #60: 0x0000000100169f54 python`_PyEval_EvalFrameDefault + 21912
    frame #61: 0x0000000100164374 python`_PyEval_EvalCode + 2968
    frame #62: 0x000000010015eeec python`builtin_exec + 1032
    frame #63: 0x00000001000b3c20 python`cfunction_vectorcall_FASTCALL + 208
    frame #64: 0x000000010016bc0c python`_PyEval_EvalFrameDefault + 29264
    frame #65: 0x0000000100164374 python`_PyEval_EvalCode + 2968
    frame #66: 0x000000010005f9e0 python`_PyFunction_Vectorcall + 240
    frame #67: 0x000000010016edc8 python`call_function + 572
    frame #68: 0x000000010016b8e4 python`_PyEval_EvalFrameDefault + 28456
    frame #69: 0x000000010005fa60 python`function_code_fastcall + 116
    frame #70: 0x000000010016edc8 python`call_function + 572
    frame #71: 0x000000010016b8c0 python`_PyEval_EvalFrameDefault + 28420
    frame #72: 0x000000010005fa60 python`function_code_fastcall + 116
    frame #73: 0x000000010016edc8 python`call_function + 572
    frame #74: 0x000000010016b960 python`_PyEval_EvalFrameDefault + 28580
    frame #75: 0x000000010005fa60 python`function_code_fastcall + 116
    frame #76: 0x000000010016edc8 python`call_function + 572
    frame #77: 0x000000010016b960 python`_PyEval_EvalFrameDefault + 28580
    frame #78: 0x000000010005fa60 python`function_code_fastcall + 116
    frame #79: 0x0000000100060c84 python`object_vacall + 376
    frame #80: 0x0000000100060e74 python`_PyObject_CallMethodIdObjArgs + 132
    frame #81: 0x000000010019951c python`PyImport_ImportModuleLevelObject + 1564
    frame #82: 0x0000000100169f54 python`_PyEval_EvalFrameDefault + 21912
    frame #83: 0x0000000100164374 python`_PyEval_EvalCode + 2968
    frame #84: 0x00000001001c9ccc python`PyRun_InteractiveOneObjectEx + 1432
    frame #85: 0x00000001001c6188 python`PyRun_InteractiveLoopFlags + 540
    frame #86: 0x00000001001c5ef4 python`PyRun_AnyFileExFlags + 72
    frame #87: 0x00000001001e9b14 python`Py_RunMain + 3316
    frame #88: 0x00000001001eab14 python`pymain_main + 1272
    frame #89: 0x000000010000573c python`main + 56
    frame #90: 0x00000001004490f4 dyld`start + 520

Walking up through the backtrace just shows assembly code, so not very useful.

@isuruf
Copy link
Member

isuruf commented Jan 8, 2022

See scikit-build/scikit-build#589

@bnavigator
Copy link
Contributor Author

Thanks @isuruf!

So does your fix in conda-forge/python-blosc-feedstock#39 work? Can we do the same here?

@bnavigator
Copy link
Contributor Author

@murrayrm, do you still get the segfault when you execute

install_name_tool -change @rpath/libpython3.9.dylib @rpath/libc++.1.dylib /Users/murray/anaconda3/envs/arm64/lib/python3.9/site-packages/slycot/_wrapper.cpython-39-darwin.so

?

@murrayrm
Copy link
Contributor

murrayrm commented Jan 8, 2022

New error:

(arm64) murray@evaluna python % install_name_tool -change @rpath/libpython3.9.dylib @rpath/libc++.1.dylib /Users/murray/anaconda3/envs/arm64/lib/python3.9/site-packages/slycot/_wrapper.cpython-39-darwin.so

/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/install_name_tool: warning: changes being made to the file will invalidate the code signature in: /Users/murray/anaconda3/envs/arm64/lib/python3.9/site-packages/slycot/_wrapper.cpython-39-darwin.so
(arm64) murray@evaluna python % python
Python 3.9.9 | packaged by conda-forge | (main, Dec 20 2021, 02:41:06) 
[Clang 11.1.0 ] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import slycot
zsh: killed     python

@isuruf
Copy link
Member

isuruf commented Jan 8, 2022

/usr/bin/codesign -s - -f /Users/murray/anaconda3/envs/arm64/lib/python3.9/site-packages/slycot/_wrapper.cpython-39-darwin.so

@murrayrm
Copy link
Contributor

murrayrm commented Jan 8, 2022

Ran that:

(arm64) murray@evaluna python % /usr/bin/codesign -s - -f /Users/murray/anaconda3/envs/arm64/lib/python3.9/site-packages/slycot/_wrapper.cpython-39-darwin.so
/Users/murray/anaconda3/envs/arm64/lib/python3.9/site-packages/slycot/_wrapper.cpython-39-darwin.so: replacing existing signature
(arm64) murray@evaluna python % python
Python 3.9.9 | packaged by conda-forge | (main, Dec 20 2021, 02:41:06) 
[Clang 11.1.0 ] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import slycot
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/murray/anaconda3/envs/arm64/lib/python3.9/site-packages/slycot/__init__.py", line 16, in <module>
    from .analysis import ab01nd, ab05md, ab05nd, ab07nd, ab08nd, ab08nz
  File "/Users/murray/anaconda3/envs/arm64/lib/python3.9/site-packages/slycot/analysis.py", line 20, in <module>
    from . import _wrapper
ImportError: dlopen(/Users/murray/anaconda3/envs/arm64/lib/python3.9/site-packages/slycot/_wrapper.cpython-39-darwin.so, 0x0002): Symbol not found: _PyCapsule_Type
  Referenced from: /Users/murray/anaconda3/envs/arm64/lib/python3.9/site-packages/slycot/_wrapper.cpython-39-darwin.so
  Expected in: /Users/murray/anaconda3/envs/arm64/lib/libc++.1.0.dylib
>>> 

@bnavigator
Copy link
Contributor Author

Okay, so the link is actually necessary. Could you try:

  1. Reinstall slycot in the environement in order to restore the original link

  2. Change the link to the same libpython3.9.dylib as the conda interpreter uses

(arm64) $ otool -L $(which python)
    ...
    XXX/libpython3.9.dylib (compatibility version 3.9.9, current version 3.9.9)
    ...
install_name_tool -change @rpath/libpython3.9.dylib XXX/libpython3.9.dylib /Users/murray/anaconda3/envs/arm64/lib/python3.9/site-packages/slycot/_wrapper.cpython-39-darwin.so

@murrayrm
Copy link
Contributor

murrayrm commented Jan 9, 2022

I'm not getting a libpython3.9.dylib as a shared library for python:

(arm64) murray@evaluna python % otool -L $(which python)
/Users/murray/anaconda3/envs/arm64/bin/python:
	/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1292.0.0)
(arm64) murray@evaluna python % which python
/Users/murray/anaconda3/envs/arm64/bin/python

???

@murrayrm
Copy link
Contributor

murrayrm commented Jan 9, 2022

The latest build (from PR #47) appears to be working correctly (!).

@sawyerbfuller Can you give this is a try when you have a chance?

@isuruf Thank you for all of the help!

@sawyerbfuller
Copy link

@murrayrm It seems I'm having trouble installing the osx-arm64 version of slycot (looks like I'm still getting osx-64 versions of related package like libblas, which I assume is not what I want):

(arm64) minster@Sawyers-MacBook-Pro-2 ~ % conda install conda-forge::slycot
Collecting package metadata (current_repodata.json): done
Solving environment: done

## Package Plan ##

  environment location: /Users/minster/opt/anaconda3/envs/arm64

  added / updated specs:
    - conda-forge::slycot


The following packages will be downloaded:

    package                    |            build
    ---------------------------|-----------------
    slycot-0.4.0.0             |   py39h10744cc_8         1.2 MB  conda-forge
    ------------------------------------------------------------
                                           Total:         1.2 MB

The following NEW packages will be INSTALLED:

  libblas            conda-forge/osx-64::libblas-3.9.0-12_osx64_openblas
  libcblas           conda-forge/osx-64::libcblas-3.9.0-12_osx64_openblas
  libcxx             conda-forge/osx-64::libcxx-12.0.1-habf9029_1
  libgfortran        conda-forge/osx-64::libgfortran-5.0.0-9_3_0_h6c81a4c_23
  libgfortran5       conda-forge/osx-64::libgfortran5-9.3.0-h6c81a4c_23
  liblapack          conda-forge/osx-64::liblapack-3.9.0-12_osx64_openblas
  libopenblas        conda-forge/osx-64::libopenblas-0.3.18-openmp_h3351f45_0
  llvm-openmp        conda-forge/osx-64::llvm-openmp-12.0.1-hda6cdc1_1
  numpy              conda-forge/osx-64::numpy-1.22.0-py39h9d9ce41_0
  slycot             conda-forge/osx-64::slycot-0.4.0.0-py39h10744cc_8
...

The commands leading up to this followed what you typed in above, and were executed on a standard anaconda installation. It looks like other other packages that were being installed are arm native:

minster@Sawyers-MacBook-Pro-2 ~ % CONDA_SUBDIR=osx-arm64 conda create -n arm64 -c conda-forge python=3.9
Collecting package metadata (current_repodata.json): done
Solving environment: done

## Package Plan ##

  environment location: /Users/minster/opt/anaconda3/envs/arm64

  added / updated specs:
    - python=3.9


The following packages will be downloaded:

    package                    |            build
    ---------------------------|-----------------
    bzip2-1.0.8                |       h3422bc3_4         148 KB  conda-forge
    ca-certificates-2021.10.8  |       h4653dfc_0         139 KB  conda-forge
    libffi-3.4.2               |       h3422bc3_5          38 KB  conda-forge
    libzlib-1.2.11             |    hee7b306_1013          55 KB  conda-forge
    ncurses-6.2                |       h9aa5885_4         915 KB  conda-forge
    openssl-3.0.0              |       h3422bc3_2         2.4 MB  conda-forge
    python-3.9.9               |h43b31ca_0_cpython        12.1 MB  conda-forge
    python_abi-3.9             |           2_cp39           4 KB  conda-forge
    readline-8.1               |       hedafd6a_0         259 KB  conda-forge
    setuptools-60.5.0          |   py39h2804cbe_0         1.1 MB  conda-forge
    sqlite-3.37.0              |       h72a2b83_0         1.6 MB  conda-forge
    tk-8.6.11                  |       he1e0b03_1         3.2 MB  conda-forge
    xz-5.2.5                   |       h642e427_1         222 KB  conda-forge
    zlib-1.2.11                |    hee7b306_1013          84 KB  conda-forge
    ------------------------------------------------------------
                                           Total:        22.2 MB

The following NEW packages will be INSTALLED:

  bzip2              conda-forge/osx-arm64::bzip2-1.0.8-h3422bc3_4
  ca-certificates    conda-forge/osx-arm64::ca-certificates-2021.10.8-h4653dfc_0
  libffi             conda-forge/osx-arm64::libffi-3.4.2-h3422bc3_5
  libzlib            conda-forge/osx-arm64::libzlib-1.2.11-hee7b306_1013
  ncurses            conda-forge/osx-arm64::ncurses-6.2-h9aa5885_4
  openssl            conda-forge/osx-arm64::openssl-3.0.0-h3422bc3_2
  pip                conda-forge/noarch::pip-21.3.1-pyhd8ed1ab_0
  python             conda-forge/osx-arm64::python-3.9.9-h43b31ca_0_cpython
  python_abi         conda-forge/osx-arm64::python_abi-3.9-2_cp39
  readline           conda-forge/osx-arm64::readline-8.1-hedafd6a_0
  setuptools         conda-forge/osx-arm64::setuptools-60.5.0-py39h2804cbe_0
  sqlite             conda-forge/osx-arm64::sqlite-3.37.0-h72a2b83_0
  tk                 conda-forge/osx-arm64::tk-8.6.11-he1e0b03_1
  tzdata             conda-forge/noarch::tzdata-2021e-he74cb21_0
  wheel              conda-forge/noarch::wheel-0.37.1-pyhd8ed1ab_0
  xz                 conda-forge/osx-arm64::xz-5.2.5-h642e427_1
  zlib               conda-forge/osx-arm64::zlib-1.2.11-hee7b306_1013
....
(test_slycot) minster@Sawyers-MacBook-Pro-2 ~ % conda activate arm64
(arm64) minster@Sawyers-MacBook-Pro-2 ~ % conda install slycot

@murrayrm
Copy link
Contributor

@sawyerbfuller I had that problem as well. You need to set the environment variable CONDA_SUBDIR to point to the right place:

CONDA_SUBDIR=osx-arm64 conda create -n arm64 -c conda-forge python=3.9
CONDA_SUBDIR=osx-arm64 conda install control

@sawyerbfuller
Copy link

@murrayrm That seems to do the trick. I was able to install slycot and then and run some code from it.

That is, assuming after all that that the arm64 version of slycot was the one that was imported.

@murrayrm
Copy link
Contributor

Here's the commands that I ran to convince myself I was running the ARM version:

(base) murray@evaluna recomm % conda activate arm64
(arm64) murray@evaluna recomm % python
Python 3.9.9 | packaged by conda-forge | (main, Dec 20 2021, 02:41:06) 
[Clang 11.1.0 ] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import slycot
>>> slycot.__path__
['/Users/murray/anaconda3/envs/arm64/lib/python3.9/site-packages/slycot']
>>> quit()
(arm64) murray@evaluna recomm % ls /Users/murray/anaconda3/envs/arm64/lib/python3.9/site-packages/slycot
__init__.py			math.py
__pycache__/			synthesis.py
_wrapper.cpython-39-darwin.so*	tests/
analysis.py			transform.py
examples.py			version.py
exceptions.py
(arm64) murray@evaluna recomm % file /Users/murray/anaconda3/envs/arm64/lib/python3.9/site-packages/slycot/_wrapper.cpython-39-darwin.so 
/Users/murray/anaconda3/envs/arm64/lib/python3.9/site-packages/slycot/_wrapper.cpython-39-darwin.so: Mach-O 64-bit dynamically linked shared library arm64

I think the arm64 at the end is the key: this says that you are on an M1 Mac. Otherwise, you get x86_64.

@sawyerbfuller
Copy link

sawyerbfuller commented Jan 13, 2022

Ok looks good, thanks!

>>> import slycot
>>> slycot.__path__
['/Users/minster/opt/anaconda3/envs/arm64/lib/python3.9/site-packages/slycot']
>>> exit()
(arm64) minster@Sawyers-MacBook-Pro-2 ~ % file /Users/minster/opt/anaconda3/envs/arm64/lib/python3.9/site-packages/slycot/_wrapper.cpython-39-darwin.so
/Users/minster/opt/anaconda3/envs/arm64/lib/python3.9/site-packages/slycot/_wrapper.cpython-39-darwin.so: Mach-O 64-bit dynamically linked shared library arm64

@murrayrm
Copy link
Contributor

Done. Thanks @bnavigator, @repagh, and @sawyerbfuller for the comments and feedback and @isuruf for the final tricks to implement (in PR #47).

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

5 participants