Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
160 commits
Select commit Hold shift + click to select a range
c6b655b
Added default qutrit class
mudit2812 May 12, 2022
0d4be90
Merge branch 'PennyLaneAI:master' into qutrit
mudit2812 May 12, 2022
9417e00
Added operations files for qutrits
mudit2812 May 17, 2022
b623b1b
Add non-parametric ops. Work on parametric ops
mudit2812 May 18, 2022
54e8a95
Added matrix ops file for qutrits
mudit2812 May 27, 2022
abebdcb
Added qutrit unitary
mudit2812 May 27, 2022
8811079
Added methods to qutrit device
mudit2812 May 27, 2022
c823501
Added TODO's
mudit2812 May 27, 2022
ac9b7a8
Added measurement related methods to qutrit device
mudit2812 May 30, 2022
a949eae
Adding skeleton code to default.qutrit
mudit2812 May 30, 2022
83663f5
Testing qutrit device
mudit2812 May 31, 2022
a570531
Fixing bugs
mudit2812 Jun 1, 2022
f278e1b
Debugging
mudit2812 Jun 1, 2022
5832020
Added shift and clock
mudit2812 Jun 1, 2022
cb43b9d
Added TAdd(wires)
mudit2812 Jun 2, 2022
1886a52
Added SWAP operation
mudit2812 Jun 2, 2022
afbed5c
Fixing qutrit unitary bug
mudit2812 Jun 2, 2022
6b5ac36
Fixed _apply_unitary() bug in default qutrit
mudit2812 Jun 3, 2022
c61d737
Added custom implementations for clock and shift
mudit2812 Jun 3, 2022
4d41495
Merge branch 'master' of https://github.com/PennyLaneAI/pennylane int…
mudit2812 Jun 3, 2022
7d03d64
Added custom implementation for TSWAP
mudit2812 Jun 3, 2022
e42f132
Added custom implementation for TAdd
mudit2812 Jun 6, 2022
382deae
Minor changes
mudit2812 Jun 6, 2022
e1f0e8e
Minor changed to matrix_ops
mudit2812 Jun 8, 2022
e3c53df
Added test files
mudit2812 Jun 8, 2022
cdfa431
Passed all tests for qutrit unitary
mudit2812 Jun 8, 2022
0ec9418
Removed main
mudit2812 Jun 8, 2022
01c0ed7
Renamed qutrit matrix ops test file
mudit2812 Jun 9, 2022
f011612
Removing code/files for PR
mudit2812 Jun 9, 2022
e49e58b
Added tests for QutritDevice
mudit2812 Jun 9, 2022
7e9fddb
Added tests for QutritDevice
mudit2812 Jun 10, 2022
e722e34
Merge branch 'PennyLaneAI:master' into qutrit
mudit2812 Jun 13, 2022
dd8bc4f
Added tests and test config for default qutrit
mudit2812 Jun 13, 2022
0663498
Merge branch 'qutrit' of https://github.com/mudit2812/pennylane into …
mudit2812 Jun 13, 2022
a232728
Merge branch 'PennyLaneAI:master' into qutrit
mudit2812 Jun 13, 2022
b886d5c
updated changelog
mudit2812 Jun 13, 2022
dc99a9f
Merge branch 'qutrit' of https://github.com/mudit2812/pennylane into …
mudit2812 Jun 13, 2022
b451670
Added tests for wire and prob integration
mudit2812 Jun 13, 2022
5ec2541
Update doc/releases/changelog-dev.md
mudit2812 Jun 14, 2022
5134178
Update doc/releases/changelog-dev.md
mudit2812 Jun 14, 2022
6a43c44
Update doc/releases/changelog-dev.md
mudit2812 Jun 14, 2022
33bd8cd
Update doc/releases/changelog-dev.md
mudit2812 Jun 14, 2022
c69e21c
Update tests/test_qutrit_device.py
mudit2812 Jun 14, 2022
af9f5f2
Update pennylane/devices/default_qutrit.py
mudit2812 Jun 14, 2022
461f67a
Update pennylane/devices/default_qutrit.py
mudit2812 Jun 14, 2022
8d1c5a2
Update pennylane/devices/default_qutrit.py
mudit2812 Jun 14, 2022
3b3833d
Update pennylane/devices/default_qutrit.py
mudit2812 Jun 14, 2022
e457520
Update pennylane/ops/qutrit/matrix_ops.py
mudit2812 Jun 14, 2022
b371e63
Addressing PR comments
mudit2812 Jun 14, 2022
48e08b1
Merge branch 'qutrit' of https://github.com/mudit2812/pennylane into …
mudit2812 Jun 14, 2022
0642425
Added changes to address PR comments
mudit2812 Jun 14, 2022
db793bf
Fixed changelog-dev.md
mudit2812 Jun 14, 2022
553bc65
Update pennylane/devices/default_qutrit.py
mudit2812 Jun 14, 2022
46cfe52
Update pennylane/ops/qutrit/matrix_ops.py
mudit2812 Jun 14, 2022
1710227
Adding changes for PR
mudit2812 Jun 14, 2022
e345de9
Merge branch 'qutrit' of https://github.com/mudit2812/pennylane into …
mudit2812 Jun 14, 2022
00fd522
Reformatted new files, Updated comments
mudit2812 Jun 14, 2022
941c6b4
Fixed qutrit matrix ops test
mudit2812 Jun 14, 2022
9b07d54
Reformatted and refactored code
mudit2812 Jun 14, 2022
887b390
Made QutritDevice inherit QubitDevice
mudit2812 Jun 15, 2022
80d7fc3
Tested new version of qutrit device
mudit2812 Jun 15, 2022
2be996e
Removed default.qutrit to decrease PR size
mudit2812 Jun 15, 2022
2ce452a
Reformatting and refactoring
mudit2812 Jun 15, 2022
b7d25a6
Minor changes
mudit2812 Jun 15, 2022
a200f72
Merge branch 'master' into qutrit
glassnotes Jun 15, 2022
2ba7889
Removed references to default.qutrit
mudit2812 Jun 15, 2022
46ebcf1
Merge branch 'qutrit' of https://github.com/mudit2812/pennylane into …
mudit2812 Jun 15, 2022
a8d2efe
Fixed issues with testing suite for qutrit device
mudit2812 Jun 16, 2022
d9eb454
Merge branch 'master' into qutrit
mudit2812 Jun 16, 2022
bb8cbc8
Removed references to default qutrit
mudit2812 Jun 16, 2022
91b68e6
Minor change to comments
mudit2812 Jun 16, 2022
398d3c5
Added tests for better coverage
mudit2812 Jun 16, 2022
490533f
Added tests for more coverage
mudit2812 Jun 16, 2022
e0bbf2e
Updated doc/releases.changelog-dev.md
mudit2812 Jun 16, 2022
986ff17
Merge branch 'master' into qutrit
glassnotes Jun 17, 2022
eac29f4
Update doc/releases/changelog-dev.md
mudit2812 Jun 17, 2022
29c5735
Update pennylane/_qutrit_device.py
mudit2812 Jun 17, 2022
79de304
Update pennylane/_qutrit_device.py
mudit2812 Jun 17, 2022
0c8200d
Update pennylane/_qutrit_device.py
mudit2812 Jun 17, 2022
c6e27c1
Update pennylane/ops/qutrit/matrix_ops.py
mudit2812 Jun 17, 2022
beb3d20
Update tests/test_qutrit_device.py
mudit2812 Jun 17, 2022
0cfa603
Update tests/test_qutrit_device.py
mudit2812 Jun 17, 2022
05f80a7
Update tests/test_qutrit_device.py
mudit2812 Jun 17, 2022
62824eb
Update tests/test_qutrit_device.py
mudit2812 Jun 17, 2022
9580127
Added changes recommended on PR
mudit2812 Jun 17, 2022
17ee993
Merge branch 'qutrit' of https://github.com/mudit2812/pennylane into …
mudit2812 Jun 17, 2022
ddfce37
Remove QutritUnitary example from changelog-dev.md
mudit2812 Jun 17, 2022
71f8438
Update doc/releases/changelog-dev.md
mudit2812 Jun 17, 2022
343ff6f
Update doc/releases/changelog-dev.md
mudit2812 Jun 17, 2022
a92be39
Update doc/releases/changelog-dev.md
mudit2812 Jun 17, 2022
7eaf0f7
Merge branch 'master' into qutrit
mudit2812 Jun 20, 2022
280bf6f
Updated comments in test_qutrit_device
mudit2812 Jun 20, 2022
177ba1e
Merge branch 'master' into qutrit
mudit2812 Jun 21, 2022
a962b30
Merge branch 'master' into qutrit
mudit2812 Jun 21, 2022
a07a2a2
Removed QutritDevice
mudit2812 Jun 22, 2022
c94b1e5
Addressing conflicts
mudit2812 Jun 22, 2022
5c7929b
Updated changelog-dev.md
mudit2812 Jun 22, 2022
75e8835
Merge branch 'master' into qutrit
mudit2812 Jun 22, 2022
af12b26
Merge pull request #2 from PennyLaneAI/master
mudit2812 Jun 22, 2022
ef6e302
Merge branch 'master' into qutrit
mudit2812 Jun 22, 2022
1bba561
Merge branch 'master' into qutrit
mudit2812 Jun 22, 2022
881d79d
Made changes to address PR review
mudit2812 Jun 22, 2022
2fa3199
Update doc/releases/changelog-dev.md
mudit2812 Jun 22, 2022
9fbec3b
Added changes recommended in PR review
mudit2812 Jun 23, 2022
1bccb82
Reformatting
mudit2812 Jun 23, 2022
ace9008
Added changes to qutrit device and tests for PR
mudit2812 Jun 23, 2022
604abc2
Merge branch 'qutrit_unitary' of https://github.com/mudit2812/pennyla…
mudit2812 Jun 23, 2022
7b5ba5f
Merge branch 'qutrit' into qutrit_unitary
mudit2812 Jun 23, 2022
e9e4a45
Added QutritDevice for PR
mudit2812 Jun 23, 2022
55c35ef
Added methods to QutritDevice and tests for PR
mudit2812 Jun 23, 2022
cc85c3a
Added QutritDevice to __init__.py
mudit2812 Jun 23, 2022
3c1fedf
Merge branch 'master' into qutrit
antalszava Jun 23, 2022
3cfb812
Merge branch 'qutrit' of https://github.com/mudit2812/pennylane into …
mudit2812 Jun 23, 2022
20c51e6
Updated changelog to resolve conflicts
mudit2812 Jun 24, 2022
43dab5d
Merge branch 'master' of https://github.com/PennyLaneAI/pennylane int…
mudit2812 Jun 24, 2022
25b179b
Merge branch 'merge_qutritdevice' into qutrit_unitary
mudit2812 Jun 24, 2022
67a0d71
Merge branch 'qutrit_unitary' into qutrit_device1
mudit2812 Jun 24, 2022
3b4215b
Added imports
mudit2812 Jun 24, 2022
cbb3e6e
Updated dev changelog
mudit2812 Jun 24, 2022
d83a1d3
Merge branch 'qutrit_unitary' into qutrit_device1
mudit2812 Jun 24, 2022
be859d5
Updated changelog
mudit2812 Jun 24, 2022
caa6812
Merge branch 'master' into qutrit_unitary
mudit2812 Jun 24, 2022
87c3731
Merge branch 'qutrit_unitary' of https://github.com/mudit2812/pennyla…
mudit2812 Jun 24, 2022
9f1a5de
Merge branch 'master' into qutrit_unitary
mudit2812 Jun 24, 2022
5332fd8
Merge branch 'master' into qutrit_device1
mudit2812 Jun 24, 2022
fea2692
Merge branch 'master' into qutrit_unitary
glassnotes Jun 27, 2022
404a46c
Added comment with better description
mudit2812 Jun 28, 2022
06909f5
Added comments to address PR review
mudit2812 Jun 28, 2022
2e009a3
Update doc/releases/changelog-dev.md
mudit2812 Jun 28, 2022
aa434a0
Update pennylane/_qutrit_device.py
mudit2812 Jun 28, 2022
e2411d8
Update pennylane/_qutrit_device.py
mudit2812 Jun 28, 2022
9319eb8
Update pennylane/_qutrit_device.py
mudit2812 Jun 28, 2022
b78457b
Update tests/test_qutrit_device.py
mudit2812 Jun 28, 2022
50ce4a7
Update tests/test_qutrit_device.py
mudit2812 Jun 28, 2022
1fdc865
Merge branch 'qutrit_unitary' of https://github.com/mudit2812/pennyla…
mudit2812 Jun 28, 2022
49f2e8c
Update doc/releases/changelog-dev.md
mudit2812 Jul 12, 2022
8a4abc6
Updated marginal probs documentation
mudit2812 Jul 12, 2022
5c02565
Merge branch 'qutrit_unitary' of https://github.com/mudit2812/pennyla…
mudit2812 Jul 12, 2022
17b7242
Merge branch 'qutrit_unitary' into qutrit_device1
mudit2812 Jul 12, 2022
de6632e
Merge branch 'qutrit_device1' of https://github.com/mudit2812/pennyla…
mudit2812 Jul 12, 2022
5b3e9c7
Minor changes
mudit2812 Jul 12, 2022
8ebf393
Fixed tests to contain code in correct context
mudit2812 Jul 12, 2022
d9fe276
Removed artefacts from other branch
mudit2812 Jul 12, 2022
1bdd9cd
Merge branch 'master' of https://github.com/PennyLaneAI/pennylane int…
mudit2812 Jul 13, 2022
d8988df
Merge branch 'PennyLaneAI-master' into qutrit_device1
mudit2812 Jul 13, 2022
af4ac6d
Minor change to changelog
mudit2812 Jul 14, 2022
910e57d
Merge branch 'master' of https://github.com/PennyLaneAI/pennylane int…
mudit2812 Jul 14, 2022
9e5cb48
Merge branch 'qutrit_merge_1' into qutrit_device1
mudit2812 Jul 14, 2022
bdefd52
Merge branch 'master' into qutrit_device1
mudit2812 Jul 15, 2022
1de0b3c
Merge branch 'master' into qutrit_device1
mudit2812 Jul 18, 2022
98fba4b
Update tests/test_qutrit_device.py
mudit2812 Jul 18, 2022
e373297
Changes to address PR review
mudit2812 Jul 18, 2022
1c6ae82
Merge branch 'qutrit_unitary' into qutrit_device1
mudit2812 Jul 18, 2022
017a03a
Updating tests
mudit2812 Jul 18, 2022
195aa0e
Updated test_qutrit_device test_device_executions
mudit2812 Jul 18, 2022
882133e
Refactoring
mudit2812 Jul 19, 2022
36845d3
Fixed sampling with counts. Added tests
mudit2812 Jul 19, 2022
da3b305
Added test for coverage
mudit2812 Jul 19, 2022
736fea4
Update tests/test_qutrit_device.py
mudit2812 Jul 20, 2022
0b2997a
Reformatted test_qutrit_device.py
mudit2812 Jul 20, 2022
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
5 changes: 3 additions & 2 deletions doc/releases/changelog-dev.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,9 @@
[(#2709)](https://github.com/PennyLaneAI/pennylane/pull/2709)

* Added `QutritDevice` as an abstract base class for qutrit devices.
[(#2781)](https://github.com/PennyLaneAI/pennylane/pull/2781)
* Added operation `qml.QutritUnitary` for applying user-specified unitary operations on qutrit devices.
([#2781](https://github.com/PennyLaneAI/pennylane/pull/2781), [#2782](https://github.com/PennyLaneAI/pennylane/pull/2782))

* Added operation `qml.QutritUnitary` for applying user-specified unitary operations on qutrit devices.
[(#2699)](https://github.com/PennyLaneAI/pennylane/pull/2699)

**Operator Arithmetic:**
Expand Down
78 changes: 55 additions & 23 deletions pennylane/_qutrit_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

# For now, arguments may be different from the signatures provided in QubitDevice to minimize size of pull request
# e.g. instead of expval(self, observable, wires, par) have expval(self, observable)
# pylint: disable=abstract-method, no-value-for-parameter,too-many-instance-attributes,too-many-branches, no-member, bad-option-value, arguments-renamed
# pylint: disable=arguments-differ, abstract-method, no-value-for-parameter,too-many-instance-attributes,too-many-branches, no-member, bad-option-value, arguments-renamed
import itertools

import numpy as np
Expand Down Expand Up @@ -80,10 +80,6 @@ def capabilities(cls):
capabilities.update(model="qutrit")
return capabilities

def statistics(self, observables, shot_range=None, bin_size=None):
# Overloading QubitDevice.statistics() as VnEntropy and MutualInfo not yet supported for QutritDevice
raise NotImplementedError

def generate_samples(self):
r"""Returns the computational basis samples generated for all wires.

Expand Down Expand Up @@ -152,15 +148,18 @@ def states_to_ternary(samples, num_wires, dtype=np.int64):
def density_matrix(self, wires):
"""Returns the reduced density matrix prior to measurement.

.. note::
Args:
wires (Wires): wires of the reduced system

Only state vector simulators support this property. Please see the
plugin documentation for more details.
Raises:
QuantumFunctionError: density matrix is currently unsupported on :class:`~.QutritDevice`
"""
# TODO: Add density matrix support. Currently, qml.math is hard-coded to work only with qubit states,
# (see `qml.math.reduced_dm()`) so it needs to be updated to be able to handle calculations for qutrits
# before this method can be implemented.
raise NotImplementedError
raise qml.QuantumFunctionError(
"Unsupported return type specified for observable density matrix"
)

def vn_entropy(self, wires, log_base):
r"""Returns the Von Neumann entropy prior to measurement.
Expand All @@ -172,13 +171,15 @@ def vn_entropy(self, wires, log_base):
wires (Wires): Wires of the considered subsystem.
log_base (float): Base for the logarithm, default is None the natural logarithm is used in this case.

Returns:
float: returns the Von Neumann entropy
Raises:
QuantumFunctionError: Von Neumann entropy is currently unsupported on :class:`~.QutritDevice`
"""
# TODO: Add support for VnEntropy return type. Currently, qml.math is hard coded to calculate this for qubit
# states (see `qml.math.vn_entropy()`), so it needs to be updated before VnEntropy can be supported for qutrits.
# For now, if a user tries to request this return type, an error will be raised.
raise NotImplementedError
raise qml.QuantumFunctionError(
"Unsupported return type specified for observable Von Neumann entropy"
)

def mutual_info(self, wires0, wires1, log_base):
r"""Returns the mutual information prior to measurement:
Expand All @@ -194,13 +195,15 @@ def mutual_info(self, wires0, wires1, log_base):
wires1 (Wires): wires of the second subsystem
log_base (float): base to use in the logarithm

Returns:
float: the mutual information
Raises:
QuantumFunctionError: Mutual information is currently unsupported on :class:`~.QutritDevice`
"""
# TODO: Add support for MutualInfo return type. Currently, qml.math is hard coded to calculate this for qubit
# states (see `qml.math.mutual_info()`), so it needs to be updated before MutualInfo can be supported for qutrits.
# For now, if a user tries to request this return type, an error will be raised.
raise NotImplementedError
raise qml.QuantumFunctionError(
"Unsupported return type specified for observable mutual information"
)

def estimate_probability(self, wires=None, shot_range=None, bin_size=None):
"""Return the estimated probability of each computational basis state
Expand Down Expand Up @@ -317,10 +320,27 @@ def marginal_prob(self, prob, wires=None):
perm = basis_states @ powers_of_three
return self._gather(prob, perm)

# TODO: Update in next PR to add counts capability for binning
def sample(
self, observable, shot_range=None, bin_size=None
): # pylint: disable=arguments-differ
def sample(self, observable, shot_range=None, bin_size=None, counts=False):
def _samples_to_counts(samples, no_observable_provided):
"""Group the obtained samples into a dictionary.

**Example**

>>> samples
tensor([[0, 0, 1],
[0, 0, 1],
[1, 1, 1]], requires_grad=True)
>>> self._samples_to_counts(samples)
{'111':1, '001':2}
"""
if no_observable_provided:
# If we describe a state vector, we need to convert its list representation
# into string (it's hashable and good-looking).
# Before converting to str, we need to extract elements from arrays
# to satisfy the case of jax interface, as jax arrays do not support str.
samples = ["".join([str(s.item()) for s in sample]) for sample in samples]
states, counts = np.unique(samples, return_counts=True)
return dict(zip(states, counts))

# TODO: Add special cases for any observables that require them once list of
# observables is updated.
Expand All @@ -329,10 +349,9 @@ def sample(
device_wires = self.map_wires(observable.wires)
name = observable.name # pylint: disable=unused-variable
sample_slice = Ellipsis if shot_range is None else slice(*shot_range)
no_observable_provided = isinstance(observable, MeasurementProcess)

if isinstance(
observable, MeasurementProcess
): # if no observable was provided then return the raw samples
if no_observable_provided: # if no observable was provided then return the raw samples
if (
len(observable.wires) != 0
): # if wires are provided, then we only return samples from those wires
Expand All @@ -359,9 +378,22 @@ def sample(
) from e

if bin_size is None:
if counts:
return _samples_to_counts(samples, no_observable_provided)
return samples

return samples.reshape((bin_size, -1))
num_wires = len(device_wires) if len(device_wires) > 0 else self.num_wires
if counts:
shape = (-1, bin_size, num_wires) if no_observable_provided else (-1, bin_size)
return [
_samples_to_counts(bin_sample, no_observable_provided)
for bin_sample in samples.reshape(shape)
]
return (
samples.reshape((num_wires, bin_size, -1))
if no_observable_provided
else samples.reshape((bin_size, -1))
)

# TODO: Implement function. Currently unimplemented due to lack of decompositions available
# for existing operations and lack of non-parametrized observables.
Expand Down
Loading