LBNL-ETA / pyWinCalc

Other
27 stars 10 forks source link

Cannot run basic examples #36

Closed KevinLurtis closed 1 year ago

KevinLurtis commented 1 year ago

Hi!

Thank you for your work on pyWinCalc and the underlying library.

Unfortunately, we're having some trouble getting to run the basic examples, and would greatly appreciate some help trying to figure out what is wrong.

Description: python examples/minimum_example.py fails to run. Other examples also fail with a similar error, such as examples/single_clear.py, examples/gases.py, and examples/igsdb_double_clear_glass.py.

For the IGSDB remote API example, we have an API key, and receive the response.

Observed: Excerpt of the errors obtained, at the end of Steps to reproduce

(err-pywincalc)$ python examples/minimum_example.py 
Traceback (most recent call last):
  File "/home/kevin/repos/err-pyWinCalc/examples/minimum_example.py", line 11, in <module>
    glazing_system = pywincalc.GlazingSystem( optical_standard, solid_layers)
RuntimeError: Missing product thickness
(err-pywincalc)$ python examples/igsdb_double_clear_glass.py 
**************************************************************************
Results for a double-layer system of clear glass downloaded from the IGSDB
**************************************************************************
        Results at normal incidence for system with NFRC U-Value environmental conditions
Standard W5_NFRC_2003.std does not include a SOLAR method
Standard W5_NFRC_2003.std does not include a PHOTOPIC method
Standard W5_NFRC_2003.std does not include a TUV method
Standard W5_NFRC_2003.std does not include a SPF method
Standard W5_NFRC_2003.std does not include a TDW method
Standard W5_NFRC_2003.std does not include a TKR method
Traceback (most recent call last):
  File "/home/kevin/repos/err-pyWinCalc/examples/igsdb_double_clear_glass.py", line 57, in <module>
    results_printer.print_results(glazing_system_u_environment, glazing_system_shgc_environment)
  File "/home/kevin/repos/err-pyWinCalc/examples/results_printer.py", line 192, in print_results
    print_optical_results(glazing_system_u_env, leading_tabs=leading_tabs)
  File "/home/kevin/repos/err-pyWinCalc/examples/results_printer.py", line 186, in print_optical_results
    print_color_results(glazing_system, theta, phi, leading_tabs)
  File "/home/kevin/repos/err-pyWinCalc/examples/results_printer.py", line 156, in print_color_results
    color_results = glazing_system.color(theta, phi)
RuntimeError: Standard W5_NFRC_2003.std does not include a COLOR_TRISTIMX method

Expected: The examples run successfully, displaying the output.

Steps to reproduce.

  1. Clone the repository into a new directory:

    $ git clone https://github.com/LBNL-ETA/pyWinCalc.git err-pyWinCalc
    Cloning into 'err-pyWinCalc'...
    remote: Enumerating objects: 1675, done.
    remote: Counting objects: 100% (723/723), done.
    remote: Compressing objects: 100% (284/284), done.
    remote: Total 1675 (delta 362), reused 669 (delta 317), pack-reused 952
    Receiving objects: 100% (1675/1675), 64.53 MiB | 2.02 MiB/s, done.
    Resolving deltas: 100% (844/844), done.
    $ cd err-pyWinCalc
  2. Create a clean virtual environment with mkvirtualenvwrapper:

    $ mkvirtualenv --clear -p 3.10.10 err-pywincalc
    created virtual environment CPython3.10.10.final.0-64 in 114ms
    creator CPython3Posix(dest=/home/kevin/.pyvenvs/err-pywincalc, clear=True, no_vcs_ignore=False, global=False)
    seeder FromAppData(download=False, pip=bundle, setuptools=bundle, wheel=bundle, via=copy, app_data_dir=/home/kevin/.local/share/virtualenv)
    added seed packages: pip==23.0.1, setuptools==67.4.0, wheel==0.38.4
    activators BashActivator,CShellActivator,FishActivator,NushellActivator,PowerShellActivator,PythonActivator
    virtualenvwrapper.user_scripts creating /home/kevin/.pyvenvs/err-pywincalc/bin/predeactivate
    virtualenvwrapper.user_scripts creating /home/kevin/.pyvenvs/err-pywincalc/bin/postdeactivate
    virtualenvwrapper.user_scripts creating /home/kevin/.pyvenvs/err-pywincalc/bin/preactivate
    virtualenvwrapper.user_scripts creating /home/kevin/.pyvenvs/err-pywincalc/bin/postactivate
    virtualenvwrapper.user_scripts creating /home/kevin/.pyvenvs/err-pywincalc/bin/get_env_details
    (err-pywincalc)$ python --version
    Python 3.10.10
    (err-pywincalc)$ which python
    /home/kevin/.pyvenvs/err-pywincalc/bin/python
    (err-pywincalc)$ pip freeze --all
    pip==23.0.1
    setuptools==67.4.0
    wheel==0.38.4
  3. Follow requirements installation instructions. Because it's a linux machine, only Git and CMake:

