OpenMDAO / build_pyoptsparse

python script to build/install pyoptsparse with IPOPT (and optionally SNOPT)
Apache License 2.0
9 stars 15 forks source link

Could not find a version that satisfies the requirement build_pyoptsparse (from versions: none) #46

Closed weihevt closed 1 year ago

weihevt commented 1 year ago

Hello,

When I run the python -m pip install 'build_pyoptsparse' or python -m pip install 'build_pyoptsparse[paropt]', it gives me error:

ERROR: Could not find a version that satisfies the requirement build_pyoptsparse (from versions: none) ERROR: No matching distribution found for build_pyoptsparse

Thanks.

swryan commented 1 year ago

build_pyoptsparse is not currently on the Python Package Index (PyPi), so pip would not be able to find it by name unless you clone/download the source and run the command in that directory.

Rather I suggest that you install with:

python -m pip install git+https://github.com/OpenMDAO/build_pyoptsparse
weihevt commented 1 year ago

Thanks. I do downloaded the build_pyoptsparse-master folder and run the command in that folder. The got the error.

But I followed your suggestion this time and run the command:

python -m pip install git+https://github.com/OpenMDAO/build_pyoptsparse

Then it gives me:

Collecting git+https://github.com/OpenMDAO/build_pyoptsparse
  Cloning https://github.com/OpenMDAO/build_pyoptsparse to /private/var/folders/2g/t6rykpr96ql0dfwld8yy22kw0000gn/T/pip-req-build-givvftup
  Running command git clone --filter=blob:none -q https://github.com/OpenMDAO/build_pyoptsparse /private/var/folders/2g/t6rykpr96ql0dfwld8yy22kw0000gn/T/pip-req-build-givvftup
  Resolved https://github.com/OpenMDAO/build_pyoptsparse to commit 71758a586e8af383dac72802667464d3d0176efd
  Preparing metadata (setup.py) ... done
Requirement already satisfied: ansicolors in /opt/homebrew/Caskroom/miniforge/base/envs/DPM/lib/python3.9/site-packages (from build-pyoptsparse==2.0.3) (1.1.8)
Requirement already satisfied: numpy in /opt/homebrew/Caskroom/miniforge/base/envs/DPM/lib/python3.9/site-packages (from build-pyoptsparse==2.0.3) (1.21.5)
Requirement already satisfied: sqlitedict in /opt/homebrew/Caskroom/miniforge/base/envs/DPM/lib/python3.9/site-packages (from build-pyoptsparse==2.0.3) (2.0.0)
Requirement already satisfied: packaging in /opt/homebrew/Caskroom/miniforge/base/envs/DPM/lib/python3.9/site-packages (from build-pyoptsparse==2.0.3) (21.3)
Requirement already satisfied: pyparsing!=3.0.5,>=2.0.2 in /opt/homebrew/Caskroom/miniforge/base/envs/DPM/lib/python3.9/site-packages (from packaging->build-pyoptsparse==2.0.3) (3.0.6)

Looks no errors.

But when I want to use pyOptsparse in 'openmdao.api' with command:

p = om.Problem()
p.driver = om.pyOptSparseDriver(print_results=False)

It raised error saying pyOptsparse is not installed:

  File "/opt/homebrew/Caskroom/miniforge/base/envs/DPM/lib/python3.9/site-packages/openmdao/drivers/pyoptsparse_driver.py", line 197, in __init__
    raise RuntimeError('pyOptSparseDriver is not available, pyOptsparse is not installed.')
RuntimeError: pyOptSparseDriver is not available, pyOptsparse is not installed.

Another thing if I want to support ParOpt like python -m pip install 'build_pyoptsparse[paropt]', what command should I use?

Thanks.

swryan commented 1 year ago

After installing, you will have a build_pyoptsparse command available in your environment which you then can use to install a customized build of pyoptsparse with it's various optimizers. See the README for options.

From your description above it appears you did not actually invoke the command after installing.

To install with ParOpt support, you will probably need to install from a cloned or downloaded copy, since the [paropt] suffix would cause a malformed URL. (see here).

Note that the [paropt] option just ensures that you have mpi4py and Cython which are required for ParOpt. You can just install these yourself without having to use the [paropt] qualifier.

weihevt commented 1 year ago

Thanks.

I run the command build_pyoptsparse and raised errors:

