Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updates and small fixes #43

Merged
merged 2 commits into from
Jul 31, 2019
Merged
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
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ before_install:
- sudo apt-get -y install cmake
- sudo apt-get -y install libopenblas-dev
- pip install pip --upgrade
- pip install -e git+https://github.com/XanaduAI/pennylane.git#egg=pennylane
- pip install --upgrade -r requirements.txt
- pip install --upgrade pytest pytest-cov wheel codecov
install:
Expand Down
6 changes: 3 additions & 3 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ parameters would look like:
qml.RY(y, wires=[0])
qml.RX(x, wires=[0])
qml.CNOT(wires=[0, 1])
return qml.expval.PauliZ(wires=1)
return qml.expval(qml.PauliZ(wires=1))

You can then execute the circuit like any other function to get the quantum mechanical expectation value.

Expand Down Expand Up @@ -214,8 +214,8 @@ Carsten Blank, Sebastian Boerakker, Christian Gogolin, Josh Izaac
Support
=======

- **Source Code:** https://github.com/carstenblank/pennylane-qiskit
- **Issue Tracker:** https://github.com/carstenblank/pennylane-qiskit/issues
- **Source Code:** https://github.com/XanaduAI/pennylane-qiskit
- **Issue Tracker:** https://github.com/XanaduAI/pennylane-qiskit/issues

If you are having issues, please let us know by posting the issue on our Github issue tracker.

Expand Down
4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
qiskit>=0.10.1,<0.11.0
PennyLane
qiskit>=0.11.1
PennyLane>=0.4
numpy
13 changes: 8 additions & 5 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,18 @@
with open("README.rst", "r") as fh:
long_description = fh.read()

with open("requirements.txt") as f:
requirements = f.readlines()
requirements = [
"qiskit>=0.11.1",
"pennylane>=0.4",
"numpy"
]