(err-pywincalc)$ git --version
git version 2.40.0
(err-pywincalc)$ cmake --version
cmake version 3.26.0

CMake suite maintained and supported by Kitware (kitware.com/cmake)
(err-pywincalc)$ uname --all
Linux antares 6.2.7-arch1-1 #1 SMP PREEMPT_DYNAMIC Sat, 18 Mar 2023 01:06:36 +0000 x86_64 GNU/Linux
  1. Follow installation instructions, from source:
(err-pywincalc)$ pip install git+https://github.com/LBNL-ETA/pyWinCalc.git 
Collecting git+https://github.com/LBNL-ETA/pyWinCalc.git
  Cloning https://github.com/LBNL-ETA/pyWinCalc.git to /tmp/pip-req-build-5228fgkq
  Running command git clone --filter=blob:none --quiet https://github.com/LBNL-ETA/pyWinCalc.git /tmp/pip-req-build-5228fgkq
  Resolved https://github.com/LBNL-ETA/pyWinCalc.git to commit 57d430edf3d71532fbf030327eec5607c39d431f
  Running command git submodule update --init --recursive -q
  Installing build dependencies ... done
  Getting requirements to build wheel ... done
  Preparing metadata (pyproject.toml) ... done
Building wheels for collected packages: pywincalc
  Building wheel for pywincalc (pyproject.toml) ... done
  Created wheel for pywincalc: filename=pywincalc-2.4.3-cp310-cp310-linux_x86_64.whl size=1440916 sha256=ec8bfae35db405860bfbb6e1f656302ec057c4f5f271d6c513035781ff93bdd5
  Stored in directory: /tmp/pip-ephem-wheel-cache-sbe4d4ng/wheels/78/81/e1/3dc0cd9770a1582e35d58a18982d17351452717224afd96acc
Successfully built pywincalc
Installing collected packages: pywincalc
Successfully installed pywincalc-2.4.3
  1. Check that the local version is the same as the installed version:
(err-pywincalc)$ pip freeze --all
pip==23.0.1
pywincalc @ git+https://github.com/LBNL-ETA/pyWinCalc.git@57d430edf3d71532fbf030327eec5607c39d431f
setuptools==67.4.0
wheel==0.38.4
(err-pywincalc)$ git log -n 1
commit 57d430edf3d71532fbf030327eec5607c39d431f (HEAD -> main, origin/main, origin/HEAD)
Author: StephenCzarnecki <sczarnecki@lbl.gov>
Date:   Mon Oct 3 00:04:05 2022 -0400

    Added permeability factor to examples that call ProductDataOpticalNBand
  1. Run basic examples:
(err-pywincalc)$ python examples/minimum_example.py 
Traceback (most recent call last):
  File "/home/kevin/repos/err-pyWinCalc/examples/minimum_example.py", line 11, in <module>
    glazing_system = pywincalc.GlazingSystem( optical_standard, solid_layers)