build_pyoptsparse
Checking for conda-forge... OK
------------------------ Relevant environment variables -----------------------
CONDA_PREFIX: /opt/homebrew/Caskroom/miniforge/base/envs/DPM
TMPDIR: /var/folders/2g/t6rykpr96ql0dfwld8yy22kw0000gn/T/
------- Testing build environment functionality. Can be skipped with -k. ------
Using $CONDA_PREFIX for install prefix
Changed directory to $TMPDIR/tmpa7i4ip0h
Testing gcc... OK
Testing g++... OK
Testing gfortran... Traceback (most recent call last):
  File "/opt/homebrew/Caskroom/miniforge/base/envs/DPM/bin/build_pyoptsparse", line 8, in <module>
    sys.exit(perform_install())
  File "/opt/homebrew/Caskroom/miniforge/base/envs/DPM/lib/python3.9/site-packages/build_pyoptsparse.py", line 1236, in perform_install
    finish_setup()
  File "/opt/homebrew/Caskroom/miniforge/base/envs/DPM/lib/python3.9/site-packages/build_pyoptsparse.py", line 1144, in finish_setup
    check_sanity()
  File "/opt/homebrew/Caskroom/miniforge/base/envs/DPM/lib/python3.9/site-packages/build_pyoptsparse.py", line 1094, in check_sanity
    check_compiler_sanity()
  File "/opt/homebrew/Caskroom/miniforge/base/envs/DPM/lib/python3.9/site-packages/build_pyoptsparse.py", line 1017, in check_compiler_sanity
    run_cmd(cmd_list=[os.environ['FC'], '-o', 'hello_f', 'hello.f90'])
  File "/opt/homebrew/Caskroom/miniforge/base/envs/DPM/lib/python3.9/site-packages/build_pyoptsparse.py", line 367, in run_cmd
    raise inst
  File "/opt/homebrew/Caskroom/miniforge/base/envs/DPM/lib/python3.9/site-packages/build_pyoptsparse.py", line 364, in run_cmd
    result = subprocess.run(cmd_list, check=do_check, capture_output=True, text=True)
  File "/opt/homebrew/Caskroom/miniforge/base/envs/DPM/lib/python3.9/subprocess.py", line 528, in run
    raise CalledProcessError(retcode, process.args,
subprocess.CalledProcessError: Command '['gfortran', '-o', 'hello_f', 'hello.f90']' returned non-zero exit status 1.

Is there something required of fortran? I didn't used fortran before.

Installed from cloned or downloaded copy gives me error, I can omitted the ParOpt support first. As I saw the README options, I thought I can used the command build_pyoptsparse -a to install ParOpt support later.

Another thing is does command build_pyoptsparse by default installed both of 'IPOPT' and 'SNOPT' optimizer?

Thanks

swryan commented 1 year ago

Yes, you do need to have a FORTRAN compiler available to build the optimizers used by pyoptsparse. Have you looked at the documentation for pyoptsparse itself (here)? This script just facilitates building/installing pyoptsparse with the various options described by the arguments.

Yes, you are able to install ParOpt support later with the -a argument as you describe.. As I mentioned previously, the [paropt] option just tries to makes sure you have the required dependencies to build ParOpt (mpi4py and cython) so that using -a will work.

IPOPT is included by default (you have to specify --no-ipopt if you don't want it) but SNOPT is not because it is commercial software that you have to purchase separately.

If you just need a basic pyoptsparse install with IPOPT support, then I might suggest that you install it from conda-forge rather than using this package, as noted here:

conda install -c conda-forge pyoptsparse

That may save you the trouble of getting a FORTRAN compiler, etc.

If you're goal is to work with ParOpt and/or SNOPT, then you will need the compilers, mpi4py, etc. and then this script should be helpful.

weihevt commented 1 year ago

Thanks.

Got it. I followed your suggestion and used conda install pyoptsparse and it works for me. Do not raise error of FORTRAN compiler. p = om.Problem()' and 'p.driver = om.pyOptSparseDriver(print_results=False) also work.

Got it. I don't have a commercial license of SNOPT so I don't worry about it.

Right now I don't need parallel so I omitted Paropt first.

Thanks.

swryan commented 1 year ago

Great.. Glad you are up and running.

weihevt commented 1 year ago

Thanks so much. I closed the issue.