Skip to content

Support shots for expectation value#72

Merged
sansiro77 merged 4 commits intoTuringQ:mainfrom
sansiro77:dev-hjj
Jan 22, 2025
Merged

Support shots for expectation value#72
sansiro77 merged 4 commits intoTuringQ:mainfrom
sansiro77:dev-hjj

Conversation

@sansiro77
Copy link
Contributor

  • shots can be set via initialization, measure, and expectation.
  • If expectation specifies shots, the estimated value obtained by sampling will be returned.
    For example:
data = torch.randn(4)
cir = dq.QubitCircuit(4, shots=2048)
cir.rylayer(encode=True)
cir.cnot_ring()
cir.rxlayer()
cir.observable(0, 'y')
cir.observable([0,1], 'xy')
cir.observable([0,1,3], 'xyz')
state = cir.amplitude_encoding(torch.randn(2**4))
cir(data=data, state=state)
# cir(data)
print(cir.shots)
print(cir.measure())
print(cir.expectation())
print(cir.expectation(shots=10000))
print(cir.shots)

@sansiro77 sansiro77 requested review from Hugh-888 and Jooyuza January 20, 2025 03:11
@sansiro77 sansiro77 self-assigned this Jan 20, 2025
@sansiro77 sansiro77 added the enhancement New feature or request label Jan 20, 2025
@sansiro77 sansiro77 merged commit 3cdc2f2 into TuringQ:main Jan 22, 2025
@sansiro77 sansiro77 deleted the dev-hjj branch January 26, 2025 12:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants