-
Notifications
You must be signed in to change notification settings - Fork 585
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] Allow user to define non-consecutive wires for a device #666
Conversation
Co-authored-by: Josh Izaac <josh146@gmail.com>
Co-authored-by: Josh Izaac <josh146@gmail.com>
Co-authored-by: Josh Izaac <josh146@gmail.com>
Regarding @josh146 comment on Tensor observables: I just realised that another problem here is the omission of identities, like in It is another example of where the wires refactor uncovers how much the independence of the |
@josh146, @trbromley , @co9olguy Thanks for your great reviews! No need for action for now, I will ping you when everything is ready (in case you want to have a last look). As a summary, I addressed the major issues as follows:
|
Hey @mariaschuld ! Just gonna put some of my observations/questions here about the wires, based on what I saw from within the context of qchem. Hopefully not hijacking the comments here and sorry for the long rant.:laughing: The more I look into it the more it looks like there are multiple things at play here, definitely not as innocent as it initially seemed 😆 . To me, there are two assumptions under the old way of naming wires: 1) consecutive order, and 2) But to keep In the context of qchem, if we keep (2) unbroken, the conversion from OpenFermion (who always uses consecutive int cubits) to Pennylane will require the user to supply the wire names of the device he latter is going to run the ansatz on; this could even be before a device is defined. This feels a bit unnatural to me and thus led to the ranting above. Or, I could keep wires as is and experiment with the operator-to-device wire mapping mentioned above. And the issue about Also @agran2018, to keep everyone in the loop. |
Thanks @zeyueN, some good thoughts. From a very high level, it would be great it we could preserve
It would also be quite nice to preserve
as this is a familiar paradigm in other QC libraries (Qiskit, OpenFermion), and allows us to abstract a lot of the more complicated logic. Users running simulations likely will be working with assumed consecutive integers as well, and this would allow them to avoid any additional 'wire label registration'. However, this one is likely highly non-trivial as @mariaschuld was mentioning. |
Thanks @zeyueN, your comment raises some good food for thought! We're thinking of ways for make operators more independently composable outside of QNodes in the future, and this would require a strong separation from the specific devices. Conceptually, I think we can indeed separate "wire labels" logically from devices. |
Is this the case? ideally, all |
This is where I was referring to that matches operator's wires to device's wires: |
Thanks @zeyueN for finding that one, it definitely looks like something that should be ironed out. 🤔 I think what should be checked is that the user's labels for wires in the operations are self-consistent, and can be mapped to corresponding labels on the underlying devices, not necessarily that the user's names for wires match the underlying indices/labels the device prefers (by default, consecutive integers) |
…nylane into allow_non_consecutive_wires
* rm consec wires assumption in map and Tensor.prune * treat Wires separately for _flatten
…nylane into allow_non_consecutive_wires
* add wire map functionality to Wires class, and to Device * Backup * make syntax more elegant and add tests * fix all tests * delete comments * black * polish * polish * polish2 * fix refactor problem * small fixes * one more fix * add __array__ func to wires * Update pennylane/_device.py Co-authored-by: Nathan Killoran <co9olguy@users.noreply.github.com> * Update pennylane/_device.py Co-authored-by: Nathan Killoran <co9olguy@users.noreply.github.com> * Update pennylane/plugins/default_gaussian.py Co-authored-by: Nathan Killoran <co9olguy@users.noreply.github.com> * code review comments * finish code review comments * remove superfluous line * [WIRES] Sort observables in Tensor class (#734) * backuo * change sorting function * fix stuff * remove indexing with wires * remove more of those instances * try one more change * backup * convert wires to list in map function Co-authored-by: Nathan Killoran <co9olguy@users.noreply.github.com>
Context:
This is the main PR of the wires management refactor. It refactors PennyLane to not assume any more that wires are consecutive integers that can be sorted and compared.
Description of the Change:
The main change is to use the
wires
argument indevice('XXX', wires=..)
optionally to pass a sequence of representations or identifiers of wires, i.e. (to name a crazy example).This user wire ordering is converted to a Wires object and stored in the new attribute
register
. If the old versiondevice('XXX', wires=N)
is used, the register is initialised withWires(range(N))
instead.The user can now address wires with her labels, i.e.
Hadamard(wires=['q2'])
. The device translates these labels into indices of the wires in the register, i.e. viawire_indices = self.register.indices(op.wires)
Finally, with this changes we can now let the Wires objects (which do not follow a consecutive logic) pass freely through PennyLane, instead of converting them to lists, as done in the previous PR.
This PR also contains new tests to check that various parts of PennyLane work smoothly for non-consecutive wires.