Skip to content

Commit

Permalink
Remove analytic keyword argument and v0.15 version bump (#69)
Browse files Browse the repository at this point in the history
* Remove analytic keyword argument and v0.15 version bump

* fix

* fix

* fix

* fix

* Update setup.py

* fix

* fix

* fix

* fix

* fix

* fix

* update header
  • Loading branch information
josh146 authored Apr 15, 2021
1 parent 35b8d5b commit 8a44381
Show file tree
Hide file tree
Showing 10 changed files with 44 additions and 49 deletions.
14 changes: 7 additions & 7 deletions .github/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
# Release 0.15.0-dev
# Release 0.15.0

### New features since last release

### Breaking changes

### Improvements

### Documentation

### Bug fixes
* For compatibility with PennyLane v0.15, the `analytic` keyword argument
has been removed from all devices. Analytic expectation values can
still be computed by setting `shots=None`.
[(#69)](https://github.com/XanaduAI/pennylane-pq/pull/69)

### Contributors

This release contains contributions from (in alphabetical order):

Josh Izaac

---

# Release 0.11.0
Expand Down
10 changes: 6 additions & 4 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ jobs:
uses: styfle/cancel-workflow-action@0.4.1
with:
access_token: ${{ github.token }}
- uses: actions/checkout@v1
- uses: actions/checkout@v2
with:
fetch-depth: 2
- name: Set up Python
uses: actions/setup-python@v2
with:
Expand All @@ -33,8 +35,8 @@ jobs:
- name: Run tests
env:
IBMQX_TOKEN: ${{ secrets.IBMQX_TOKEN }}
run: python -m pytest tests --cov=pennylane_pq --cov-report=term-missing -p no:warnings --tb=native
run: python -m pytest tests --cov=pennylane_pq --cov-report=term-missing --cov-report=xml -p no:warnings --tb=native
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v1.0.7
uses: codecov/codecov-action@v1.0.12
with:
file: ./.coverage
file: ./coverage.xml
5 changes: 4 additions & 1 deletion doc/xanadu_theme/header.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,13 @@
</li>
<li class="nav-item active">
<a class="nav-link" href="https://pennylane.ai/plugins.html">Plugins</a>
<span class="sr-only">(current)</span>
</li>
<li class="nav-item">
<a class="nav-link" href="https://pennylane.readthedocs.io">Documentation</a>
<span class="sr-only">(current)</span>
</li>
<li class="nav-item">
<a class="nav-link" href="https://pennylane.ai/blog">Blog</a>
</li>
<li class="nav-item">
<a class="nav-link" href="https://qhack.ai"><img src="https://pennylane.ai/img/qhack_plain_black.png"></a>
Expand Down
1 change: 1 addition & 0 deletions doc/xanadu_theme/layout.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
{# Do this so that bootstrap is included before the main css file #}
{%- block htmltitle %}
<link href="https://fonts.googleapis.com/css?family=Noto+Serif" rel="stylesheet">
<link href="https://fonts.googleapis.com/css?family=Noto+Sans" rel="stylesheet">
<link href="https://fonts.googleapis.com/css?family=Roboto&display=swap" rel="stylesheet">

<!-- Font Awesome -->
Expand Down
15 changes: 3 additions & 12 deletions doc/xanadu_theme/static/xanadu.css_t
Original file line number Diff line number Diff line change
@@ -1,14 +1,5 @@
/* Sphinx themes
-------------------------------------------------- */
@font-face {
font-family: 'Product Sans';
font-style: normal;
font-weight: 400;
src: local('Open Sans'), local('OpenSans'), url(https://fonts.gstatic.com/s/productsans/v5/HYvgU2fE2nRJvZ5JFAumwegdm0LZdjqr5-oayXSOefg.woff2) format('woff2');
}



body {
/*background-color: #edf0f2;*/
margin: 0;
Expand Down Expand Up @@ -92,7 +83,7 @@ h1, h2, h3, h4, h5, h6 {
color: black;
font-weight: normal;
padding: 0;
font-family: 'Product Sans', 'Roboto', sans-serif!important;
font-family: 'Noto Sans', 'Roboto', sans-serif!important;
}

h1, h2, h3 {
Expand Down Expand Up @@ -371,7 +362,7 @@ div.sphinxsidebar p {
margin: 20px 0px 10px 21px;
font-weight: normal;
padding: 0;
font-family: 'Product Sans', 'Roboto', sans-serif!important;
font-family: 'Noto Sans', 'Roboto', sans-serif!important;
font-size: 24px;
color: #515151;
/*text-align: center;*/
Expand Down Expand Up @@ -2012,7 +2003,7 @@ footer.page-footer .footer-copyright {
margin-left: 20px;
font-size: initial;
color: black;
font-family: 'Product Sans', 'Roboto', sans-serif !important;
font-family: 'Noto Sans', 'Roboto', sans-serif !important;
margin-bottom: -9px;
border-bottom: 3px solid;
border-bottom-color: white;
Expand Down
2 changes: 1 addition & 1 deletion pennylane_pq/_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@
Version number (major.minor.patch[-label])
"""

__version__ = "0.15.0-dev"
__version__ = "0.15.0"
33 changes: 12 additions & 21 deletions pennylane_pq/devices.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,13 +111,9 @@ class _ProjectQDevice(Device): # pylint: disable=abstract-method
wires (int or Iterable[Number, str]]): Number of subsystems represented by the device,
or iterable that contains unique labels for the subsystems as numbers (i.e., ``[-1, 0, 2]``)
or strings (``['ancilla', 'q1', 'q2']``). Default 1 if not specified.
shots (int): How many times the circuit should be evaluated (or sampled) to estimate
the expectation values. Defaults to 1024 if not specified.
If ``analytic == True``, then the number of shots is ignored
in the calculation of expectation values and variances, and only controls the number
of samples returned by ``sample``.
analytic (bool): indicates if the device should calculate expectations
and variances analytically
shots (None, int): How many times the circuit should be evaluated (or sampled) to estimate
the expectation values. Defaults to ``None`` if not specified, which means that the device
returns analytical results.
Keyword Args:
backend (string): Name of the backend, i.e., either "Simulator",
Expand Down Expand Up @@ -165,7 +161,7 @@ def _observable_map(self):
def _backend_kwargs(self):
raise NotImplementedError

def __init__(self, wires=1, shots=1024, analytic=True, *, backend, **kwargs):
def __init__(self, wires=1, shots=None, *, backend, **kwargs):
# overwrite shots with num_runs if given
if "num_runs" in kwargs:
shots = kwargs["num_runs"]
Expand All @@ -176,7 +172,6 @@ def __init__(self, wires=1, shots=1024, analytic=True, *, backend, **kwargs):
if "verbose" not in kwargs:
kwargs["verbose"] = False

self.analytic = analytic
self._backend = backend
self._kwargs = kwargs
self._eng = None
Expand Down Expand Up @@ -276,13 +271,9 @@ class ProjectQSimulator(_ProjectQDevice):
wires (int or Iterable[Number, str]]): Number of subsystems represented by the device,
or iterable that contains unique labels for the subsystems as numbers (i.e., ``[-1, 0, 2]``)
or strings (``['ancilla', 'q1', 'q2']``).
shots (int): How many times the circuit should be evaluated (or sampled) to estimate
the expectation values. Defaults to 1000 if not specified.
If ``analytic == True``, then the number of shots is ignored
in the calculation of expectation values and variances, and only controls the number
of samples returned by ``sample``.
analytic (bool): indicates if the device should calculate expectations
and variances analytically
shots (None, int): How many times the circuit should be evaluated (or sampled) to estimate
the expectation values. Defaults to ``None`` if not specified, which means that the device
returns analytical results.
Keyword Args:
gate_fusion (bool): If True, operations are cached and only executed once a
Expand Down Expand Up @@ -337,9 +328,9 @@ class ProjectQSimulator(_ProjectQDevice):
_circuits = {}
_backend_kwargs = ["gate_fusion", "rnd_seed"]

def __init__(self, wires=1, shots=1024, analytic=True, **kwargs):
def __init__(self, wires=1, shots=None, **kwargs):
kwargs["backend"] = "Simulator"
super().__init__(wires=wires, shots=shots, analytic=analytic, **kwargs)
super().__init__(wires=wires, shots=shots, **kwargs)

def reset(self):
"""Reset/initialize the device by initializing the backend and engine, and allocating qubits."""
Expand Down Expand Up @@ -372,7 +363,7 @@ def expval(self, observable, wires, par):
# pq.ops.QubitOperator("Z"+'0'), [qubit])
# for qubit in self._reg]

if not self.analytic and observable != "Identity":
if not self.shots is None and observable != "Identity":
p0 = (expval + 1) / 2
p0 = max(min(p0, 1), 0)
n0 = np.random.binomial(self.shots, p0)
Expand Down Expand Up @@ -516,7 +507,7 @@ def __init__(self, wires=1, shots=1024, **kwargs):
) # pylint: disable=line-too-long

kwargs["backend"] = "IBMBackend"
super().__init__(wires=wires, shots=shots, analytic=False, **kwargs)
super().__init__(wires=wires, shots=shots, **kwargs)

def reset(self):
"""Reset/initialize the device by initializing the backend and engine, and allocating qubits."""
Expand Down Expand Up @@ -658,7 +649,7 @@ class ProjectQClassicalSimulator(_ProjectQDevice):

def __init__(self, wires=1, **kwargs):
kwargs["backend"] = "ClassicalSimulator"
super().__init__(wires=wires, shots=1024, analytic=True, **kwargs)
super().__init__(wires=wires, shots=None, **kwargs)

def reset(self):
"""Reset/initialize the device by initializing the backend and engine, and allocating qubits."""
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
projectq>=0.5.1
pennylane>=0.11
git+https://github.com/PennyLaneAI/pennylane.git
pybind11
5 changes: 4 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@
version = f.readlines()[-1].split()[-1].strip("\"'") # pylint: disable=invalid-name


requirements = ["projectq>=0.5.1", "pennylane>=0.11"] # pylint: disable=invalid-name
requirements = [
"projectq>=0.5.1",
"pennylane @ git+https://github.com/PennyLaneAI/pennylane.git@master"
] # pylint: disable=invalid-name


info = { # pylint: disable=invalid-name
Expand Down
6 changes: 5 additions & 1 deletion tests/test_compare_with_default_qubit.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,11 @@ def circuit():
operation_class(*operation_pars, wires=operation_wires)
return qml.expval(observable_class(*observable_pars, wires=observable_wires))

output = circuit()
try:
output = circuit()
except IgnoreOperationException:
continue

if (operation, observable) not in outputs:
outputs[(operation, observable)] = {}

Expand Down

0 comments on commit 8a44381

Please sign in to comment.