4
.gitmodules
vendido
Archivo normal
4
.gitmodules
vendido
Archivo normal
@@ -0,0 +1,4 @@
|
||||
[submodule "HDH"]
|
||||
path = HDH
|
||||
url = https://github.com/manalejandro/HDH
|
||||
branch = database-branch
|
||||
@@ -52,9 +52,6 @@ WORKDIR /app
|
||||
# Copy application files
|
||||
COPY . .
|
||||
|
||||
# Copy HDH library (assuming it's in the parent directory)
|
||||
COPY ../HDH ./HDH
|
||||
|
||||
# Install HDH library
|
||||
RUN pip install -e ./HDH
|
||||
|
||||
|
||||
1
HDH
Submódulo
1
HDH
Submódulo
Submodule HDH added at e84b7d9d8c
@@ -56,7 +56,7 @@ source hdh-env/bin/activate # On Windows: hdh-env\Scripts\activate
|
||||
pip install -r requirements.txt
|
||||
|
||||
# Install HDH library in development mode
|
||||
pip install -e ../HDH
|
||||
pip install -e ./HDH
|
||||
|
||||
# Verify installation
|
||||
python main.py --help
|
||||
|
||||
36
benchmark.py
36
benchmark.py
@@ -37,7 +37,8 @@ import numpy as np
|
||||
# Memory and performance monitoring
|
||||
import psutil
|
||||
import gc
|
||||
from memory_profiler import profile
|
||||
import tracemalloc
|
||||
from memory_profiler import profile, memory_usage
|
||||
|
||||
# Add HDH to path
|
||||
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..', 'HDH')))
|
||||
@@ -118,17 +119,34 @@ class HDHBenchmarkSuite:
|
||||
|
||||
# Initial memory measurement
|
||||
gc.collect() # Force garbage collection
|
||||
|
||||
# Start memory tracking with tracemalloc
|
||||
tracemalloc.start()
|
||||
initial_snapshot = tracemalloc.take_snapshot()
|
||||
initial_memory = self.get_memory_usage()
|
||||
|
||||
try:
|
||||
# Time the conversion
|
||||
# Time the conversion and track memory
|
||||
start_time = time.perf_counter()
|
||||
hdh = from_qiskit(circuit)
|
||||
conversion_time = time.perf_counter() - start_time
|
||||
|
||||
# Memory peak measurement
|
||||
# Memory peak measurement using tracemalloc
|
||||
current_snapshot = tracemalloc.take_snapshot()
|
||||
top_stats = current_snapshot.compare_to(initial_snapshot, 'lineno')
|
||||
|
||||
# Calculate memory difference in MB
|
||||
tracemalloc_memory = sum(stat.size_diff for stat in top_stats) / 1024 / 1024
|
||||
|
||||
# Also get psutil measurement as backup
|
||||
peak_memory = self.get_memory_usage()
|
||||
memory_used = peak_memory - initial_memory
|
||||
psutil_memory = peak_memory - initial_memory
|
||||
|
||||
# Use the larger of the two measurements (tracemalloc is usually more accurate)
|
||||
memory_used = max(abs(tracemalloc_memory), abs(psutil_memory))
|
||||
|
||||
# Stop tracemalloc
|
||||
tracemalloc.stop()
|
||||
|
||||
# HDH statistics
|
||||
hdh_nodes = len(hdh.S)
|
||||
@@ -142,8 +160,12 @@ class HDHBenchmarkSuite:
|
||||
if hdh_nodes > 1:
|
||||
try:
|
||||
num_parts = min(3, max(2, hdh_nodes // 2))
|
||||
# Calculate capacity: distribute qubits evenly across partitions with some buffer
|
||||
num_qubits = circuit.num_qubits
|
||||
capacity = max(1, (num_qubits + num_parts - 1) // num_parts + 1) # Ceiling division + buffer
|
||||
|
||||
start_partition = time.perf_counter()
|
||||
partitions = compute_cut(hdh, num_parts)
|
||||
partitions, _ = compute_cut(hdh, num_parts, capacity)
|
||||
partitioning_time = time.perf_counter() - start_partition
|
||||
partition_cost = cost(hdh, partitions)
|
||||
except Exception as e:
|
||||
@@ -177,6 +199,10 @@ class HDHBenchmarkSuite:
|
||||
)
|
||||
|
||||
except Exception as e:
|
||||
# Make sure to stop tracemalloc even on error
|
||||
if tracemalloc.is_tracing():
|
||||
tracemalloc.stop()
|
||||
|
||||
self.logger.error(f"Benchmark failed for {circuit_name}: {str(e)}")
|
||||
self.logger.debug(traceback.format_exc())
|
||||
|
||||
|
||||
@@ -28,8 +28,7 @@ sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..',
|
||||
|
||||
from qiskit import QuantumCircuit, QuantumRegister, ClassicalRegister
|
||||
from qiskit.circuit.library import (
|
||||
QFT, GroverOperator, DeutschJozsaOracle,
|
||||
TwoLocal, RealAmplitudes, EfficientSU2
|
||||
QFT, TwoLocal, RealAmplitudes, EfficientSU2
|
||||
)
|
||||
from qiskit.circuit import Parameter
|
||||
import qiskit.circuit.library as qlib
|
||||
|
||||
Referencia en una nueva incidencia
Block a user