Skip to content

Commit

Permalink
Merge branch 'develop' of github.com:SModelS/smodels into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
andlessa committed Jan 17, 2024
2 parents a6e9ba3 + e6439fd commit 5df156b
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 43 deletions.
42 changes: 10 additions & 32 deletions smodels/installation.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
from __future__ import print_function
import sys
import os
from typing import Union
from semver import VersionInfo

def installDirectory():
"""
Expand Down Expand Up @@ -127,32 +129,6 @@ def authors():
authors += to_add
return authors

def _toTuple_ ( ver ):
""" convert version string to tuple """
a = ver.replace(" ",".",1).split(".")
for ctr,el in enumerate(a):
try:
a[ctr]=int(el)
except ValueError:
a[ctr]=el
b=[]
for i in a:
found=False
for pf in [ "rc", "post", "pre" ]:
if type(i)==str and pf in i:
found=True
minor = i[:i.find(pf)]
try:
minor = int(minor)
except (ValueError,TypeError):
pass
b.append ( minor )
b.append ( i[i.find(pf):] )
continue
if not found:
b.append ( i )
return tuple(b)

def requirements():
ret=[]
f = open("%s/smodels/share/requirements.txt" % installDirectory())
Expand All @@ -161,20 +137,22 @@ def requirements():
f.close()
return ret

def version(astuple=False):
def version( return_object : bool = False ) -> Union[str,VersionInfo]:
"""
Print version number of the SModelS framework.
Returns version number of the SModelS framework.
:param return_object: Return a semver VersionInfo object instead of string
:returns: version, either as string or as semver VersionInfo object
"""
f = open("%s/smodels/version" % installDirectory())
f = open( f"{installDirectory()}/smodels/version" )
l = f.readline()
f.close()
l = l.replace("\n", "")
l.strip()
if not astuple:
if not return_object:
return l
return _toTuple_ ( l )

import semver
return semver.parse ( l )

def license():
"""
Expand Down
22 changes: 11 additions & 11 deletions smodels/matching/theoryPrediction.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from smodels.matching import clusterTools
from smodels.base.smodelsLogging import logger
from smodels.statistics.statsTools import StatsComputer
from typing import Union, Text
from typing import Union, Text, Dict
import numpy as np

__all__ = [ "TheoryPrediction", "theoryPredictionsFor", "TheoryPredictionsCombiner" ]
Expand Down Expand Up @@ -397,7 +397,7 @@ def __new__(cls,theoryPredictions: list, slhafile=None, deltas_rel=None):
def __init__(self, theoryPredictions: list, slhafile=None, deltas_rel=None):
"""
Constructor.
:param theoryPredictions: the List of theory predictions
:param slhafile: optionally, the slhafile can be given, for debugging
:param deltas_rel: relative uncertainty in signal (float).
Expand Down Expand Up @@ -562,7 +562,7 @@ def __init__(self, theoryPredictions=None, maxCond=None):
condition violation < maxCond.
"""
self._theoryPredictions = []
if theoryPredictions and isinstance(theoryPredictions,
if theoryPredictions and isinstance(theoryPredictions,
(TheoryPredictionList,list)):

if not maxCond:
Expand Down Expand Up @@ -623,16 +623,16 @@ def sortTheoryPredictions(self):
)


def theoryPredictionsFor(database, smsTopDict, maxMassDist=0.2,
useBestDataset=True, combinedResults=True,
deltas_rel=None):
def theoryPredictionsFor(database : Database, smsTopDict : Dict,
maxMassDist : float = 0.2, useBestDataset : bool = True,
combinedResults : bool = True, deltas_rel : Union[None,float] = None):
"""
Compute theory predictions for the given experimental result, using the list of
SMS in smsTopDict.
For each Txname appearing in expResult, it collects the SMS and
efficiencies, combine the SMS and compute the conditions (if exist).
:parameter expResult: expResult to be considered (ExpResult object), if list of ExpResults is given, produce theory predictions for all
:parameter database: the database with the selected experimental results
:parameter smsTopDict: dictionary of SMS, where the canonical names are keys and the TheorySMS objects are values.
(TopologyDict object)
:parameter maxMassDist: maximum mass distance for clustering SMS (float)
Expand Down Expand Up @@ -661,7 +661,7 @@ def theoryPredictionsFor(database, smsTopDict, maxMassDist=0.2,
expSMSDict = database.expSMSDict
# Compute dictionary with matches:
smsMatch = expSMSDict.getMatchesFrom(smsTopDict)

ret = []
for expResult in database.expResultList:
dataSetResults = []
Expand All @@ -672,11 +672,11 @@ def theoryPredictionsFor(database, smsTopDict, maxMassDist=0.2,
dataSetResults.append(predList)
if not dataSetResults: # no results at all?
continue

# For results with more than one dataset keep all dataset predictions
if len(dataSetResults) == 1: # only a single dataset? Easy case.
expResults = dataSetResults[0]

# if useBestDataSet=False and combinedResults=False:
elif not useBestDataset and not combinedResults:
expResults = sum(dataSetResults)
Expand Down Expand Up @@ -912,7 +912,7 @@ def _getSMSFor(dataset,smsMatch,smsDict):
sms_orig.setTestedBy(dataset.globalInfo.type)
newSMS.eff = eff
newSMS.txname = txname
newSMS.txlabel = smsLabel
newSMS.txlabel = smsLabel
smsList.append(newSMS)

return smsList
Expand Down
1 change: 1 addition & 0 deletions smodels/share/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ pyslha>=3.1.0
pyhf>=0.6.1
jsonpatch>=1.25
jsonschema>=3.2.0
semver>=2.0.0

0 comments on commit 5df156b

Please sign in to comment.