Skip to content

Commit

Permalink
add gate by gate sampling and MPS local expectation methods
Browse files Browse the repository at this point in the history
  • Loading branch information
jcmgray committed Oct 18, 2024
1 parent ab9f014 commit d57eb53
Show file tree
Hide file tree
Showing 20 changed files with 1,618 additions and 58,763 deletions.
Binary file added docs/_static/amplitude.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/_static/branching.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/_static/compute_marginal.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/_static/local_expectation.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/_static/partial_trace.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/_static/sample.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/_static/sample_chaotic.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/_static/sample_gate_by_gate.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/_static/to_dense.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
18 changes: 15 additions & 3 deletions docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,26 @@

Release notes for `quimb`.

(whats-new-1-8-5)=
## v1.8.5 (unreleased)
(whats-new-1-9-0)=
## v1.9.0 (unreleased)

**Breaking Changes**

- renamed `MatrixProductState.partial_trace` and `MatrixProductState.ptr` to [MatrixProductState.partial_trace_to_mpo](quimb.tensor.tensor_1d.MatrixProductState.partial_trace_to_mpo) to avoid confusion with other `partial_trace` methods that usually produce a dense matrix.

**Enhancements:**

- add [`Circuit.sample_gate_by_gate`](quimb.tensor.circuit.Circuit.sample_gate_by_gate) and related methods [`CircuitMPS.reordered_gates_dfs_clustered`](quimb.tensor.circuit.Circuit.reordered_gates_dfs_clustered) and [`CircuitMPS.get_qubit_distances`](quimb.tensor.circuit.CircuitMPS.get_qubit_distances) for sampling a circuit using the 'gate by gate' method introduced in https://arxiv.org/abs/2112.08499.
- add [`Circuit.draw`](quimb.tensor.circuit.Circuit.draw) for drawing a very simple circuit schematic.
- [`Circuit`](quimb.tensor.circuit.Circuit): by default turn on `simplify_equalize_norms` and use a `group_size=10` for sampling. This should result in faster and more stable sampling.
- [`Circuit`](quimb.tensor.circuit.Circuit): use `numpy.random.default_rng` for random number generation.
- add [`qtn.circ_a2a_rand`](quimb.tensor.circuit_gen.circ_a2a_rand) for generating random all-to-all circuits.
- expose [`qtn.edge_coloring`](quimb.tensor.tensor_arbgeom_tebd.edge_coloring) as top level function and allow layers to be returned grouped.
- add docstring for [`tn.contract_compressed`](quimb.tensor.tensor_core.TensorNetwork.contract_compressed)
- add docstring for [`tn.contract_compressed`](quimb.tensor.tensor_core.TensorNetwork.contract_compressed) and by default pick up important settings from the supplied contraction path optimizer (`max_bond` and `compress_late`)
- add [`Tensor.rand_reduce`](quimb.tensor.tensor_core.Tensor.rand_reduce) for randomly removing a tensor index by contracting a random vector into it. One can also supply the value `"r"` to `isel` selectors to use this.
- add `fit-zipup` and `fit-projector` shorthand methods to the general 1d tensor network compression function
- add [`MatrixProductState.compute_local_expectation`](quimb.tensor.tensor_1d.MatrixProductState.compute_local_expectation) for computing many local expectations for a MPS at once, to match the interface for this method elsewhere. These can either be computed via canonicalization (`method="canonical"`), or via explicit left and right environment contraction (`method="envs"`)
- specialize [`CircuitMPS.local_expectation`](quimb.tensor.circuit.CircuitMPS.local_expectation) to make use of the MPS form.

---

Expand Down
59,219 changes: 534 additions & 58,685 deletions docs/tensor-circuit.ipynb

Large diffs are not rendered by default.

5 changes: 2 additions & 3 deletions quimb/calc.py
Original file line number Diff line number Diff line change
Expand Up @@ -357,8 +357,7 @@ def simulate_counts(p, C, phys_dim=2, seed=None):
{'000': 514, '111': 510}
"""
if seed is not None:
np.random.seed(seed)
rng = np.random.default_rng(seed)

n = infer_size(p, phys_dim)
d = phys_dim**n
Expand All @@ -372,7 +371,7 @@ def simulate_counts(p, C, phys_dim=2, seed=None):
pi = pi.reshape(-1)

# raw counts in terms of integers
raw_counts = np.random.choice(np.arange(d), size=C, p=pi)
raw_counts = rng.choice(d, size=C, p=pi)

# convert to frequencies of binary
bin_str = "{:0>" + str(n) + "b}"
Expand Down
21 changes: 21 additions & 0 deletions quimb/schematic.py
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,9 @@ def marker(self, coo, preset=None, **kwargs):
coo, preset=preset, n=n, orientation=orientation, **style
)

def square(self, coo, preset=None, **kwargs):
return self.marker(coo, preset=preset, marker="s", **kwargs)

Check warning on line 434 in quimb/schematic.py

View check run for this annotation

Codecov / codecov/patch

quimb/schematic.py#L433-L434

Added lines #L433 - L434 were not covered by tests

def cube(self, coo, preset=None, **kwargs):
"""Draw a cube at the specified coordinate, which must be 3D.
Expand Down Expand Up @@ -825,6 +828,24 @@ def shape(self, coos, preset=None, **kwargs):
for coo in coos:
self._adjust_lims(*coo)

def rectangle(self, cooa, coob, preset=None, **kwargs):
style = parse_style_preset(self.presets, preset, **kwargs)
radius = style.pop("radius", 0.25)

Check warning on line 833 in quimb/schematic.py

View check run for this annotation

Codecov / codecov/patch

quimb/schematic.py#L831-L833

Added lines #L831 - L833 were not covered by tests

forward, inverse = get_rotator_and_inverse(cooa, coob)

Check warning on line 835 in quimb/schematic.py

View check run for this annotation

Codecov / codecov/patch

quimb/schematic.py#L835

Added line #L835 was not covered by tests

# rotate both onto y=0
xa, _ = forward(*cooa)
xb, _ = forward(*coob)
points = [

Check warning on line 840 in quimb/schematic.py

View check run for this annotation

Codecov / codecov/patch

quimb/schematic.py#L838-L840

Added lines #L838 - L840 were not covered by tests
(xa - radius, -radius),
(xa - radius, +radius),
(xb + radius, +radius),
(xb + radius, -radius),
]
points = [inverse(*coo) for coo in points]
self.shape(points, **style)

Check warning on line 847 in quimb/schematic.py

View check run for this annotation

Codecov / codecov/patch

quimb/schematic.py#L846-L847

Added lines #L846 - L847 were not covered by tests

def patch(self, coos, preset=None, **kwargs):
"""Draw a closed smooth patch through given coordinates.
Expand Down
2 changes: 2 additions & 0 deletions quimb/tensor/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
Gate,
)
from .circuit_gen import (
circ_a2a_rand,
circ_ansatz_1D_brickwork,
circ_ansatz_1D_rand,
circ_ansatz_1D_zigzag,
Expand Down Expand Up @@ -222,6 +223,7 @@
"array_contract",
"bonds_size",
"bonds",
"circ_a2a_rand",
"circ_ansatz_1D_brickwork",
"circ_ansatz_1D_rand",
"circ_ansatz_1D_zigzag",
Expand Down
Loading

0 comments on commit d57eb53

Please sign in to comment.