Skip to content

updating spin-chain-vqe tutorial to use SPSA#4744

Open
nathanearnestnoble wants to merge 16 commits intomainfrom
spsa-vqe
Open

updating spin-chain-vqe tutorial to use SPSA#4744
nathanearnestnoble wants to merge 16 commits intomainfrom
spsa-vqe

Conversation

@nathanearnestnoble
Copy link
Collaborator

@nathanearnestnoble nathanearnestnoble commented Mar 3, 2026

Work done by Aryaman Manish Kolhe (@Chasmiccoder) and Ritajit Majumdar (@ritajitmajumdar1). Would like to update tutorial with this SPSA implementation.

Fixes #3632

Work done by Aryaman Manish Kolhe (Chasmiccoder) and Ritajit Majumdar (ritajitmajumdar1)
@review-notebook-app
Copy link

Check out this pull request on  ReviewNB

See visual diffs & provide feedback on Jupyter Notebooks.


Powered by ReviewNB

@qiskit-bot
Copy link
Contributor

One or more of the following people are relevant to this code:

@nathanearnestnoble
Copy link
Collaborator Author

Resolves issue 3632 (#3632)

@@ -1,411 +1,470 @@
{
Copy link
Collaborator

@kaelynj kaelynj Mar 3, 2026

Choose a reason for hiding this comment

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

Looks like this needs the title and metadata tags at the very top of the file. You should be able to replace this cell with the following:

---
title: Ground-state energy estimation of the Heisenberg chain with VQE
description: Build, deploy, and run a Qiskit pattern for simulating a Heisenberg chain and estimating its ground state energy.
---  

*Usage estimate: 37 minutes on a Heron processor (NOTE: This is an estimate only. Your runtime might vary.)*

Reply via ReviewNB

"name": "python3"
],
"metadata": {
"description": "Build, deploy, and run a Qiskit pattern for simulating a Heisenberg chain and estimating its ground state energy.",
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
"description": "Build, deploy, and run a Qiskit pattern for simulating a Heisenberg chain and estimating its ground state energy.",

Copy link
Collaborator

Choose a reason for hiding this comment

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

The title and metadata tags now need to go at the top of the file (though I'm not totally sure when that changed 😅 )

"pygments_lexer": "ipython3",
"version": "3.13.3"
},
"title": "Ground state energy estimation of the Heisenberg chain with VQE"
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
"title": "Ground state energy estimation of the Heisenberg chain with VQE"

@abbycross
Copy link
Collaborator

@kaelynj @nathanearnestnoble I fixed the metadata but am getting an error regarding an unused variable session, stemming from

    # Evaluate the problem using a QPU via Qiskit IBM Runtime
    with Session(backend=backend) as session:
        estimator = EstimatorV2()
        estimator.skip_transpilation = True
        x_opt = spsa(
            cost_func,
            x0=x0,
            args=(isa_ansatz, isa_observable, estimator, cost_history_dict),
            maxiter=maxiter,
        )

can you help clear the error? I can then clear the rest of the checks, like converting the output to images.

@Chasmiccoder
Copy link

Chasmiccoder commented Mar 20, 2026

Hi @abbycross and everyone. Thank you for helping merge this work.

I believe from the code snippet you have shared, the error can be fixed as follows:

with Session(backend=backend) as _:

The problem might be that if you write

with Session(backend=backend) as session:

then the variable session is being created but not used in the code block, which is being flagged by the compiler.

@ritajitmajumdar1
Copy link
Collaborator

Rather just do

estimator = EstimatorV2(mode=session)

This ensures the entire block runs as a single session. Unless the Estimator is initiated with session, I presume it would run in a job mode.

Comment on lines +428 to +430
"<Admonition type=\"tip\" title=\"Recommendations\">\n",
"If you found this work interesting, you might be interested in the following material:\n",
"</Admonition>"
Copy link
Collaborator

Choose a reason for hiding this comment

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

Are there any suggestions to add here, for what to read or other tutorials to explore after doing this tutorial? If not, we can remove this whole cell.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Not sure if there are any tutorials as follow up. Since this is variational, the only variational algorithm in the current tutorials is QAOA. But it is not an extension of this tutorial.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

Update VQE tutorial to have SPSA optimizer

6 participants