Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/qc_compiler/batching.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
same device, maximizing qubit utilization.
"""

import hashlib
from dataclasses import dataclass, field

from qiskit import QuantumCircuit
Expand Down Expand Up @@ -302,7 +303,7 @@ def _compute_core_hash(self, circuit: QuantumCircuit) -> int:
)
core_gates.append((gate_name, qubits, params))

return hash(tuple(core_gates))
return int(hashlib.sha256(str(tuple(core_gates)).encode()).hexdigest(), 16)

def _detect_measurement_basis(
self, circuit: QuantumCircuit
Expand Down
26 changes: 25 additions & 1 deletion tests/test_batching.py
Original file line number Diff line number Diff line change
Expand Up @@ -352,4 +352,28 @@ def test_circuits_exceeding_device_capacity_split_into_batches(self):
qc.cx(0, 1)
plan = batcher.create_batch_plan(circuits, strategy="structural")
assert plan.total_circuits == 4
assert plan.num_batches >= 2
assert plan.num_batches >= 2


class TestDeterministicCoreHash:
"""Regression test for deterministic hashing (issue #51)."""

def test_core_hash_is_deterministic_across_calls(self):
batcher = CircuitBatcher(cost_model=CostModel())
qc = QuantumCircuit(2)
qc.h(0)
qc.cx(0, 1)
hash1 = batcher._compute_core_hash(qc)
hash2 = batcher._compute_core_hash(qc)
assert hash1 == hash2

def test_core_hash_differs_for_different_circuits(self):
batcher = CircuitBatcher(cost_model=CostModel())
qc1 = QuantumCircuit(2)
qc1.h(0)
qc1.cx(0, 1)
qc2 = QuantumCircuit(2)
qc2.x(0)
hash1 = batcher._compute_core_hash(qc1)
hash2 = batcher._compute_core_hash(qc2)
assert hash1 != hash2
Loading