Skip to content

Commit fdafb22

Browse files
Merge branch 'master' of github.com:QInfer/python-qinfer into feature-hyper-heuristic-optimisation
2 parents 8d35435 + 4d0aee3 commit fdafb22

File tree

13 files changed

+596
-29
lines changed

13 files changed

+596
-29
lines changed

doc/source/apiref/domains.rst

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,16 @@ Class Reference
3232
.. autoclass:: Domain
3333
:members:
3434

35+
36+
:class:`ProductDomain` - Cartesian product of multiple domains
37+
--------------------------------------------------------------
38+
39+
Class Reference
40+
~~~~~~~~~~~~~~~
41+
.. autoclass:: ProductDomain
42+
:members:
43+
44+
3545
:class:`RealDomain` - (A subset of) Real Numbers
3646
------------------------------------------------
3747

@@ -58,4 +68,4 @@ This domain is used by :class:`MultinomialModel`.
5868
Class Reference
5969
~~~~~~~~~~~~~~~
6070
.. autoclass:: MultinomialDomain
61-
:members:
71+
:members:

doc/source/guide/citing.rst

Lines changed: 159 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
1+
..
2+
This work is licensed under the Creative Commons Attribution-
3+
NonCommercial-ShareAlike 3.0 Unported License. To view a copy of this
4+
license, visit http://creativecommons.org/licenses/by-nc-sa/3.0/ or send a
5+
letter to Creative Commons, 444 Castro Street, Suite 900, Mountain View,
6+
California, 94041, USA.
7+
8+
.. _citing_guide:
9+
10+
.. currentmodule:: qinfer
11+
12+
Citing QInfer and Related Projects
13+
==================================
14+
15+
Citing Released Versions
16+
------------------------
17+
18+
If you use **QInfer** in your publication or presentation, we would appreciate it
19+
if you cited our work. We recommend citing **QInfer** by using the BibTeX
20+
entry::
21+
22+
@misc{qinfer-1_0,
23+
author = {Christopher Granade and
24+
Christopher Ferrie and
25+
Steven Casagrande and
26+
Ian Hincks and
27+
Michal Kononenko and
28+
Thomas Alexander and
29+
Yuval Sanders},
30+
title = {{QInfer}: Library for Statistical Inference in Quantum Information},
31+
month = september,
32+
year = 2016,
33+
doi = {10.5281/zenodo.157007},
34+
url = {http://dx.doi.org/10.5281/zenodo.157007}
35+
}
36+
37+
38+
Pre-Release Versions
39+
--------------------
40+
41+
If you wish to cite **QInfer** functionality that has not yet appeared in a
42+
released version, it may be helpful
43+
to cite a given SHA hash as listed on
44+
`GitHub <https://github.com/QInfer/python-qinfer/commits/master>`_ (the
45+
hashes of each commit are listed on the right hand side of the page).
46+
A recommended BibTeX entry for citing a particular commit is::
47+
48+
@misc{qinfer-prerelease,
49+
author = {Christopher Granade and
50+
Christopher Ferrie and
51+
Steven Casagrande and
52+
Ian Hincks and
53+
Michal Kononenko and
54+
Thomas Alexander and
55+
Yuval Sanders},
56+
title = {{QInfer}: Library for Statistical Inference in Quantum Information},
57+
month = may,
58+
year = 2016,
59+
url = "https://github.com/QInfer/python-qinfer/commit/bc3736c",
60+
note = {Version \texttt{bc3736c}.}
61+
}
62+
63+
In this example, ``bc3736c`` should be replaced by the
64+
particular commit being cited, and the date should be replaced by the date
65+
of that commit.
66+
67+
Automatic Citation Collection
68+
-----------------------------
69+
70+
QInfer also supports the use of the `duecredit`_ project to automatically
71+
collect citations for a bibliography. This support is still experimental,
72+
and may not yet generate complete bibliographies, so please manually check
73+
the resulting bibliography. In any case, to get started, install `duecredit`_::
74+
75+
$ pip install duecredit
76+
77+
If your project then uses a script to generate and/or analyze data, then you
78+
can use `duecredit`_ to collect citations for Python modules and functions
79+
called by your script. For example, if your project can be run as
80+
`python script.py`, use the following command to collect a bibliography::
81+
82+
$ python -m duecredit script.py
83+
84+
Alternatively, it may be more reliable to use environment variables to turn
85+
on `duecredit`_ collection, since this approach also works with
86+
Jupyter Notebook::
87+
88+
$ export DUECREDIT_ENABLE=yes # Bash
89+
PS> $Env:DUECREDIT_ENABLE = "yes" # PowerShell
90+
91+
Or, from within an Jupyter Notebook, environment variables can be set before
92+
import using::
93+
94+
import os
95+
os.environ['DUECREDIT_ENABLE'] = 'yes'
96+
import qinfer as qi
97+
98+
Whenever it is detected that this variable is true, any uses of **Qinfer** in a
99+
given folder (even multiple distinct runs) will maintain
100+
a file in the same folder called ``.duecredit.p`` that contains
101+
a representation of your bibliography. This file is updated whenever **Qinfer**
102+
uses a module, class, or method that is appropriately tagged with a citation.
103+
104+
If you wish to see the citation compilaton of a *single* python session,
105+
you can dump the current state with::
106+
107+
qi.due.dump()
108+
109+
On the other hand, to print it out the entire ``.duecredit.p`` collection
110+
in BibTeX form, use the summary functionality of `duecredit`_::
111+
112+
$ duecredit summary --format=bibtex
113+
114+
Note that this summary will also include projects such as NumPy and SciKit-Learn
115+
that are supported by `duecredit`_, as well as any other projects which natively
116+
host citation metadata through `duecredit`_. For example::
117+
118+
$ export DUECREDIT_ENABLE=yes
119+
$ ipython
120+
In [1]: import qinfer as qi
121+
In [2]: exit
122+
123+
DueCredit Report:
124+
- Scientific tools library / numpy (v 1.11.1) [1]
125+
- Bayesian inference for quantum information / qinfer (v 1.0) [2]
126+
- Machine Learning library / sklearn (v 0.17.1) [3]
127+
- Affinity propagation clustering algorithm / sklearn.cluster.affinity_propagation_ (v 0.17.1) [4]
128+
129+
3 packages cited
130+
1 module cited
131+
0 functions cited
132+
133+
References
134+
----------
135+
136+
[1] Van Der Walt, S., Colbert, S.C. & Varoquaux, G., 2011. The NumPy array: a structure for efficient numerical computation. Computing in Science & Engineering, 13(2), pp.22–30.
137+
[2] Granade, C. et al., 2016. QInfer: Statistical Inference Software for Quantum Applications. arXiv:1610.00336 [physics, physics:quant-ph, stat].
138+
[3] Pedregosa, F. et al., 2011. Scikit-learn: Machine learning in Python. The Journal of Machine Learning Research, 12, pp.2825–2830.
139+
[4] Frey, B.J. & Dueck, D., 2007. Clustering by Passing Messages Between Data Points. Science, 315(5814), pp.972–976.
140+
141+
The bibliography entries defined by QInfer are organized according to different
142+
*tags*, making it easier to filter through the results of `duecredit`_. In particular,
143+
QInfer uses the following citation tags, as defined in the `duecredit documentation
144+
<https://github.com/duecredit/duecredit/blob/master/README.md>`_:
145+
146+
- ``implementation``: The tagged function is an implementation of the cited work.
147+
- ``experiment``: Concerns experimental demonstrations of an algorithm or procedure. This tag
148+
is similar to, but distinct from, the ``use`` tag defined by `duecredit`_.
149+
150+
These tags can be controlled using the ``DUECREDIT_REPORT_ALL`` and ``DUECREDIT_REPORT_TAGS``
151+
environment variables. By default, all tags by ``implementation`` are hidden, such that
152+
summaries of the collected bibliography describe which software implementations are used
153+
in the course of a project.
154+
155+
For more details on how to use `duecredit`_, please see their `documentation on
156+
GitHub <https://github.com/duecredit/duecredit/blob/master/README.md>`_.
157+
158+
159+
.. _duecredit: https://github.com/duecredit/duecredit/

doc/source/guide/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,5 @@ User's Guide
2424
perf_testing
2525
parallel
2626
interop
27+
citing
2728

doc/source/intro.rst

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -63,32 +63,7 @@ entry::
6363
url = {http://dx.doi.org/10.5281/zenodo.157007}
6464
}
6565

66-
If you wish to cite **QInfer** functionality that has not yet appeared in a
67-
released version, it may be helpful
68-
to cite a given SHA hash as listed on
69-
`GitHub <https://github.com/QInfer/python-qinfer/commits/master>`_ (the
70-
hashes of each commit are listed on the right hand side of the page).
71-
A recommended BibTeX entry for citing a particular commit is::
72-
73-
@misc{qinfer-1_0b4,
74-
author = {Christopher Granade and
75-
Christopher Ferrie and
76-
Steven Casagrande and
77-
Ian Hincks and
78-
Michal Kononenko and
79-
Thomas Alexander and
80-
Yuval Sanders},
81-
title = {{QInfer}: Library for Statistical Inference in Quantum Information},
82-
month = may,
83-
year = 2016,
84-
url = "https://github.com/QInfer/python-qinfer/commit/bc3736c",
85-
note = {Version \texttt{bc3736c}.}
86-
}
87-
88-
89-
In this example, ``bc3736c`` should be replaced by the
90-
particular commit being cited, and the date should be replaced by the date
91-
of that commit.
66+
For more details, please see :ref:`citing_guide`.
9267

9368
Getting Started
9469
===============

src/qinfer/__init__.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,28 @@
2626
from __future__ import absolute_import
2727
from qinfer.version import version as __version__
2828

29+
## CITATION METADATA ##########################################################
30+
31+
from ._due import due, Doi, BibTeX
32+
33+
due.cite(
34+
BibTeX("""
35+
@article{qinfer,
36+
title = {{QInfer}: {Statistical} Inference Software for Quantum Applications},
37+
eprinttype = {arxiv},
38+
eprint = {1610.00336},
39+
journal = {arXiv:1610.00336 [physics, physics:quant-ph, stat]},
40+
author = {Granade, Christopher and Ferrie, Christopher and Hincks, Ian and Casagrande, Steven and Alexander, Thomas and Gross, Jonathan and Kononenko, Michal and Sanders, Yuval},
41+
month = oct,
42+
year = {2016}
43+
}
44+
"""),
45+
description="Bayesian inference for quantum information",
46+
tags=["implementation"],
47+
cite_module=True,
48+
path="qinfer"
49+
)
50+
2951
## IMPORTS ####################################################################
3052
# These imports control what is made available by importing qinfer itself.
3153

src/qinfer/_due.py

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
# emacs: at the end of the file
2+
# ex: set sts=4 ts=4 sw=4 et:
3+
# pylint: skip-file
4+
# ## ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### #
5+
"""
6+
7+
Stub file for a guaranteed safe import of duecredit constructs: if duecredit
8+
is not available.
9+
10+
To use it, place it into your project codebase to be imported, e.g. copy as
11+
12+
cp stub.py /path/tomodule/module/due.py
13+
14+
Note that it might be better to avoid naming it duecredit.py to avoid shadowing
15+
installed duecredit.
16+
17+
Then use in your code as
18+
19+
from .due import due, Doi, BibTeX
20+
21+
See https://github.com/duecredit/duecredit/blob/master/README.md for examples.
22+
23+
Origin: Originally a part of the duecredit
24+
Copyright: 2015-2016 DueCredit developers
25+
License: BSD-2
26+
"""
27+
28+
__version__ = '0.0.5'
29+
30+
31+
class InactiveDueCreditCollector(object):
32+
"""Just a stub at the Collector which would not do anything"""
33+
def _donothing(self, *args, **kwargs):
34+
"""Perform no good and no bad"""
35+
pass
36+
37+
def dcite(self, *args, **kwargs):
38+
"""If I could cite I would"""
39+
def nondecorating_decorator(func):
40+
return func
41+
return nondecorating_decorator
42+
43+
cite = load = add = _donothing
44+
45+
def __repr__(self):
46+
return self.__class__.__name__ + '()'
47+
48+
49+
def _donothing_func(*args, **kwargs):
50+
"""Perform no good and no bad"""
51+
pass
52+
53+
54+
try:
55+
from duecredit import due, BibTeX, Doi, Url
56+
if 'due' in locals() and not hasattr(due, 'cite'):
57+
raise RuntimeError(
58+
"Imported due lacks .cite. DueCredit is now disabled")
59+
except Exception as e:
60+
if type(e).__name__ != 'ImportError':
61+
import logging
62+
logging.getLogger("duecredit").error(
63+
"Failed to import duecredit due to %s" % str(e))
64+
# Initiate due stub
65+
due = InactiveDueCreditCollector()
66+
BibTeX = Doi = Url = _donothing_func
67+
68+
# Emacs mode definitions
69+
# Local Variables:
70+
# mode: python
71+
# py-indent-offset: 4
72+
# tab-width: 4
73+
# indent-tabs-mode: nil
74+
# End:

src/qinfer/ale.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
from qinfer.derived_models import DerivedModel
5050
from qinfer.abstract_model import Model, Simulatable, FiniteOutcomeModel
5151
from qinfer._exceptions import ApproximationWarning
52+
from qinfer._due import due, Doi
5253

5354
## CLASSES ####################################################################
5455

@@ -73,6 +74,11 @@ class ALEApproximateModel(DerivedModel):
7374
cause the algorithm to require more samples.
7475
"""
7576

77+
@due.dcite(
78+
Doi("10.1103/PhysRevLett.112.130402"),
79+
description="Adaptive likelihood estimation",
80+
tags=["implementation"]
81+
)
7682
def __init__(self, simulator,
7783
error_tol=1e-2, min_samp=10, samp_step=10,
7884
est_hedge=0.509, adapt_hedge=0.509

0 commit comments

Comments
 (0)