hongyehu / PyClifford

An intuitive programming package for simulating and analyzing Clifford circuits, quantum measurement, and stabilizer states with applications to many-body localization, classical shadows, quantum chemistry and error correction code.
https://hongyehu.github.io/PyCliffordPages/intro.html
BSD 3-Clause "New" or "Revised" License
75 stars 15 forks source link

feat: added vectorized expectation value computation for a batch of s… #20

Closed teng10 closed 1 year ago

teng10 commented 1 year ago

This is an implementation of vectorzied fuction to compute expectation values torchclifford.utils.stabilizer_expect() for multiple stabilizer states (see UnitaryFund issue here) using vmap PyTorch. Currently, the computation is not yet vmapped as the following block raises an error

# vmap currently blocked by issue: https://github.com/pytorch/pytorch/issues/103329
# vectorizable_stabilizer_expect_r = functools.partial(vectorizable_stabilizer_expect, r=r) # fix r
# batched_stabilizer_expect = torch.vmap(vectorizable_stabilizer_expect_r, in_dims=(0,0, None, None), out_dims=0)
# return batched_stabilizer_expect(gs_stb_batched, ps_stb_batched, gs_obs, ps_obs)    

This is because of a potential issue in PyTorch: https://github.com/pytorch/pytorch/issues/103329

natestemen commented 1 year ago

ping @hongyehu in case you haven't seen this.

hongyehu commented 1 year ago

ping @hongyehu in case you haven't seen this.

Hi Nate! I have seen this PR, and reviewing it. Many thanks!

hongyehu commented 1 year ago

New implementation of vectorized_batch_expectation, which enables parallel expectation value evaluation for single states. Future thinking: parallelization of states