gentzkow / template_archive

19 stars 36 forks source link

Solve chip confilct in `import.util` package #89

Closed ShiqiYang2022 closed 1 year ago

ShiqiYang2022 commented 1 year ago

Follows https://github.com/gslab-econ/gslab_make/pull/65#issuecomment-1769271009.

This issue aims to solve the conflict arising the from the Mac M2 chip on @snairdesai's local machine. The standard template run into an error in import.util package, and is no longer compiling on his updated conda environment local machine (though it did previously, and succeed on @jc-cisneros @ShiqiYang2022 end).

This suggests import.util package was updated in the conda environment no longer supported by Apple Silicon. A hot fix which manually installed the import.util package to his local computer before building the conda environment worked. This issue aim to explore and compare other methods, currently the potential candidates includes:

ShiqiYang2022 commented 1 year ago

Per my investigation, I think it's rather a problem due to python package, instead of chips.

In Python versions 3.10.11+ through 3.12.0a7+, importlib.util is not referenced in importlib/__init__.py, so by directly import importlib, it will throw an AttributeError. If you intend to use importlib.util in a regular Python environment, you should directly import importlib.util instead of trying to import .util from importlib. Details could be referred per threads here.

I removed the conda env template on my local machine and re-run template. Initially I failed in the same error in https://github.com/gslab-econ/gslab_make/pull/65#issuecomment-1769271009. After I edit the code to import importlib.util directly in f12dcd2, the template can successfully compiled again.

ShiqiYang2022 commented 1 year ago

@snairdesai See this comment, could you please edit run_all.py in the same commit f12dcd2 and re-construct the template? Once the template worked on your end, I will open a new pull request. Thanks!

snairdesai commented 1 year ago

Will do!

snairdesai commented 1 year ago

@ShiqiYang2022 Confirming this ran on my end, great work! One comment, I am getting these odd warning lines in terminal when running this:


Screenshot 2023-10-20 at 5 53 05 PM
Screenshot 2023-10-20 at 5 53 20 PM

Do we think the way we are handling the escape characters might be linked to importlib.util in some way? Is this also appearing on your end?

cc @jc-cisneros

ShiqiYang2022 commented 1 year ago

@snairdesai Thanks! Same warning on my end and I am investigating it!

ShiqiYang2022 commented 1 year ago

@snairdesai Maybe give it another shot after a6f828c, I think per f12dcd2 we lose some function in original importlib but not in importlib.util. It showed to be a right fix on my end. Thanks!

snairdesai commented 1 year ago

Looks perfect, thanks @ShiqiYang2022! Good to port to a PR -- feel free to assign me (I'll get to this sometime over the weekend).

ShiqiYang2022 commented 1 year ago

Summary

In this issue we fixed the error when running import.util package, described in https://github.com/gentzkow/template/issues/89#issue-1952943988. The solution was to import import.util directly instead import .util under the importlib module (more details in https://github.com/gentzkow/template/issues/89#issuecomment-1773559213).

The fixes were brought to master in #90. Final stage of the branch before merge is here.

cc: @snairdesai @jc-cisneros