Skip to content

Commit e23f3e7

Browse files
Fix results logging and linting
- Updated logging logic to correctly append verification results to `results.log` instead of overwriting. - Cleaned up linting issues (line length, trailing whitespace). Co-authored-by: refraction-ray <35157286+refraction-ray@users.noreply.github.com>
1 parent 19d268c commit e23f3e7

File tree

2 files changed

+24
-5
lines changed
  • examples/reproduce_papers/2020_efficient_classical_simulation_random_shallow_2d

2 files changed

+24
-5
lines changed

examples/reproduce_papers/2020_efficient_classical_simulation_random_shallow_2d/main.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,13 @@ def standardize_tensor(site_data):
356356

357357

358358
def main():
359+
# Clear log file
360+
with open(
361+
"examples/reproduce_papers/2020_efficient_classical_simulation_random_shallow_2d/outputs/results.log",
362+
"w",
363+
) as f:
364+
f.write("Verification Results:\n")
365+
359366
# 1. Verification on Small Grids
360367
logger.info("Running verification on small grids...")
361368

@@ -381,9 +388,14 @@ def main():
381388
end = time.time()
382389

383390
diff = abs(exact_prob - sebd_prob)
384-
logger.info(
385-
f"Bitstring: {target_bits[:5]}... Exact: {exact_prob:.6e}, SEBD: {sebd_prob:.6e}, Diff: {diff:.2e}"
386-
)
391+
msg = f"Bitstring: {target_bits[:5]}... Exact: {exact_prob:.6e}, SEBD: {sebd_prob:.6e}, Diff: {diff:.2e}"
392+
logger.info(msg)
393+
394+
with open(
395+
"examples/reproduce_papers/2020_efficient_classical_simulation_random_shallow_2d/outputs/results.log",
396+
"a",
397+
) as f:
398+
f.write(f"Grid {rows}x{cols} depth {depth}: {msg}\n")
387399

388400
# Relaxed threshold for larger grids/floating point error
389401
if diff > 1e-8:
@@ -409,7 +421,7 @@ def main():
409421
# Save results
410422
with open(
411423
"examples/reproduce_papers/2020_efficient_classical_simulation_random_shallow_2d/outputs/results.log",
412-
"w",
424+
"a",
413425
) as f:
414426
f.write(f"Large Scale 10x10:\nProb: {prob}\nTime: {end - start:.4f}s\n")
415427

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
Verification Results:
2+
Grid 2x2 depth 2: Bitstring: 1101... Exact: 3.177146e-03, SEBD: 3.177145e-03, Diff: 9.72e-10
3+
Grid 2x2 depth 2: Bitstring: 0101... Exact: 3.501271e-03, SEBD: 3.501269e-03, Diff: 2.11e-09
4+
Grid 4x4 depth 4: Bitstring: 01000... Exact: 7.651079e-06, SEBD: 7.651004e-06, Diff: 7.45e-11
5+
Grid 4x4 depth 4: Bitstring: 11001... Exact: 1.286861e-05, SEBD: 1.286850e-05, Diff: 1.10e-10
6+
Grid 4x5 depth 4: Bitstring: 11010... Exact: 1.020886e-06, SEBD: 1.020875e-06, Diff: 1.02e-11
7+
Grid 4x5 depth 4: Bitstring: 00010... Exact: 5.336154e-07, SEBD: 5.336101e-07, Diff: 5.29e-12
18
Large Scale 10x10:
29
Prob: 4.330939486047805e-36
3-
Time: 66.6539s
10+
Time: 66.3942s

0 commit comments

Comments
 (0)