info = {
'name': 'PennyLane-qiskit',
'version': version,
'maintainer': 'Carsten Blank',
'maintainer_email': 'blank@data-cybernetics.com',
'url': 'http://data-cybernetics.com',
'maintainer': 'Xanadu',
'maintainer_email': 'software@xanadu.ai',
'url': 'http://pennylane.ai',
'license': 'Apache License 2.0',
'packages': [
'pennylane_qiskit'
Expand Down
12 changes: 6 additions & 6 deletions tests/test_backend_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def test_basicaer_initial_unitary(self):

@qml.qnode(dev)
def circuit():
return qml.expval.PauliZ(wires=[0]), qml.expval.PauliZ(wires=[1])
return qml.expval(qml.PauliZ(wires=[0])), qml.expval(qml.PauliZ(wires=[1]))

measurement = circuit()

Expand All @@ -104,7 +104,7 @@ def circuit():
# An angle of 1e-1 would fail!
angle = 1e-2
qml.RY(angle, wires=[0])
return qml.expval.PauliZ(wires=[0]), qml.expval.PauliZ(wires=[1])
return qml.expval(qml.PauliZ(wires=[0])), qml.expval(qml.PauliZ(wires=[1]))

measurement = circuit()

Expand All @@ -124,7 +124,7 @@ def assertOptions(dev, backend_options):

@qml.qnode(dev)
def circuit():
return qml.expval.PauliZ(wires=[0]), qml.expval.PauliZ(wires=[1])
return qml.expval(qml.PauliZ(wires=[0])), qml.expval(qml.PauliZ(wires=[1]))

circuit()

Expand All @@ -136,7 +136,7 @@ def circuit():
if isinstance(value, (list, np.ndarray)):
self.assertAllEqual(value, other_value)
else:
self.assertEquals(value, other_value)
self.assertEqual(value, other_value)

all_backend_options = {
'initial_unitary': np.array([
Expand Down Expand Up @@ -171,7 +171,7 @@ def assertOptions(dev, backend_options):

@qml.qnode(dev)
def circuit():
return qml.expval.PauliZ(wires=[0]), qml.expval.PauliZ(wires=[1])
return qml.expval(qml.PauliZ(wires=[0])), qml.expval(qml.PauliZ(wires=[1]))

circuit()

Expand All @@ -185,7 +185,7 @@ def circuit():
if isinstance(value, (list, np.ndarray)):
self.assertAllEqual(value, other_value)
else:
self.assertEquals(value, other_value)
self.assertEqual(value, other_value)

all_backend_options = {
'initial_unitary': np.array([
Expand Down
6 changes: 3 additions & 3 deletions tests/test_basis_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def test_basis_state(self):
@qml.qnode(device)
def circuit():
qml.BasisState(bits_to_flip, wires=list(range(self.num_subsystems)))
return qml.expval.PauliZ(0), qml.expval.PauliZ(1), qml.expval.PauliZ(2), qml.expval.PauliZ(3)
return qml.expval(qml.PauliZ(0)), qml.expval(qml.PauliZ(1)), qml.expval(qml.PauliZ(2)), qml.expval(qml.PauliZ(3))

log.info("BasisState on device %s with bitflip pattern %s.", device.name, bits_to_flip)

Expand All @@ -86,7 +86,7 @@ def test_basis_state_on_subsystem(self):
@qml.qnode(device)
def circuit():
qml.BasisState(bits_to_flip, wires=list(range(self.num_subsystems - 1)))
return qml.expval.PauliZ(0), qml.expval.PauliZ(1), qml.expval.PauliZ(2), qml.expval.PauliZ(3)
return qml.expval(qml.PauliZ(0)), qml.expval(qml.PauliZ(1)), qml.expval(qml.PauliZ(2)), qml.expval(qml.PauliZ(3))

log.info("BasisState on device %s with bitflip pattern %s (sub-system).", device.name, bits_to_flip)

Expand All @@ -103,7 +103,7 @@ def test_disallow_basis_state_after_other_operation(self):
def circuit():
qml.PauliX(wires=[0])
qml.BasisState(np.array([0, 1, 0, 1]), wires=list(range(self.num_subsystems)))
return qml.expval.PauliZ(0)
return qml.expval(qml.PauliZ(0))

self.assertRaises(pennylane._device.DeviceError, circuit)

Expand Down
7 changes: 4 additions & 3 deletions tests/test_compare_with_default_qubit.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,9 @@ def circuit():
operation_class = getattr(qml, operation)
else:
operation_class = getattr(pennylane_qiskit, operation)
if hasattr(qml.expval, observable):
observable_class = getattr(qml.expval, observable)

if hasattr(qml.ops, observable):
observable_class = getattr(qml.ops, observable)
else:
observable_class = getattr(pennylane_qiskit.expval, observable)

Expand Down Expand Up @@ -141,7 +142,7 @@ def circuit():

# Apply operator and observable
operation_class(*operation_pars, wires=operation_wires)
return observable_class(*observable_pars, observable_wires)
return qml.expval(observable_class(*observable_pars, observable_wires))

output = circuit()
if (operation, observable) not in outputs:
Expand Down
8 changes: 4 additions & 4 deletions tests/test_device_initialization.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,11 @@ def test_noise_model_for_aer():

dev = qml.device("qiskit.aer", wires=num_subsystems, noise_model=noise_model)
assert dev._noise_model is not None
assert noise_model.as_dict() == dev._noise_model.as_dict()
assert noise_model.to_dict() == dev._noise_model.to_dict()

dev2 = AerQiskitDevice(wires=num_subsystems, noise_model=noise_model)
assert dev2._noise_model is not None
assert noise_model.as_dict() == dev2._noise_model.as_dict()
assert noise_model.to_dict() == dev2._noise_model.to_dict()

except DeviceError:
raise Exception(
Expand All @@ -99,11 +99,11 @@ def test_noise_model_for_basic_aer():
"qiskit.basicaer", wires=num_subsystems, noise_model=noise_model
)
assert dev._noise_model is not None
assert noise_model.as_dict() == dev._noise_model.as_dict()
assert noise_model.to_dict() == dev._noise_model.to_dict()

dev2 = BasicAerQiskitDevice(wires=num_subsystems, noise_model=noise_model)
assert dev2._noise_model is not None
assert noise_model.as_dict() == dev2._noise_model.as_dict()
assert noise_model.to_dict() == dev2._noise_model.to_dict()

except DeviceError:
raise Exception(
Expand Down
10 changes: 5 additions & 5 deletions tests/test_simple_circuits.py
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ def circuit():
for i, p in enumerate(bits_to_flip):
if p == 1:
qml.PauliX(wires=[i])
return qml.expval.PauliZ(0), qml.expval.PauliZ(1), qml.expval.PauliZ(2), qml.expval.PauliZ(3)
return qml.expval(qml.PauliZ(0)), qml.expval(qml.PauliZ(1)), qml.expval(qml.PauliZ(2)), qml.expval(qml.PauliZ(3))

self.assertAllAlmostEqual([1] * self.num_subsystems - 2 * bits_to_flip, np.array(circuit()),
delta=self.tol)
Expand All @@ -330,7 +330,7 @@ def circuit(x, y, z):
qml.RY(y, wires=[0])
qml.RX(x, wires=[0])
qml.CNOT(wires=[0, 1])
return qml.expval.PauliZ(wires=1)
return qml.expval(qml.PauliZ(wires=1))

self.assertAllAlmostEqual(0.96875, circuit(0.2, 0.1, 0.3), delta=self.tol)

Expand All @@ -348,7 +348,7 @@ def test_arbitrary_state(self):
@qml.qnode(device)
def circuit():
qml.QubitStateVector(state, wires=[0, 1, 2, 3])
return qml.expval.PauliZ(0), qml.expval.PauliZ(1), qml.expval.PauliZ(2), qml.expval.PauliZ(3)
return qml.expval(qml.PauliZ(0)), qml.expval(qml.PauliZ(1)), qml.expval(qml.PauliZ(2)), qml.expval(qml.PauliZ(3))

result = np.array(circuit())
expected = np.array(list(map(lambda c: 1.0 if c == '0' else -1.0, "{:b}".format(index).zfill(self.num_subsystems))))
Expand All @@ -373,7 +373,7 @@ def test_arbitrary_unitary(self):
@qml.qnode(device)
def circuit():
qml.QubitUnitary(i, wires=[0])
return qml.expval.PauliZ(0)
return qml.expval(qml.PauliZ(0))

circuit()
# TODO 2018-12-23 Carsten Blank: create meaningful tests
Expand All @@ -395,7 +395,7 @@ def circuit():
for i, p in enumerate(bits_to_flip):
if p == 1:
qml.PauliX(wires=[i])
return qml.expval.PauliZ(0), qml.expval.PauliZ(1), qml.expval.PauliZ(2), qml.expval.PauliZ(3)
return qml.expval(qml.PauliZ(0)), qml.expval(qml.PauliZ(1)), qml.expval(qml.PauliZ(2)), qml.expval(qml.PauliZ(3))
# The assert is almost useless. Depending on the current noise model, the expectation values might be
# very different than what we expect. I guess it would be pretty much the best practice to assume
# that it is at least more likely to measure a 1 than a 0, hence we need to make sure that the
Expand Down
4 changes: 2 additions & 2 deletions tests/test_unsupported_operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def test_unsupported_operation(self):
@qml.qnode(device)
def circuit():
qml.Beamsplitter(0.2, 0.1, wires=[0, 1]) # this expectation will never be supported
return qml.expval.Homodyne(0.7, 0)
return qml.expval(qml.QuadOperator(0.7, 0))

self.assertRaises(pennylane._device.DeviceError, circuit)

Expand All @@ -74,7 +74,7 @@ def test_unsupported_expectation(self):
for device in self.devices:
@qml.qnode(device)
def circuit():
return qml.expval.Homodyne(0.7, 0) # this expectation will never be supported
return qml.expval(qml.QuadOperator(0.7, 0)) # this expectation will never be supported

self.assertRaises(pennylane._device.DeviceError, circuit)

Expand Down