RuntimeError: Missing product thickness
(err-pywincalc)$ python examples/single_clear.py 
Traceback (most recent call last):
  File "/home/kevin/repos/err-pyWinCalc/examples/single_clear.py", line 27, in <module>
    glazing_system_single_layer_u_environment = pywincalc.GlazingSystem(optical_standard=optical_standard,
RuntimeError: Missing product thickness
(err-pywincalc)$ python examples/gases.py 
Traceback (most recent call last):
  File "/home/kevin/repos/err-pyWinCalc/examples/gases.py", line 70, in <module>
    glazing_system_u_environment = pywincalc.GlazingSystem(optical_standard, solid_layers, gaps, width, height)
RuntimeError: Missing product thickness
  1. Add API key loading for IGSDB remote API examples. In examples/igsdb_interaction.py, replace igsdb_api_key with:
from typing import Final
import os

_key_name: Final = "IGSDB_API_KEY"
igsdb_api_token: Final = os.getenv(_key_name)

if igsdb_api_token is None:
    raise RuntimeError("API KEY NOT DEFINED. Define the environment variable {_key_name}")
  1. Load API key into shell:
(err-pywincalc)$ export IGSDB_API_KEY=censored-the-api-key
(err-pywincalc)$ env | grep IGSDB_API_KEY
IGSDB_API_KEY=censored-the-api-key
  1. Install requests.
(err-pywincalc)$ pip install requests
Collecting requests
  Using cached requests-2.28.2-py3-none-any.whl (62 kB)
Collecting charset-normalizer<4,>=2
  Using cached charset_normalizer-3.1.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (199 kB)
Collecting idna<4,>=2.5
  Using cached idna-3.4-py3-none-any.whl (61 kB)
Collecting urllib3<1.27,>=1.21.1
  Using cached urllib3-1.26.15-py2.py3-none-any.whl (140 kB)
Collecting certifi>=2017.4.17
  Using cached certifi-2022.12.7-py3-none-any.whl (155 kB)
Installing collected packages: urllib3, idna, charset-normalizer, certifi, requests
Successfully installed certifi-2022.12.7 charset-normalizer-3.1.0 idna-3.4 requests-2.28.2 urllib3-1.26.15
(err-pywincalc)$ pip freeze --all
certifi==2022.12.7
charset-normalizer==3.1.0
idna==3.4
pip==23.0.1
pywincalc @ git+https://github.com/LBNL-ETA/pyWinCalc.git@57d430edf3d71532fbf030327eec5607c39d431f
requests==2.28.2
setuptools==67.4.0
urllib3==1.26.15
wheel==0.38.4
  1. Run a basic IGSDB remote API example:
(err-pywincalc)$ python examples/igsdb_double_clear_glass.py 
**************************************************************************
Results for a double-layer system of clear glass downloaded from the IGSDB
**************************************************************************
        Results at normal incidence for system with NFRC U-Value environmental conditions
Standard W5_NFRC_2003.std does not include a SOLAR method
Standard W5_NFRC_2003.std does not include a PHOTOPIC method
Standard W5_NFRC_2003.std does not include a TUV method
Standard W5_NFRC_2003.std does not include a SPF method
Standard W5_NFRC_2003.std does not include a TDW method
Standard W5_NFRC_2003.std does not include a TKR method
Traceback (most recent call last):
  File "/home/kevin/repos/err-pyWinCalc/examples/igsdb_double_clear_glass.py", line 57, in <module>
    results_printer.print_results(glazing_system_u_environment, glazing_system_shgc_environment)
  File "/home/kevin/repos/err-pyWinCalc/examples/results_printer.py", line 192, in print_results
    print_optical_results(glazing_system_u_env, leading_tabs=leading_tabs)
  File "/home/kevin/repos/err-pyWinCalc/examples/results_printer.py", line 186, in print_optical_results
    print_color_results(glazing_system, theta, phi, leading_tabs)
  File "/home/kevin/repos/err-pyWinCalc/examples/results_printer.py", line 156, in print_color_results
    color_results = glazing_system.color(theta, phi)
RuntimeError: Standard W5_NFRC_2003.std does not include a COLOR_TRISTIMX method

Thank you for your time.

StephenCzarnecki commented 1 year ago

Sorry for the delay but I just released version 3 which should now be on pypi. Among other things it should hopefully simplify dealing with the optical standards.

It also attempts to simplify the example files. So now most of the example files only show one result. There are specific examples that show all of the available results for optical calculations (NFRC: https://github.com/LBNL-ETA/pyWinCalc/blob/main/examples/optical_results_NFRC.py EN-410: https://github.com/LBNL-ETA/pyWinCalc/blob/main/examples/optical_results_EN_410.py) and thermal results (ISO-15099: https://github.com/LBNL-ETA/pyWinCalc/blob/main/examples/thermal_results_ISO_15099.py).

Most of the rest of the examples now are focused on only showing how to construct what they are trying to demonstrate and only show one result for illustration purposes.

The hope is these changes make pywincalc clearer and easier to use.

Looking through the code you sent the only thing I notice is that you are running the examples from the root of the repo and not the examples folder. One issue may be that some of the examples load files by relative path so if the working directory isn't the examples folder it may cause some problems. Hopefully the changes to how the standards files work should fix some of them.

So when you get a chance can you try getting version 3.0 and trying that? There should be wheels on pypi for anything that is not a arm-based Mac (e.g. M2). There may even be a wheel that works with python 3.11 on an arm-based Mac but that hasn't been tested. But we have done some light testing on building from source on arm-based Mac's and that does seem to work.

Please let us know if this new release fixes things for you or if you are still having problems.

Thank you for your interest.

KevinLurtis commented 1 year ago

Thank you for your time.

It looks like running the examples from the example folder was the issue... Good catch! The error message had really thrown me off-course.

I've also tested out version 3.0.0, and it seems to be working too; including the IGSDB examples when using the API key. Running the examples from the examples folder works perfectly, and running from the root of the repository shows the same errors I was encountering. My problems seem to be solved.

Using the run_all_examples.py script seems to work correctly, producing values for every output.

I've only lightly gone over a few of the examples, but it does seem to help that they're more explicit with what is going on at each step. Particularly useful are the optical_results_* and thermal_results_* files. Thanks for that change!

I don't have any M2 based machine, so I'm afraid I can't be of help there.

Thank you very much for all of the help!