SampledExpectation layer seems to recompute the same circuits for different measurement ops

Offen
#271 6 Kommentare 0 Reaktionen 1 zugewiesene Person Auf GitHub ansehen

Maintainer antworten meist innerhalb von 21 Tagen

@MichaelBroughton arbeitet bereits daran.

Seit 20.6.2020.

Bewertung

Dieses Issue wurde noch nicht bewertet.

Beschreibung

area/circuits area/docs kind/bug-report

Example

c = cirq.Circuit()
qubits = cirq.GridQubit.rect(2, 1)
c.append(cirq.rz(0.)(qubits[0]))
c.append(cirq.H(qubits[1]))
sampled_expectation_layer = tfq.layers.SampledExpectation()
output = sampled_expectation_layer(
    [c],
    operators=[cirq.Z(qubits[0]), cirq.Z(qubits[1]), cirq.Z(qubits[0]) * cirq.Z(qubits[1])],
    repetitions=1)
print(output) # we have [1, -1, 1] sometimes
assert output[0,0]*output[0,1] == output[0,2] # and this may fail

It is unnatural to me that, when repetitions=1 (1 sample), we have inconsistent measurement results between Z1, Z2 and Z1*Z2.

And from code here https://github.com/tensorflow/quantum/blob/db2eac4e598f614a8c0e157c56313a23ef1943fb/tensorflow_quantum/core/ops/batch_util.py#L554-L561, this may be due to that each circuit, batch, measurement ops combination is simulated separately on backends. If it is so, it is not only unnatural but also inefficient since one can measure all ops for one circuit simulation.

My understanding may be wrong somewhere, any ideas on this?

Vorherrschende Sprache
Python
Sterne
2.2k
Forks
675
Ø Merge
15 T. 11 Std.
Gemergte PRs (30 T.)
3

Entwicklungsumgebung

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus tensorflow/quantum

Alle Issues in tensorflow/quantum

Ähnliche Issues

Weitere Issues zu Python

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.