PennyLaneAI / pennylane

PennyLane is a cross-platform Python library for quantum computing, quantum machine learning, and quantum chemistry. Train a quantum computer the same way as a neural network.
https://pennylane.ai
Apache License 2.0
2.27k stars 585 forks source link

Pennylane functionality with arbitrary operators #5456

Open joeybarreto opened 5 months ago

joeybarreto commented 5 months ago

Feature details

In the context of VQE, I am wondering whether in Pennylane it is a hard requirement that all unitaries must be defined over qubits, or if it's possible to optimize a cost function <U* H U> where the dimensions of U and H aren't necessarily a power of 2. Basically, I don't want to define an underlying circuit - is this a no-go? Or is it possible that the cost can still be numerically optimized by using/hacking Pennylane methods as-is?

Implementation

I don't need a proper implementation per-se, just some way of calling (potentially) internal functions to extract the necessary functionality.

How important would you say this feature is?

1: Not important. Would be nice to have.

Additional information

No response

trbromley commented 5 months ago

Hi @joeybarreto, this is a good question. Right now, PennyLane is quite dimension-dependent - we have support for both qubits and qutrits, but it would be great to generalize to arbitrary $d$.

Though we're always up for prioritizing features if they are of use to users. It would be great to get a few more details on what you're trying to do, perhaps we could have a brief call to get on the same page?

isaacdevlugt commented 2 weeks ago

Hey @joeybarreto! It's been a while since there was any activity here. Just wondering if you're able to provide us with more context regarding what you're trying to accomplish with PennyLane? 🙂

joeybarreto commented 1 day ago

Hi, sorry for the delayed reply. The main idea is that I have a simulation of a physical system which obeys some symmetries. I can choose two ways of simulating it:

Ideally, I could take my projected states/operators and just cast them to Pennylane objects, and run the circuits like usual. The parameter shift rules won't work out of the box here, but analytic gradient recipes should still apply given that each gate is still of the form $U = e^{-i \theta H}$. I know that QuTiP essentially can do this, but it would be nice to have out-of-the-box access to Pennylane optimizers. I have NumPy code which does all of this now, so I can get by, but I was wondering how hard it would be to get this functionality in Pennylane. I'm imagining a simple quantum device which takes in a $dim=d$ instead of a number of qubits, and supports simple things like state prep, unitaries, exp values, and training via backprop/adjoint gradients.

isaacdevlugt commented 1 day ago

Hey @joeybarreto no worries! Thanks for getting back to us.

Do you mind sharing some toy example code that we can use to reference exactly what you want to accomplish? This will help us figure out the best path forward (i.e., if there is something in PennyLane currently that you can use, or if we can suggest adding something new to PennyLane to meet your needs).