do the layerwise sampling as in the paper

This commit is contained in:
Noa Aarts 2026-01-14 14:52:18 +01:00
parent 0865fddcb5
commit 238caf645b
Signed by: noa
GPG key ID: 1850932741EFF672

View file

@ -261,24 +261,21 @@ def sample_circuit(rng: random.Random, qubits: int, depth: int) -> QuantumCircui
for _ in range(depth): for _ in range(depth):
if total_single + total_double >= 36: if total_single + total_double >= 36:
break break
gate_type_offset = 3 if rng.random() < TWO_QUBIT_GATE_PROBABILITY else 0
gate_type = rng.randint(1, 3)
gate_locations = even if rng.random() < 0.5 else odd gate_locations = even if rng.random() < 0.5 else odd
if gate_type_offset == 0: layer = []
gates.append( for loc in gate_locations:
[Gate(GateType(gate_type), x, params) for (x, _) in gate_locations] gate_type = rng.randint(1, 6)
) if gate_type >= 4:
total_single += len(gate_locations) if loc[1] == qubits:
continue
layer.append(Gate(GateType(gate_type), loc, params))
total_double += 1
else: else:
gates.append( layer.append(Gate(GateType(gate_type), loc[0], params))
[ total_single += 1
Gate(GateType(gate_type + gate_type_offset), xy, params) gates.append(layer)
for xy in gate_locations
if xy[1] != qubits
]
)
total_double += len(gate_locations)
params += 1 params += 1
return QuantumCircuit(qubits, gates, total_single, total_double, params) return QuantumCircuit(qubits, gates, total_single, total_double, params)