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

[WIRES] Make plugin compatible with wires refactor #37

Merged
merged 5 commits into from
Aug 6, 2020
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
30 changes: 29 additions & 1 deletion .github/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,22 @@

### Improvements

* Made plugin device compatible with new PennyLane wire management.

One can now specify any string or number as a custom wire label,
and use these labels to address subsystems on the device:

``` python

dev = qml.device('cirq.simulator', wires=['q1', 'ancilla', 0, 1]

def circuit():
qml.Hadamard(wires='q1')
qml.CNOT(wires=[1, 'ancilla'])
...
```
[#37](https://github.com/PennyLaneAI/pennylane-cirq/pull/37)

### Documentation

### Bug fixes
Expand All @@ -14,6 +30,18 @@

This release contains contributions from (in alphabetical order):

Maria Schuld

---

# Release 0.9.1

### Improvements

### Contributors

This release contains contributions from (in alphabetical order):

---

# Release 0.9.0
Expand All @@ -39,7 +67,7 @@ This release contains contributions from (in alphabetical order):

This release contains contributions from (in alphabetical order):

Theodor Isacsson, Nathan Killoran, Maria Shuld, Antal Száva
Theodor Isacsson, Nathan Killoran, Maria Schuld, Antal Száva

---

Expand Down
7 changes: 5 additions & 2 deletions pennylane_cirq/cirq_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ def __init__(self, wires, shots, analytic, qubits=None):

self.circuit = None

device_wires = self.map_wires(self.wires)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, so if I understand this correctly, self.map_wires will in this case go from e.g. self.wires -> ['q1', 'ancilla', 0, 1] to device_wires -> [0, 1, 2, 3]. And then the list of wires can be extracted from the Wires object with device_wires.labels. Is this correct?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, perfect! Well, strictly speaking the map goes from self.wires -> Wires(['q1', 'ancilla', 0, 1]) to device_wires -> Wires([0, 1, 2, 3]), and device_wires.labels is the tuple (0, 1, 2, 3)...


if qubits:
if wires != len(qubits):
raise qml.DeviceError(
Expand All @@ -81,7 +83,7 @@ def __init__(self, wires, shots, analytic, qubits=None):

self.qubits = qubits
else:
self.qubits = [cirq.LineQubit(wire) for wire in range(wires)]
self.qubits = [cirq.LineQubit(wire) for wire in device_wires.labels]

# Add inverse operations
self._inverse_operation_map = {}
Expand Down Expand Up @@ -193,8 +195,9 @@ def _apply_operation(self, operation):
if cirq_operation:
cirq_operation.parametrize(*operation.parameters)

device_wires = self.map_wires(operation.wires)
self.circuit.append(
cirq_operation.apply(*[self.qubits[wire] for wire in operation.wires])
cirq_operation.apply(*[self.qubits[w] for w in device_wires.labels])
)

def apply(self, operations, **kwargs):
Expand Down