aquacropos / aquacrop

AquaCrop-OSPy: Python implementation of AquaCrop-OS
https://aquacropos.github.io/aquacrop/
Apache License 2.0
102 stars 73 forks source link

attempt to compile AOT function fails #40

Closed rbavery closed 2 years ago

rbavery commented 2 years ago

When I run the aquacrop-streamlit app, I get this error

RuntimeError: Attempted to compile AOT function without the compiler used by `numpy.distutils` present. If using conda try: #> conda install gcc_linux-64 gxx_linux-64

I'm setting up dependencies in a venv and not using conda. This may mean we need to add the gcc compiler dependency for a specific architecture family to the aquacrop dependencies: https://numba.pydata.org/numba-doc/dev/user/pycc.html

rbavery commented 2 years ago

It looks like the gcc dependencies can't be installed via pypi, only conda...

This indicates that if we distribute AOT compiled modules we will need to switch to a conda based setup and document that, instead of using pip in order to handle the compiler dependency. Or am I missing something?

thomasdkelly commented 2 years ago

Have you tried running the solution.py file locally first, then run pip install -e . again

Basically just overwriting the solution_aot file included in the package

thomasdkelly commented 2 years ago

I have also had issues when testing the new pypi upload, where it cant locate the solution_aot.so file even though it is inlcuded in the pip package

rbavery commented 2 years ago

I did not try that, but thanks for mentioning it. What I did instead was set up a conda environment that installed the gcc dependencies. Then I locally installed aquacrop with pip and I think I already had the compiled file so it worked. So I'm not sure but it seems like maybe gcc is a requirement to run the compiled functions?

arongergely commented 2 years ago

Shouldn't the code be compiled on target (user's system) during the pip install? Otherwise we would need to ship compiled code for each architecture and python version..

thomasdkelly commented 2 years ago

Have finally got the pypi package upload/download working. Was running into all kinds of errors while using the methods described here https://numba.pydata.org/numba-doc/dev/user/pycc.html.

One of which is similar to the point made by @arongergely that the compiled binarys only work for my local pc. pip was having a hard time building these into a wheels and so we now have to build a source distribution instead of wheels. The other reason to dot build a wheels is that we want to run a compilation script as the user pip installs the module so that the binary works for their architecture as @arongergely said.

Will create a pull request tomorrow that does this as well as creating a github action to push to pypi following a new version release.

Can go into more detail in that pull request if you have any more questions about the wheels erros etc.

thomasdkelly commented 2 years ago

And to your point @rbavery about gcc dependecy: I can pip install (and then compile) inside a fresh google colab using the code below without issue so I dont think we are assuming any crazy dependencies.

!pip install numba==0.55
!pip install -i https://test.pypi.org/simple/ aquacrop==0.4.18

from aquacrop.classes import    *
from aquacrop.core import       *
path = get_filepath('champion_climate.txt')
wdf = prepare_weather(path)

def run_model(smts,max_irr_season,year1,year2):
    maize = CropClass('Maize',PlantingDate='05/01') 
    loam = SoilClass('ClayLoam') 
    init_wc = InitWCClass(wc_type='Pct',value=[70])
    irrmngt = IrrMngtClass(IrrMethod=1,SMT=smts,) 

    # create and run model
    model = AquaCropModel(f'{year1}/05/01',f'{year2}/10/31',wdf,loam,maize,
                          IrrMngt=irrmngt,InitWC=init_wc)
    model.initialize()
    model.step(till_termination=True)
    return model.Outputs.Final

run_model([70]*4,300,2018,2018)
thomasdkelly commented 2 years ago

42