Add conditional homodyne measurement#33
Merged
sansiro77 merged 17 commits intoTuringQ:mainfrom Aug 29, 2024
Merged
Conversation
…partial measurement performed
…nd the reverse operation.
…rary angle homodyne measurement
Contributor
|
可以参考我这个函数去简化一下forward函数。应该是不需要置换函数的,甚至连xxpp和xpxp之间的转换都不用。 from torch.distributions.multivariate_normal import MultivariateNormal
def measure_dyne(cov, mean, idx, eps):
nmode = cov.shape[-1] // 2
cov_m = torch.diag(torch.tensor([eps**2, 1.0 / eps**2] * (len(idx) // 2)))
idx_rest = np.delete(np.arange(2 * nmode), idx)
cov_a = cov[idx_rest][:, idx_rest]
cov_b = cov[idx][:, idx]
cov_ab = cov[idx_rest][:, idx]
mean_a = mean[idx_rest]
mean_b = mean[idx]
mean_m = MultivariateNormal(mean_b, cov_b + cov_m).sample([1])[0]
cov_out = cov_a - cov_ab @ torch.linalg.inv(cov_b + cov_m) @ cov_ab.mT
mean_out = mean_a + cov_ab @ torch.linalg.inv(cov_b + cov_m) @ (mean_m - mean_b)
return cov_out, mean_out, mean_m |
sansiro77
reviewed
Aug 27, 2024
Contributor
sansiro77
left a comment
There was a problem hiding this comment.
目前这个Homodyne没有相关的指定shots的功能。我的想法是Homodyne的forward只返回[cov, mean],用self.samples去记录采样结果。其实输入的cov如果是(batch*shots, 2n, 2n),Homodyne就已经处理了shots不为1的情况。
QumodeCircuit里的self.state只记录operators的结果,self.measurements的输出赋值给临时变量或者记录为self.state_measured之类的,并且把计算过程放到measure_homodyne里,自动判断或者加个参数来判断执行ideal还是conditional Homodyne。
Generaldyne和Homodyne继承自Operation就可以了,放到新文件measurement.py里更清楚。
sansiro77
reviewed
Aug 27, 2024
sansiro77
reviewed
Aug 29, 2024
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Update details
circ.homodyneif the circuits don't contain
homodyne,circuit.measure_homodynestill works, but with the idealmultinormal distribution sampling.