Skip to content

Commit

Permalink
Merge pull request #55 from XanaduAI/v0.6_update
Browse files Browse the repository at this point in the history
Version bump
  • Loading branch information
josh146 authored Oct 18, 2019
2 parents 7a68739 + 16e2045 commit a0e59df
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 17 deletions.
17 changes: 17 additions & 0 deletions .github/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
# Version 0.6.0

### Bug fixes

* The way measurement statistics works has changed in the latest version of PennyLane. Now, rather
than `shots=0` referring to 'analytic' mode, there is a separate analytic argument.
Further, the num_shots argument has been removed from Device.samples().
([#53](https://github.com/XanaduAI/pennylane-pq/pull/53))

### Contributors

This release contains contributions from (in alphabetical order):

Josh Izaac

---

# Version 0.4.1

### Bug fixes
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.5.0-dev'
__version__ = '0.6.0'
36 changes: 22 additions & 14 deletions pennylane_pq/devices.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,13 @@ class _ProjectQDevice(Device): #pylint: disable=abstract-method
Args:
wires (int): The number of qubits of the device. Default 1 if not specified.
shots (int): number of circuit evaluations/random samples used to estimate
expectation values of observables. For simulator devices, a value of 0 (default)
results in the exact expectation value being returned. For the IBMBackend the
default is 1024.
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
Keyword Args:
backend (string): Name of the backend, i.e., either "Simulator",
Expand All @@ -124,7 +127,7 @@ class _ProjectQDevice(Device): #pylint: disable=abstract-method
name = 'ProjectQ PennyLane plugin'
short_name = 'projectq'
pennylane_requires = '>=0.4.0'
version = '0.4.0'
version = '0.4.2'
plugin_version = __version__
author = 'Christian Gogolin'
_capabilities = {'backend': list(["Simulator", "ClassicalSimulator", "IBMBackend"])}
Expand All @@ -141,7 +144,7 @@ def _observable_map(self):
def _backend_kwargs(self):
raise NotImplementedError

def __init__(self, wires=1, shots=0, *, backend, **kwargs):
def __init__(self, wires=1, shots=1024, analytic=True, *, backend, **kwargs):
# overwrite shots with num_runs if given
if 'num_runs' in kwargs:
shots = kwargs['num_runs']
Expand All @@ -152,6 +155,7 @@ def __init__(self, wires=1, shots=0, *, 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 @@ -242,9 +246,13 @@ class ProjectQSimulator(_ProjectQDevice):
Args:
wires (int): The number of qubits of the device. Default 1 if not specified.
shots (int): number of random samples used to estimate expectation values of
observables. A value of 0 (default) results in the exact expectation value
being returned.
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
Keyword Args:
gate_fusion (bool): If True, operations are cached and only executed once a
Expand Down Expand Up @@ -298,9 +306,9 @@ class ProjectQSimulator(_ProjectQDevice):
_circuits = {}
_backend_kwargs = ['gate_fusion', 'rnd_seed']

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

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

if self.shots != 0 and observable != 'Identity':
if not self.analytic and observable != 'Identity':
p0 = (expval+1)/2
p0 = max(min(p0, 1), 0)
n0 = np.random.binomial(self.shots, p0)
Expand Down Expand Up @@ -448,7 +456,7 @@ def __init__(self, wires=1, shots=1024, **kwargs):
import projectq.setups.ibm #pylint: disable=unused-variable

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

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

def __init__(self, wires=1, **kwargs):
kwargs['backend'] = 'ClassicalSimulator'
super().__init__(wires=wires, shots=0, **kwargs)
super().__init__(wires=wires, shots=1024, analytic=True, **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,2 +1,2 @@
projectq
pennylane>=0.4
pennylane>=0.6
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
version = f.readlines()[-1].split()[-1].strip("\"'") # pylint: disable=invalid-name


requirements = ["projectq>=0.4.1", "pennylane>=0.4"] # pylint: disable=invalid-name
requirements = ["projectq>=0.4.1", "pennylane>=0.6"] # pylint: disable=invalid-name


info = { # pylint: disable=invalid-name
Expand Down

0 comments on commit a0e59df

Please sign in to comment.