Closed king-p3nguin closed 3 months ago
Hi @AbdullahKazi500, I modified your code to calculate the correct entanglement entropy and support mid-circuit measurement correctly, and I would not mind splitting the bounty with you. Please let me know what you think.
Hi @king-p3nguin I appreciate that you informed me and I am happy that you were able to solve it with my code @refraction-ray we can split the bounty I am happy with that, and any decision taken by the organizer thank you once again
Thanks for the contribution, the PR now looks better. However, I can still find the inconsistence of the entropy calculation with num_qubits = 10, depth = 6
, where stim gives EE value 0 while tc gives 0.693. Could you debug the issue of this inconsistency? It would also be better to generalize the code a bit to support any partition for EE calculation instead of half chain now as num_qubits//2
Attached is the circuit yielding inconsistent results
Hi @refraction-ray and @king-p3nguin I have updated the code here Stim Entropy in the new patch I have got the results Stim Entanglement Entropy: 0.6931471805599453 TensorCircuit Entanglement Entropy: 0.6931471813752873
The cut variable is used to define the partition size and can be adjusted as needed. The get_bipartite_binary_matrix function is updated to take cut as a parameter. Ensured that postselection logic is correctly applied in both TensorCircuit and Stim. The simulate_stim_circuit_with_mid_measurement function now correctly handles postselections.
@refraction-ray I was able to fix the bug in the example. I have tested the code with num_qubits = 10
, depth=1~30
, cut = [i for i in range(num_qubits // 3)]
.
np.isclose()
is used to check the probability since even if the probability is close to 1.0, p < 1.0
can be True
due to floating-point error.Thanks for your contribution. I'll assign the issue to both of you first and then further testing the code :)
all the mid-circuit measurements are pushed to the end of the circuit, so I just created a list of operations
That's why we need c.measurement_instruction()
for each mid-circuit measurement to record, and merge_qir
to ensure the order of gates and mid-circuit measurements
@all-contributors please add @AbdullahKazi500 for example
@refraction-ray
I've put up a pull request to add @AbdullahKazi500! :tada:
Resolve #211
How the example works:
Output: