-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Copy over PyBaMM citations code Also add license notice * Minimal working version of citations function By default, just cite the flavio paper. Removed the read_citation method, as rather than reading the bibtex from a file, it seems better to just ouput the INSPIRE texkeys and worry about getting bibtex from INSPIRE later. (E.g. if you print to a .tex file, you could use INSPIRE's bibliography generator at https://inspirehep.net/bibliography-generator, or if fixed David's inspiretools python package.) * A initial citation reference for testing The way flavio does Gamma_12 is based on the a,b,c notation originally introduced in the 2003 BBLN paper * Add SM_citations function to Observable class Gives the theory papers to be cited for an observable, using a throwaway instance. As part of this, move the registering of the flavio paper out of the constructor so you don't get that as well. * Merge _reset method into constructor Since this only gets used here, just do it in the constructor. (In the original PyBaMM version the _reset just gets used for testing, which I think we want to do slightly differently anyway.) * Add docstring to SM_citations * Copy over the PyBaMM citation test class * Revert "Merge _reset method into constructor" This reverts commit a6a545e. Yeah, we need the reset method for testing... * Rejig the print functions to return a list Return something instead of printing directly, unless outputting to a file. * Add some tests of the citation functionality * Fix typo in docstring * Citations for B->Xgamma Note the CP asymmetry needs citations adding, wherever the numbers in ka1_r, ka2_r, ka1_i came from. * Citations for meson mixing Just the Inami-Lim function - everything else worth citing comes in through parameters (fB, B, RG factors) * Add citations for W and Z observables * Improve theory citation function Allow for arguments to be passed to prediction function. Also change the name as you are really getting the citations for a general theory prediction, not just the SM. * Add citations for beta decay * Fix failing test Forgot to update the test when I renamed the function * Citations for mu and tau decays * Citations for quark mass conversions * Citations for K decays * Add D decay form factor citations * Add a bunch of b decay citations * Add bvll citations * Add B -> P formfactor citations * Add B -> gamma formfactor citations * Add citations for B->V formfactors * Small change to docstrings * Add citations for Higgs stuff I'm assuming all the numbers come (indirectly) from 1911.07866 as mentioned in the release notes for flavio v2 * Adds citations for B->llgamma * Fix indentation Got borked when I rebased * Move copyright notice to appropriate file * Give citations instance a unique name * Correct docstring * Fix code typo Somehow this find+replace got mucked up * Improve internals of the citation class Update tests and the theory_citation function too * Remove tex citation string method, add properties * Add convenience `register_citation` method * use multiprocessing.Array * raise meaningful error meassge if inspire key not in YAML * Add docstrings for the main methods * Update and add tests Specifically test that a multithreaded computation works and gives the same citations as single threaded. * Update tests Remove the test for a "unknown" inspire key, since it becomes a "known" inspirekey as soon as we re-run update_citations.py. Add a test to check that the list of "known" citations matches what's in the source code. * improve regexp in `extract_citations` function Co-authored-by: Peter Stangl <peter.stangl@ph.tum.de>
- Loading branch information
1 parent
7e0502c
commit 16fc707
Showing
43 changed files
with
391 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
# Inspired by pybamm.citations | ||
# https://github.com/pybamm-team/PyBaMM | ||
|
||
from multiprocessing import Array | ||
import flavio | ||
import sys | ||
from itertools import compress | ||
import ctypes | ||
import yaml | ||
import pkgutil | ||
|
||
|
||
class CitationScope: | ||
|
||
def __enter__(self): | ||
self._citations_global = flavio.citations | ||
flavio.citations = Citations() | ||
return flavio.citations | ||
|
||
def __exit__(self, type, value, traceback): | ||
flavio.citations = self._citations_global | ||
|
||
|
||
class Citations: | ||
|
||
collect = CitationScope | ||
__all_citations = set(yaml.safe_load( | ||
pkgutil.get_data('flavio', 'data/citations.yml') | ||
)) | ||
|
||
def __init__(self, initial_citations=[]): | ||
self._initial_citations = set(initial_citations) | ||
self._all_citations = { | ||
k:i for i,k in | ||
enumerate(sorted(self.__all_citations | self._initial_citations)) | ||
} | ||
self._array = Array(ctypes.c_bool, len(self._all_citations)) | ||
for inspire_key in self._initial_citations: | ||
self.register(inspire_key) | ||
|
||
def __iter__(self): | ||
for citation in self.set: | ||
yield citation | ||
|
||
def __str__(self): | ||
return ",".join(self.set) | ||
|
||
@property | ||
def set(self): | ||
return set(compress(sorted(self._all_citations.keys()), self._array)) | ||
|
||
@property | ||
def string(self): | ||
return str(self) | ||
|
||
def register(self, inspire_key): | ||
"""Register a paper to be cited. The intended use is that this method | ||
should be called only when the referenced functionality is actually being used. | ||
Parameters | ||
---------- | ||
key : str | ||
The INSPIRE texkey for the paper to be cited | ||
""" | ||
try: | ||
self._array[self._all_citations[inspire_key]] = True | ||
except KeyError: | ||
from flavio.util import get_datapath | ||
yaml_path = get_datapath('flavio', 'data/citations.yml') | ||
raise KeyError( | ||
f'The inspire key must be contained in {yaml_path}. ' | ||
f'The key `{inspire_key}` was not found there.' | ||
) | ||
|
||
|
||
def clear(self): | ||
"""Clear the list of cited papers (including any default citations).""" | ||
self._array[:] = [False]*len(self._array) | ||
|
||
def reset(self): | ||
"""Reset the list of cited papers back to only the default ones.""" | ||
self.clear() | ||
for inspire_key in self._initial_citations: | ||
self.register(inspire_key) | ||
|
||
|
||
sys.modules[__name__] = Citations(["Straub:2018kue"]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
- Antonelli:2010yf | ||
- Asatrian:2003vq | ||
- Awramik:2003rn | ||
- Beneke:2001at | ||
- Beneke:2003az | ||
- Beneke:2004dp | ||
- Benson:2003kp | ||
- Bernard:2009zm | ||
- Bjorn:2016zlr | ||
- Bobeth:2013uxa | ||
- Boer:2014kda | ||
- Bourrely:2008za | ||
- Brignole:2004ah | ||
- Brivio:2017vri | ||
- Brod:2010hi | ||
- Buras:2006gb | ||
- Buras:2015yba | ||
- Caprini:1997mu | ||
- Chobanova:2017rkj | ||
- Cirigliano:2007ga | ||
- Descotes-Genon:2015hea | ||
- Falkowski:2019hvp | ||
- Freitas:2014hra | ||
- Gambino:2011cq | ||
- Gonzalez-Alonso:2018omy | ||
- Gorbahn:2006bm | ||
- Greub:2008cy | ||
- Guadagnoli:2016erb | ||
- Gubernari:2018wyi | ||
- Huber:2015sra | ||
- Inami:1980fz | ||
- Kitano:2002mt | ||
- Kozachuk:2017mdk | ||
- Kruger:2002gf | ||
- Kuno:1999jp | ||
- Melikhov:2004mk | ||
- Misiak:2006ab | ||
- Misiak:2015xwa | ||
- Pich:2013lsa | ||
- Seidel:2004jh | ||
- Straub:2015ica | ||
- fakename:2020abc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#! /usr/bin/env python3 | ||
|
||
"""Standalone helper script to update the list of citations referenced in the | ||
flavio source code.""" | ||
|
||
import argparse | ||
import logging | ||
import sys | ||
import yaml | ||
import pkgutil | ||
logging.basicConfig(level=logging.INFO) | ||
|
||
def main(argv): | ||
parser = argparse.ArgumentParser(description='Update the list of citations referenced in the flavio source code.') | ||
args = parser.parse_args() | ||
|
||
from flavio.util import get_datapath, extract_citations | ||
|
||
filename = get_datapath('flavio', 'data/citations.yml') | ||
with open(filename, 'w') as f: | ||
f.write(yaml.dump(sorted(extract_citations()))) | ||
logging.info(f"Saved updated citations to {filename}") | ||
|
||
if __name__ == '__main__': | ||
main(sys.argv) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.