Skip to content

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

Merged
abbycross merged 21 commits intomainfrom
spsa-vqe
Apr 2, 2026
Merged

updating spin-chain-vqe tutorial to use SPSA#4744
abbycross merged 21 commits intomainfrom
spsa-vqe

Conversation

@nathanearnestnoble
Copy link
Copy Markdown
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
Copy Markdown

Check out this pull request on  ReviewNB

See visual diffs & provide feedback on Jupyter Notebooks.


Powered by ReviewNB

@qiskit-bot
Copy link
Copy Markdown
Contributor

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

@nathanearnestnoble
Copy link
Copy Markdown
Collaborator Author

Resolves issue 3632 (#3632)

@@ -1,411 +1,470 @@
{
Copy link
Copy Markdown
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

Comment thread docs/tutorials/spin-chain-vqe.ipynb Outdated
"name": "python3"
],
"metadata": {
"description": "Build, deploy, and run a Qiskit pattern for simulating a Heisenberg chain and estimating its ground state energy.",
Copy link
Copy Markdown
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
Copy Markdown
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 😅 )

Comment thread docs/tutorials/spin-chain-vqe.ipynb Outdated
"pygments_lexer": "ipython3",
"version": "3.13.3"
},
"title": "Ground state energy estimation of the Heisenberg chain with VQE"
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown

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
Copy Markdown
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 thread docs/tutorials/spin-chain-vqe.ipynb
abbycross
abbycross previously approved these changes Mar 23, 2026
Copy link
Copy Markdown
Collaborator

@abbycross abbycross left a comment

Choose a reason for hiding this comment

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

Thanks!

Comment thread docs/tutorials/spin-chain-vqe.ipynb Outdated
@abbycross
Copy link
Copy Markdown
Collaborator

FYI - In my last commit I needed to revert the change that introduced the pip install for visualization - we intentionally no longer list it out because the exact syntax to install it varies depending on your OS (so instead we just point to the API docs).

@abbycross abbycross added this pull request to the merge queue Apr 2, 2026
Merged via the queue into main with commit 651d8fe Apr 2, 2026
5 checks passed
@abbycross abbycross deleted the spsa-vqe branch April 2, 2026 18:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

Update VQE tutorial to have SPSA optimizer

6 participants