Giter Site home page Giter Site logo

Comments (12)

S-Erik avatar S-Erik commented on August 20, 2024 1

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.

CatalinaAlbornoz avatar CatalinaAlbornoz commented on August 20, 2024

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.

S-Erik avatar S-Erik commented on August 20, 2024

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 $k=1$.

I hope I did not make a mistake implementing your suggestion.

from pennylane.

CatalinaAlbornoz avatar CatalinaAlbornoz commented on August 20, 2024

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.

soranjh avatar soranjh commented on August 20, 2024

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.

S-Erik avatar S-Erik commented on August 20, 2024

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.

soranjh avatar soranjh commented on August 20, 2024

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.

S-Erik avatar S-Erik commented on August 20, 2024

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.

soranjh avatar soranjh commented on August 20, 2024

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.

CatalinaAlbornoz avatar CatalinaAlbornoz commented on August 20, 2024

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.

S-Erik avatar S-Erik commented on August 20, 2024

I have just created a PR, see #5801.

from pennylane.

CatalinaAlbornoz avatar CatalinaAlbornoz commented on August 20, 2024

Thanks @S-Erik !

from pennylane.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.