From 066543df760921036cb4ad366bcc63aa8c5c7650 Mon Sep 17 00:00:00 2001 From: meandmytram Date: Thu, 18 Apr 2024 15:59:16 -0400 Subject: [PATCH] formatting --- examples/decoding/classical.py | 27 ++++++++++++++++-------- examples/decoding/classical_ldpc.ipynb | 4 +++- examples/random_circuit/mps-rand-circ.py | 4 +++- 3 files changed, 24 insertions(+), 11 deletions(-) diff --git a/examples/decoding/classical.py b/examples/decoding/classical.py index 30ae405a..8ccbc0b6 100644 --- a/examples/decoding/classical.py +++ b/examples/decoding/classical.py @@ -9,15 +9,18 @@ from scipy.stats import unitary_group # Setup logging -logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s') +logging.basicConfig( + level=logging.INFO, format="%(asctime)s - %(levelname)s - %(message)s" +) # Append paths using environment variables or hardcoded fallbacks project_root = os.getenv( - 'MDOPT_PATH', '/home/bereza/projects/def-ko1/bereza/project-mdopt/mdopt' - ) + "MDOPT_PATH", "/home/bereza/projects/def-ko1/bereza/project-mdopt/mdopt" +) examples_path = os.getenv( - 'MDOPT_EXAMPLES_PATH', '/home/bereza/projects/def-ko1/bereza/project-mdopt/mdopt/examples' - ) + "MDOPT_EXAMPLES_PATH", + "/home/bereza/projects/def-ko1/bereza/project-mdopt/mdopt/examples", +) sys.path.append(project_root) sys.path.append(examples_path) @@ -40,7 +43,9 @@ decode_linear, ) except ImportError as e: - logging.error("Failed to import required modules. Ensure paths are correct.", exc_info=True) + logging.error( + "Failed to import required modules. Ensure paths are correct.", exc_info=True + ) sys.exit(1) NUM_EXPERIMENTS = 100 @@ -61,7 +66,7 @@ for PROB_ERROR in tqdm(error_rates): logging.info( f"Starting experiments for NUM_BITS={NUM_BITS}, CHI_MAX={CHI_MAX_CONTRACTOR}, PROB_ERROR={PROB_ERROR}" - ) + ) failures = [] for l in range(NUM_EXPERIMENTS): @@ -129,6 +134,10 @@ failures.append(1 - success) failures_statistics[(NUM_BITS, CHI_MAX_CONTRACTOR, PROB_ERROR)] = failures - failures_key = f"numbits{NUM_BITS}_bonddim{CHI_MAX_CONTRACTOR}_errorprob{PROB_ERROR}" + failures_key = ( + f"numbits{NUM_BITS}_bonddim{CHI_MAX_CONTRACTOR}_errorprob{PROB_ERROR}" + ) np.save(f"data/{failures_key}.npy", failures) - logging.info(f"Completed experiments for {failures_key} with {np.mean(failures)*100:.2f}% failure rate.") + logging.info( + f"Completed experiments for {failures_key} with {np.mean(failures)*100:.2f}% failure rate." + ) diff --git a/examples/decoding/classical_ldpc.ipynb b/examples/decoding/classical_ldpc.ipynb index c0468616..79282fdb 100644 --- a/examples/decoding/classical_ldpc.ipynb +++ b/examples/decoding/classical_ldpc.ipynb @@ -836,7 +836,9 @@ " failures.append(1 - success)\n", "\n", " failures_statistics[NUM_BITS, CHI_MAX_CONTRACTOR, PROB_ERROR] = failures\n", - " failures_key = f\"numbits{NUM_BITS}_bonddim{CHI_MAX_CONTRACTOR}_errorprob{PROB_ERROR}\"\n", + " failures_key = (\n", + " f\"numbits{NUM_BITS}_bonddim{CHI_MAX_CONTRACTOR}_errorprob{PROB_ERROR}\"\n", + " )\n", " np.save(f\"data/{failures_key}.npy\", failures)" ] } diff --git a/examples/random_circuit/mps-rand-circ.py b/examples/random_circuit/mps-rand-circ.py index 5f42b8e0..a1d2880c 100644 --- a/examples/random_circuit/mps-rand-circ.py +++ b/examples/random_circuit/mps-rand-circ.py @@ -78,7 +78,9 @@ fidels = [1 - error for error in errors] tails_iter.append(np.prod(fidels)) - tails_key = f"numqubits{NUM_QUBITS}_bonddim{BOND_DIM}_circlayers{NUM_LAYERS_CIRC}" + tails_key = ( + f"numqubits{NUM_QUBITS}_bonddim{BOND_DIM}_circlayers{NUM_LAYERS_CIRC}" + ) tails[tails_key] = tails_iter np.save(f"data/{tails_key}.npy", tails)