-
Notifications
You must be signed in to change notification settings - Fork 186
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
Tutorial: tensor network basics #1193
base: master
Are you sure you want to change the base?
Conversation
👋 Hey, looks like you've updated some demos! 🐘 Don't forget to update the Please hide this comment once the field(s) are updated. Thanks! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great skeleton @EmilianoG-byte @Shiro-Raven !
Mainly minor suggestions, and one bigger one towards the last section for quantum circuit applications
demonstrations/tutorial_tn_basics.py
Outdated
- For this reason there exist heuristics for optimizing contraction path complexity. NP problem -> no perfect solution but great heuristics (https://arxiv.org/pdf/2002.01935). | ||
(optional) mention the idea behind some of them | ||
Link to quimb examples. | ||
- CODE: show this using np.einsum, timeit, and very large dimensions expecting to see a difference. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
timeit is a good idea, could also print out dimensions at different steps along a contraction path
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good idea!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Coming back to this, I printed the dimensions locally but I don't quite get what insight we get from this. Since we only have three tensors, the dimensions of intermediate tensors (AB) and (BC) are actually exactly the same. This also by construction to get the expected scaling in the computational cost.
I could come up with an example where the dimensions vary between contraction paths but probably would have to be more complex and not just a "triangle-like" tensor network
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah sounds like the example is too simple to show the desired property
I could come up with an example where the dimensions vary between contraction paths
💯
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just to be sure, I guess also the timing is the same in the situation you describe rn?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well the timing varies and that is what I was trying to convey here, as the timing scales exactly as we would expect it from the complexity analysis I discussed some lines before. What would you like to show with the dimensions? That some paths result in tensors of larger intermediate size?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What would you like to show with the dimensions? That some paths result in tensors of larger intermediate size?
exactly :)
demonstrations/tutorial_tn_basics.py
Outdated
From tensor networks to quantum circuits: | ||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
- Quantum circuits are a restricted subclass of tensor networks | ||
- show examples on https://arxiv.org/pdf/1912.10049 page 8 and 9 showing a quantum circuit for a bell state, defining each component as a tensor and show their contraction. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would suggest to do concrete examples of gates already above, e.g. single qubit gates = matrices, 2 qubit gates like CNOT = 4 leg tensor with 2 "in" and 2 "out" legs etc.
and then focus here on how e.g. an expectation value
there are some subtleties here:
- While in priciple a n-qubit state is a n-legged (=2^n sized) tensor,
$\psi_0$ is often a product state, so it is just n independent vectors. - H is often the sum of multiple operators. It is beyond the scope of this tutorial to go in depth, but there are ways to efficiently represent such a sum of tensors (e.g. MPOs and generalizations thereof). The "naive" thing to do for a sum of operators
$H = \sum_i h_i$ is to do separate evaluations for each$\langle \psi_0 | U^\dagger h_i U |\psi_0\rangle$ and sum them in the end. -
$\langle \psi_0 | U^\dagger$ and$U |\psi_0\rangle$ appear twice in the equation, if one can represent their result efficiently we can re-use it (not a given as it may result in a large 2^n tensor)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While in priciple a n-qubit state is a n-legged (=2^n sized) tensor,
$\psi_0$
is often a product state, so it is just n independent vectors.
doesn't this go more into the direction of MPS (which is out of the scope of this tutorial)?
The "naive" thing to do for a sum of operators
If I am not mistaken, since we are assuming an exact contraction of the tensor network without approximating it as an MPS, this naive way is the only option, no? Or is it possible to use the Hamiltonian as an MPO and contract it with the state vector even tho this is not in MPS form?
if one can represent their result efficiently we can re-use it (not a given as it may result in a large 2^n tensor)
here again you mean efficiently as an MPS? Or do you mean this thing that Quimb does where it reuses contraction paths and other parts of the computation? (I couldn't find the link but I remember seeing something along these lines)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I am not mistaken, since we are assuming an exact contraction of the tensor network without approximating it as an MPS, this naive way is the only option, no? Or is it possible to use the Hamiltonian as an MPO and contract it with the state vector even tho this is not in MPS form?
Update: Actually I thought more about it, and I think I was wrong on this. I cannot think of a real constraint of why just contracting a general tensor circuit (no MPS) with an MPO would not work.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
doesn't this go more into the direction of MPS (which is out of the scope of this tutorial)?
A product state is something different. You can interpret it as an MPS with trivial virtual bond dimension 1 but that is not the point
If I am not mistaken, since we are assuming an exact contraction of the tensor network without approximating it as an MPS, this naive way is the only option, no? Or is it possible to use the Hamiltonian as an MPO and contract it with the state vector even tho this is not in MPS form?
MPOs are typically exact and of course you can contract them with something that is not an MPS :)
here again you mean efficiently as an MPS? Or do you mean this thing that Quimb does where it reuses contraction paths and other parts of the computation? (I couldn't find the link but I remember seeing something along these lines)
The latter :) though I am actually not sure what https://github.com/PennyLaneAI/pennylane/blob/master/pennylane/devices/default_tensor.py#L799 does
Do you think is worth going into the details of boolean tensor networks when talking about the CNOT (for instance):
Up to you! I personally dont find that too important but if you like it feel free to include it :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have now added a section on tensor networks-quantum computing. Lmk what you think!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is the demo overall ready for review?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would think so @Qottmann :). I can read the whole thing between today and tomorrow to find typos but content-wise, I am happy with what it has.
I just have two TODO's on the script for myself which are to add some details to some figures.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great! Then I'd suggest to do a self-review first, and when it's ready for a full review please tag me in the PR :)
Thank you for opening this pull request. You can find the built site at this link. Deployment Info:
Note: It may take several minutes for updates to this pull request to be reflected on the deployed site. |
Initial draft from last week: DRAFT:
Very nice source with visual explanations that we can cite: https://www.math3ma.com/blog/matrices-as-tensor-network-diagrams |
hey @EmilianoG-byte @Shiro-Raven how are things coming along? Please let me know when you have a first draft that is ready for review (don't forget to self-review first) :) |
modify size of diagrams
Before submitting
Please complete the following checklist when submitting a PR:
Ensure that your tutorial executes correctly, and conforms to the
guidelines specified in the README.
Remember to do a grammar check of the content you include.
All tutorials conform to
PEP8 standards.
To auto format files, simply
pip install black
, and thenrun
black -l 100 path/to/file.py
.When all the above are checked, delete everything above the dashed
line and fill in the pull request template.
Title:
Summary:
Relevant references:
[sc-66746]
If you are writing a demonstration, please answer these questions to facilitate the marketing process.
GOALS — Why are we working on this now?
Eg. Promote a new PL feature or show a PL implementation of a recent paper.
AUDIENCE — Who is this for?
Eg. Chemistry researchers, PL educators, beginners in quantum computing.
KEYWORDS — What words should be included in the marketing post?
Which of the following types of documentation is most similar to your file?
(more details here)