Comments (12)
Sounds perfect @soranjh. I will prepare a PR in the coming days. I will orient myself on the kUpCCGSD template as you said.
Thank you @soranjh @CatalinaAlbornoz for your quick responses. Very much appreciated β€οΈ
from pennylane.
Hi @S-Erik ,
Thanks for your suggestion! My colleague Soran helped me with some insights here.
It is correct the our implementation of UCCSD, following literature, assumes first-order Trotter expansion.
What Qiskit does is that it repeats the template n times. You can code this as part of any circuit in PennyLane too!
We also have the kUpCCGSD template where k is a user-defined parameter specifying the number of repetitions.
Take a look at this template, it might be exactly what you were looking for! π
from pennylane.
Thank you for your quick answer @CatalinaAlbornoz. Now, I have a few further questions:
How do you imagine repeating the UCCSD template in PennyLane? Because a simple for loop in a circuit definition does not work. For example
@qml.qnode(dev)
def circuit(params):
for rep in range(uccsd_reps):
qml.UCCSD(params[rep], wires, s_wires, d_wires, init_state=hf_state)
return qml.expval(H)
does not work as intended because the BasisState(init_state)
is used every time qml.UCCSD
is called, see this code line in pennylane/uccsd.py. Therefore, each application of qml.UCCSD
first resets the state of the quantum circuit to the init_state
.
A naΓ―ve approach trying to work around this reset by setting init_state=None
,
@qml.qnode(dev)
def circuit(params):
for rep in range(uccsd_reps):
init_state = hf_state if rep == 0 else None # ValueError: Elements of 'init_state' must be integers; got object
qml.UCCSD(params[rep], wires, s_wires, d_wires, init_state=init_state)
return qml.expval(H)
, results in a ValueError: Elements of 'init_state' must be integers; got object
, since BasisState accepts only a list of integers and always prepares a basis state.
You are correct that the implementation of the kUpCCGSD template is very similar to what I proposed in my initial comment. But, since the kUpCCGSD template uses generalized fermionic excitations it generates a different circuit than the UCCSD template even for
I hope I did not make a mistake implementing your suggestion.
from pennylane.
Hi @S-Erik,
I'm checking with the team on this. We'll be back in the next few days with more info on what can be done here. Thanks for your questions!
from pennylane.
Hi @S-Erik and thanks for opening the issue. Repeating the first-order UCCSD ansatz, as you suggested, is an option for improving accuracy but it will make your circuit deep and expensive to simulate. The better alternative is to build adaptive circuits, where extra gates are added systematically to improve the quality of your ansatz. You can find more details in this demo. Please let me know if the adaptive method is a solution for your problem.
from pennylane.
Hi @soranjh. Thank you for your concerns and suggestions. I am aware of the ADAPT-VQE approach and its usage in PennyLane. Unfortunately, my aim for this issue is that one can improve the accuracy of the UCCSD ansatz by using higher-orders. The main reason for this is to investigate the limit of the UCCSD ansatz and the error from different Trotter-orders. Since ADAPT-VQE converges to the FCI value for large ADAPT-steps value and not to the UCCSD limit, I cannot assess the UCCSD error with ADAPT-VQE.
I hope you can better understand my aim now and I am open for any further suggestions.
from pennylane.
Thanks for the clarification @S-Erik. Have you considered using the SingleExcitation
and DoubleExcitation
gates and building your circuit manually? This will be very easy and you can repeat your gates as many time as you want. Please let me know if this solution is working, otherwise we can add a parameter to the UCCSD ansatz to allow repetition.
def circuit(params):
qml.BasisState(hf_state, wires=range(qubits))
for i, excitation in enumerate(excitations):
if len(excitation) == 4:
qml.DoubleExcitation(params[i], wires=excitation)
elif len(excitation) == 2:
qml.SingleExcitation(params[i], wires=excitation)
# repeat as needed
return qml.expval(...)
from pennylane.
Thank you for your suggestion @soranjh. Building the circuit manually would indeed work. Your code suggestion is therefore very close to the already implemented UCCSD template and my UCCSD_w_reps
template in my initial comment.
I believe it would benefit PennyLane to incorporate this functionality of allowing repetitions into the existing UCCSD template. Similarly, one could argue that while a UCCSD template isn't strictly necessary, because the circuit can also be build manually, it does streamline the process by automating the creation of the circuit.
from pennylane.
Thanks @S-Erik, sounds good. Are you interested to open a quick PR and add a repeat parameter? The implementation will be similar to that of kUpCCGSD template.
from pennylane.
It's great to hear that you decided to prepare the PR! Let us know if you have any questions along the way and please mention this issue in the PR too!
from pennylane.
I have just created a PR, see #5801.
from pennylane.
Thanks @S-Erik !
from pennylane.
Related Issues (20)
- [BUG] Loading the MQT Bench dataset does not work as expected. HOT 1
- [BUG] Array indexing error when sampling after mid-circuit measurements are performed on other wires HOT 3
- NotImplementedError: VJP of eigvals wrt argnums (0,) not defined[BUG] HOT 2
- Implement `Hermitian.decomposition`
- [BUG] `qml.center` does not work for all linear combinations of Paulis
- [BUG] JAX JIT errors-out when using a tracer-based PRNG key HOT 4
- [BUG] WireError when computing quantum fisher info of mixed state HOT 2
- `qml.lie_closure` often raises `LinAlgError: Singular matrix` HOT 4
- [BUG] Class method hyperlinks don't work in PL docs
- [BUG] imaginary part of expectation values of observables with complex coefficients is silently discarded HOT 5
- [BUG] TorchLayer doesn't work with diff_method='parameter-shift'
- [Regression] Restore good performance when requesting many individual shots HOT 1
- Add `is_leaf`optional keyword argument to `qml.pytrees.flatten` HOT 4
- specify dtype for "default.qubit" [BUG] HOT 8
- [BUG] qml.shadows.shadow_expval raises an exception HOT 2
- [BUG] `pattern_matching_optimization` eliminates all measurements
- [BUG] Incorrect documentation in `mitigate_with_zne`
- Distributive property is not correctly applied without `simplify`
- [BUG] Probabilities not summing to 1 on `default.qubit`
- [BUG] `qml.qsvt` throws `UnboundLocalError` with `convention = Wx` HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pennylane.