Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Advanced tutorial on quantum simulation #33

Merged
merged 14 commits into from
Oct 3, 2022

Conversation

ajrazander
Copy link
Contributor

This PR includes an advanced tutorial on quantum simulation methods with the aim of demonstrating advanced topics in quantum simulation and error mitigation to newcomers.

@coveralls
Copy link

coveralls commented Sep 9, 2022

Pull Request Test Coverage Report for Build 3175685706

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage remained the same at 88.726%

Totals Coverage Status
Change from base Build 2929411720: 0.0%
Covered Lines: 2424
Relevant Lines: 2732

💛 - Coveralls

@kevinsung
Copy link
Collaborator

The notebook is too large to view in GitHub so I won't be able to provide comments in-line.

Just a few comments for now:

  • After reading a bit of the beginning, I noticed some typos. Could you go through it one more time to try to fix any remaining?
    • "We hope you find the source code to jump start your dive..." it seems you forgot a word here, like "find the source code useful..."
    • "It is also apart of other, more complicated" missing a space
  • When introducing Trotterization of the tight-binding model, please mention that the tight-binding model can be simulated exactly efficiently because it is a quadratic fermion Hamiltonian, and that you are using Trotterization only for expository purposes.

@kevinsung
Copy link
Collaborator

kevinsung commented Sep 9, 2022

def compute_H(tau, tau_d, num_sites, defect_locs):
    '''
    Compute 1D spinless tight-binding Hamiltonian with "defective" interactions on specificed edges
    
    Args:
        tau - float; strength of hopping term between all sites except at the defect edge(s)
        tau_d - float; strength of hopping term at defect edge(s)
        num_sites - int; number of lattice sites in the 1D chain
        defect_locs - list or array of ints; index location(s) of defect edge(s). Indexed such that the left most edge is at position 0 and the rightmost is 4

    Returns:
        H - SummedOp; the Hamiltonian
    '''
    
    H = 0
    for i in range(num_sites-1):
        if (i in defect_locs):
            H += -tau_d/2 * ((I^(num_sites-i-2))^(X^X)^(I^i))
            H += -tau_d/2 * ((I^(num_sites-i-2))^(Y^Y)^(I^i))
        else:
            H += -tau/2 * ((I^(num_sites-i-2))^(X^X)^(I^i))
            H += -tau/2 * ((I^(num_sites-i-2))^(Y^Y)^(I^i))
    return H

Wouldn't it be more appropriate and pedagogical to construct the original fermionic Hamiltonian using Qiskit Nature and then map it to a qubit Hamiltonian using the Jordan-Wigner transform in Qiskit Nature?

@ajrazander ajrazander changed the title Add advanced tutorial on quantum simulation Advanced tutorial on quantum simulation Sep 13, 2022
@ajrazander
Copy link
Contributor Author

The listed typos have been corrected. I scanned over the notebook again but didn't find any others. Thanks for the qiskit nature suggestion. We added it, and kept the Opflow method because 1) it's good to be familiar with how to do this both ways and 2) the opflow method supports Parameters, but the FermionicOp object does not currently support Parameters.

@kevinsung
Copy link
Collaborator

Ah ok that makes sense, I hadn't thought of the Parameters issue. Please state explicitly in the notebook that the reason we use OpFlow at all is that Nature does not yet support Parameters. Then, add a TODO in a comment saying to update the notebook once Qiskit Nature supports Parameters.

The tests are failing because tqdm is not installed. You'll need to add that to requirements-dev.txt. You need to format your notebook using black in order to pass the format check. Something like

pip install black[jupyter]
black qsim-tight-binding-model.ipynb

Also ran black styling on notebook and included tqdm in requirements file
@ajrazander
Copy link
Contributor Author

ajrazander commented Sep 14, 2022

Made the changes and committed :)

Edit:
Looks like there is a check error when running the notebook. I've included accessing the backends, but didn't put in a valid token or hub-group-project.

@kevinsung
Copy link
Collaborator

There is now an issue at Qiskit Nature for Parameter support: qiskit-community/qiskit-nature#828. Please reference this issue in the TODO that I asked you to add.

