peterridolfi / Pyhf-to-Combine-converter

Tool to convert models from pyhf to CMS Combine and vise versa
MIT License
7 stars 1 forks source link

Tutorial Python API example needs to have `options` argument provided #31

Open matthewfeickert opened 2 years ago

matthewfeickert commented 2 years ago

Follow up to Issue #13 and Issue #14. The tutorial example for the Python API doesn't provide an options argument

https://github.com/peterridolfi/Pyhf-to-Combine-converter/blob/612107b11fcabb2f6b62fb98d35151be2cbc4dd9/docs/tutorial.py#L5

to pyhf_converted_from_datacard

https://github.com/peterridolfi/Pyhf-to-Combine-converter/blob/612107b11fcabb2f6b62fb98d35151be2cbc4dd9/src/pyhf_combine_converter/combine_to_pyhf.py#L316

This is automatically provided by the CLI API

https://github.com/peterridolfi/Pyhf-to-Combine-converter/blob/612107b11fcabb2f6b62fb98d35151be2cbc4dd9/src/pyhf_combine_converter/combine_to_pyhf.py#L341-L356

but it needs to be provided explicitly with the Python API or else HiggsAnalysis/CombinedLimit/DatacardParser.py will raise a AttributeError.

$ docker run \
    --rm \
    -ti \
    -P \
    --device /dev/fuse \
    --cap-add SYS_ADMIN \
    --security-opt apparmor:unconfined \
    -e CVMFS_MOUNTS="cms.cern.ch oasis.opensciencegrid.org" \
    pyhf/pyhf-combine-converter:cmssw-11.2.0-python3
MY_UID variable not specified, defaulting to cmsusr user id (1000)
MY_GID variable not specified, defaulting to cmsusr user group id (1000)
Mounting the filesystem "cms.cern.ch" ... DONE
Mounting the filesystem "oasis.opensciencegrid.org" ... DONE
Checking CVMFS mounts ... DONE
    The following CVMFS folders have been successfully mounted:
        cms.cern.ch
        oasis.opensciencegrid.org

# Sourcing cmsenv ... DONE
[cmsusr@7b2fc7d5933b workarea]$ git clone https://github.com/peterridolfi/Pyhf-to-Combine-converter.git
Cloning into 'Pyhf-to-Combine-converter'...
remote: Enumerating objects: 959, done.
remote: Counting objects: 100% (209/209), done.
remote: Compressing objects: 100% (102/102), done.
remote: Total 959 (delta 117), reused 162 (delta 84), pack-reused 750
Receiving objects: 100% (959/959), 17.96 MiB | 23.58 MiB/s, done.
Resolving deltas: 100% (561/561), done.
[cmsusr@7b2fc7d5933b workarea]$ cd Pyhf-to-Combine-converter
[cmsusr@7b2fc7d5933b Pyhf-to-Combine-converter]$ python3 -m pip install --upgrade pip
[cmsusr@7b2fc7d5933b Pyhf-to-Combine-converter]$ python3 -m pip install .
[cmsusr@7b2fc7d5933b Pyhf-to-Combine-converter]$ cd test/
[cmsusr@7b2fc7d5933b test]$ python3 ../docs/tutorial.py 
Traceback (most recent call last):
  File "../docs/tutorial.py", line 5, in <module>
    pyhf_converted_from_datacard(input_datacard = "converted_datacard.txt", outfile = "pyhf_workspace.json")
  File "/home/cmsusr/.local/lib/python3.8/site-packages/pyhf_combine_converter/combine_to_pyhf.py", line 320, in pyhf_converted_from_datacard
    data_card = DP.parseCard(file=dc_file, options=options)
  File "/home/cmsusr/CMSSW_11_2_0/python/HiggsAnalysis/CombinedLimit/DatacardParser.py", line 354, in parseCard
    setattr(options, "evaluateEdits", True)
AttributeError: 'NoneType' object has no attribute 'evaluateEdits'
matthewfeickert commented 2 years ago

https://github.com/peterridolfi/Pyhf-to-Combine-converter/commit/cc6ee5c271cb95d11b26a2661b99339bebc5bd6f doesn't solve this as the default is None already. So it needs additional information of a evaluateEdits key word arg to be given.