Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions hepdata/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,9 +223,9 @@ def do_unload(records_to_unload):

@utils.command()
@with_appcontext
@click.option('--endpoint', '-e', type=str, help='Specific endpoint to update (e.g. "rivet" or "MadAnalysis" or "SModelS" or "CheckMATE" or "HackAnalysis" or "Combine"). Omit for all.')
@click.option('--endpoint', '-e', type=str, help='Specific endpoint to update (e.g. "rivet" or "MadAnalysis" or "SModelS" or "CheckMATE" or "HackAnalysis" or "Combine" or "GAMBIT"). Omit for all.')
Comment thread
mhabedan marked this conversation as resolved.
def find_and_add_record_analyses(endpoint):
"""Finds analyses such as Rivet, MadAnalysis 5, SModelS, CheckMATE, HackAnalysis and Combine and adds them to records."""
"""Finds analyses such as Rivet, MadAnalysis 5, SModelS, CheckMATE, HackAnalysis, Combine and GAMBIT and adds them to records."""
update_analyses(endpoint)


Expand Down
3 changes: 3 additions & 0 deletions hepdata/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,9 @@ def _(x):
'url': 'https://creativecommons.org/licenses/by/4.0'
},
},
'GAMBIT': {
'endpoint_url': 'https://gambitbsm.org/analyses.json',
},
#'ufo': {},
#'xfitter': {},
#'applgrid': {},
Expand Down
2 changes: 1 addition & 1 deletion hepdata/ext/opensearch/document_enhancers.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def add_shortened_authors(doc):

def add_analyses(doc):
"""
Add analyses links such as Rivet, MadAnalysis 5, SModelS, CheckMATE, HackAnalysis, Combine, HistFactory and NUISANCE to the index.
Add analyses links such as Rivet, MadAnalysis 5, SModelS, CheckMATE, HackAnalysis, Combine, HistFactory, NUISANCE and GAMBIT to the index.

:param doc:
:return:
Expand Down
1 change: 1 addition & 0 deletions hepdata/modules/records/assets/js/hepdata_common.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ HEPDATA.file_type_to_details = {
"checkmate": {"icon": "area-chart", "description": "CheckMATE Analysis"},
"hackanalysis": {"icon": "area-chart", "description": "HackAnalysis Analysis"},
"combine": {"icon": "area-chart", "description": "Combine Analysis"},
"gambit": {"icon": "area-chart", "description": "GAMBIT analysis"},
"xfitter": {"icon": "area-chart", "description": "xFitter Analysis"},
"applgrid": {"icon": "area-chart", "description": "APPLgrid Analysis"},
"ufo": {"icon": "rocket", "description": "Universal Feynrules Output (UFO)"},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ <h4>Add Resource for <span id="selected_resource_item">Submission</span></h4>
<option value="HackAnalysis">HackAnalysis</option>
<option value="Combine">Combine</option>
<option value="rivet">Rivet</option>
<option value="GAMBIT">GAMBIT</option>
<option value="fastnlo">fastNLO</option>
<option value="ufo">Universal Feynrules Output (UFO)</option>
<option value="xfitter">xFitter</option>
Expand Down
193 changes: 134 additions & 59 deletions hepdata/modules/records/utils/analyses.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@
@shared_task
def update_analyses(endpoint=None):
"""
Update (Rivet, MadAnalysis 5, SModelS, CheckMATE, HackAnalysis and Combine) analyses and remove outdated resources.
Update (Rivet, MadAnalysis 5, SModelS, CheckMATE, HackAnalysis, Combine, and GAMBIT) analyses and remove outdated resources.
Allow bulk subscription to record update notifications if "subscribe_user_id" in endpoint.
Add optional "description" and "license" fields if present in endpoint.

:param endpoint: either "rivet" or "MadAnalysis" or "SModelS" or "CheckMATE" or "HackAnalysis" or "Combine" or None (default) for all
:param endpoint: either "rivet" or "MadAnalysis" or "SModelS" or "CheckMATE" or "HackAnalysis" or "Combine" or "GAMBIT" or None (default) for all
"""
endpoints = current_app.config["ANALYSES_ENDPOINTS"]
for analysis_endpoint in endpoints:
Expand All @@ -64,62 +64,129 @@ def update_analyses(endpoint=None):

if response and response.status_code == 200:

analyses = response.json()

analysis_resources = DataResource.query.filter_by(file_type=analysis_endpoint).all()

# Check for missing analyses.
for record in analyses:
submission = get_latest_hepsubmission(inspire_id=record, overall_status='finished')

if submission:
num_new_resources = 0

for analysis in analyses[record]:
_resource_url = endpoints[analysis_endpoint]["url_template"].format(analysis)

if not is_resource_added_to_submission(submission.publication_recid, submission.version,
_resource_url):

log.info('Adding {} analysis to ins{} with URL {}'.format(
analysis_endpoint, record, _resource_url)
)
new_resource = DataResource(
file_location=_resource_url,
file_type=analysis_endpoint)

if "description" in endpoints[analysis_endpoint]:
new_resource.file_description = str(endpoints[analysis_endpoint]["description"])

if "license" in endpoints[analysis_endpoint]:
resource_license = get_license(endpoints[analysis_endpoint]["license"])
new_resource.file_license = resource_license.id

submission.resources.append(new_resource)
num_new_resources += 1

else:

# Remove resources from 'analysis_resources' list.
resources = list(filter(lambda a: a.file_location == _resource_url, analysis_resources))
for resource in resources:
analysis_resources.remove(resource)

if num_new_resources:

try:
db.session.add(submission)
db.session.commit()
latest_submission = get_latest_hepsubmission(inspire_id=record)
if submission.version == latest_submission.version:
index_record_ids([submission.publication_recid])
except Exception as e:
db.session.rollback()
log.error(e)
r_json = response.json()
new_json = "analyses" in r_json

if new_json:
Comment thread
GraemeWatt marked this conversation as resolved.

# Check for missing analyses.
for ana in r_json["analyses"]:
inspire_id = ana["inspire_id"]
submission = get_latest_hepsubmission(inspire_id=str(inspire_id), overall_status='finished') # TODO: make inspire_id an int

else:
log.debug("An analysis is available in {0} but with no equivalent in HEPData (ins{1}).".format(
analysis_endpoint, record))
if submission:
num_new_resources = 0

for implementation in ana["implementations"]:
ana_name = implementation["name"]
ana_path = implementation["path"] if "path" in implementation else ""
_resource_url = r_json["url_templates"]["main_url"]
prev_url = None
n_tries, max_tries = 0, 10
while _resource_url!=prev_url and n_tries<max_tries:
prev_url = _resource_url
_resource_url = _resource_url.format(name=ana_name, path=ana_path)
n_tries += 1
Comment thread
mhabedan marked this conversation as resolved.

if not is_resource_added_to_submission(submission.publication_recid, submission.version,
_resource_url):

log.info('Adding {} analysis to ins{} with URL {}'.format(
analysis_endpoint, inspire_id, _resource_url)
)
new_resource = DataResource(
file_location=_resource_url,
file_type=analysis_endpoint,
file_description=r_json["implementations_description"]
)

if "license" in r_json:
resource_license = get_license(r_json["license"])
new_resource.file_license = resource_license.id

submission.resources.append(new_resource)
num_new_resources += 1

else:

# Remove resources from 'analysis_resources' list.
resources = list(filter(lambda a: a.file_location == _resource_url, analysis_resources))
for resource in resources:
analysis_resources.remove(resource)

if num_new_resources:

try:
db.session.add(submission)
db.session.commit()
latest_submission = get_latest_hepsubmission(inspire_id=inspire_id)
if submission.version == latest_submission.version:
index_record_ids([submission.publication_recid])
except Exception as e:
db.session.rollback()
log.error(e)

else:
log.debug("An analysis is available in {0} but with no equivalent in HEPData (ins{1}).".format(
analysis_endpoint, inspire_id))

else: # old JSON file
analyses = r_json

# Check for missing analyses.
for record in analyses:
submission = get_latest_hepsubmission(inspire_id=record, overall_status='finished')

if submission:
num_new_resources = 0

for analysis in analyses[record]:
_resource_url = endpoints[analysis_endpoint]["url_template"].format(analysis)

if not is_resource_added_to_submission(submission.publication_recid, submission.version,
_resource_url):

log.info('Adding {} analysis to ins{} with URL {}'.format(
analysis_endpoint, record, _resource_url)
)
new_resource = DataResource(
file_location=_resource_url,
file_type=analysis_endpoint)

if "description" in endpoints[analysis_endpoint]:
new_resource.file_description = str(endpoints[analysis_endpoint]["description"])

if "license" in endpoints[analysis_endpoint]:
resource_license = get_license(endpoints[analysis_endpoint]["license"])
new_resource.file_license = resource_license.id

submission.resources.append(new_resource)
num_new_resources += 1

else:

# Remove resources from 'analysis_resources' list.
resources = list(filter(lambda a: a.file_location == _resource_url, analysis_resources))
for resource in resources:
analysis_resources.remove(resource)

if num_new_resources:

try:
db.session.add(submission)
db.session.commit()
latest_submission = get_latest_hepsubmission(inspire_id=record)
if submission.version == latest_submission.version:
index_record_ids([submission.publication_recid])
except Exception as e:
db.session.rollback()
log.error(e)

else:
log.debug("An analysis is available in {0} but with no equivalent in HEPData (ins{1}).".format(
analysis_endpoint, record))

if analysis_resources:
# Extra resources that were not found in the analyses JSON file.
Expand Down Expand Up @@ -154,10 +221,18 @@ def update_analyses(endpoint=None):
if "subscribe_user_id" in endpoints[analysis_endpoint]:
user = get_user_from_id(endpoints[analysis_endpoint]["subscribe_user_id"])
if user:
for record in analyses:
submission = get_latest_hepsubmission(inspire_id=record, overall_status='finished')
if submission and not is_current_user_subscribed_to_record(submission.publication_recid, user):
subscribe(submission.publication_recid, user)
# Check for missing analyses.
if new_json:
for ana in r_json["analyses"]:
submission = get_latest_hepsubmission(inspire_id=str(ana["inspire_id"]), overall_status='finished')
if submission and not is_current_user_subscribed_to_record(submission.publication_recid, user):
subscribe(submission.publication_recid, user)

else: # old JSON file
for record in analyses:
submission = get_latest_hepsubmission(inspire_id=record, overall_status='finished')
if submission and not is_current_user_subscribed_to_record(submission.publication_recid, user):
subscribe(submission.publication_recid, user)

else:
log.debug("No endpoint url configured for {0}".format(analysis_endpoint))
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,13 @@ <h4>Other useful searches</h4>
(ProSelecta analysis for use with NUISANCE)
</span>
</li>
<li>
<a href='/search?q=analysis:GAMBIT&sort_by=latest'
target="_new">analysis:GAMBIT</a>
<span class="text-muted">
(GAMBIT analysis)
</span>
</li>
</ul>
</li>

Expand Down
8 changes: 8 additions & 0 deletions tests/records_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -1117,6 +1117,14 @@ def test_update_analyses(app):
assert license_data.name == 'cc-by-4.0'
assert license_data.url == 'https://creativecommons.org/licenses/by/4.0'

# Import a record that has an associated GAMBIT analysis
import_records(['ins1827025'], synchronous=True)
analysis_resources = DataResource.query.filter_by(file_type='GAMBIT').all()
assert len(analysis_resources) == 0
update_analyses('GAMBIT')
analysis_resources = DataResource.query.filter_by(file_type='GAMBIT').all()
assert len(analysis_resources) == 1
assert analysis_resources[0].file_location == 'https://github.com/GambitBSM/gambit_2.6/blob/release_2.6/ColliderBit/src/analyses/Analysis_ATLAS_13TeV_0LEP_139invfb.cpp'

def test_generate_license_data_by_id(app):
"""
Expand Down