replaced depreciated ignis measurement error mit with mthree; updated the rzx transpiler pass to be compatible with latest qiskit version; formatted print statements; and corrected typos
@ajrazander
Copy link
Contributor Author

Committed with latest changes: using mthree for measurement mitigation now, updated TODO, fixed a couple typos, formatted print statements, updated Rzx pulse scaling Transpiler pass for lastest qiskit version (0.38), and reformatted the notebook using black.

@kevinsung
Copy link
Collaborator

@ajrazander It seems like the notebook should still run if you use an instance of FakeLagos instead of the real one. Could you test that? If it works, then you should comment out the code that instantiates a real backend, and use a fake backend instead. That way, we can actually test the notebook and can satisfy the CI.

@ajrazander
Copy link
Contributor Author

Using FakeLagos gives dramatically better results compared to the real backend. The plots look quite different. I'd like the plots to display the data from the real backend, not simulated data. What's the best way to do this?

@kevinsung
Copy link
Collaborator

Unfortunately we don't currently have a good way to retrieve real data and still test the notebook. You can include instructions in the notebook for swapping out the simulator for a real backend, and reference your paper for the real data.

@kevinsung
Copy link
Collaborator

As a side note, the noise models in Qiskit Terra should be made more realistic. If you'd like, you can open an issue at Terra with a simple example showing the discrepancy.

@ajrazander
Copy link
Contributor Author

Done and done Qiskit/qiskit#8786

of the experiment were implemented, collects experimental data, analyzes data, and generates plots.

.. _arXiv:2209.02795: https://arxiv.org/abs/2209.02795
.. _tutorial: qsim-tight-binding-model.ipynb
Copy link
Collaborator

Choose a reason for hiding this comment

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

It looks like the link is written incorrectly. Please build the docs locally and make sure they look correct.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've updated the index.rst files, and the building is doing better than before, but now it's timing out. I get this output:

.
.
.
Notebook error:
CellTimeoutError in tutorial_quantum_sim/qsim-tight-binding-model.ipynb:
A cell timed out while it was being executed, after 180 seconds.
The message was: Cell execution timed out.
Here is a preview of the cell contents:
-------------------
['# Evaulate all circuits over all time points and take the mean', '', '# Compute parameterized circuit over a range of trotter steps', 'trotter_steps_array = np.arange(1, 13)', '']
...
['    # Calculate average fidelity for a given trotter step', '    qc_rzx_fid_ests.append(np.mean(rzx_fids))', '', '    # Calculate average duration for a given trotter step', '    qc_rzx_dur_ests.append(np.mean(qc_dur))']
-------------------

Task was destroyed but it is pending!
task: <Task pending name='Task-453' coro=<NotebookClient._async_poll_output_msg() running at /Users/ajrasmusson/Documents/GitHub/qiskit-research/.tox/docs/lib/python3.8/site-packages/nbclient/client.py:812> wait_for=<Future pending cb=[<TaskWakeupMethWrapper object at 0x7fe8b209b730>()]>>
ERROR: InvocationError for command /Users/ajrasmusson/Documents/GitHub/qiskit-research/.tox/docs/bin/sphinx-build -b html -W docs/ docs/_build/html (exited with code 2)
______________________________________________________ summary ______________________________________________________
ERROR:   docs: commands failed

I'm not sure what the error here is exactly. It seems like the tox -edocs is trying to run the notebook, but one of the cells is taking longer then 180 seconds?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Please push your changes and I will investigate increasing the time limit. I'm wondering though, could you take a look at the long-running cell and think about whether there is a reasonable way to make it execute faster?

@kevinsung
Copy link
Collaborator

Please revert the unrelated changes to the protein folding notebook.

Copy link
Collaborator

@kevinsung kevinsung left a comment

Choose a reason for hiding this comment

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

@ajrazander is this ready is merge?

@ajrazander
Copy link
Contributor Author

Yes, I don't have any other edits :)

@kevinsung kevinsung merged commit 306bfb6 into qiskit-community:main Oct 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants