Skip to content

Allow caching subcircuits - #470

Draft
ohuettenhofer wants to merge 2 commits into
develfrom
circuits_as_gates
Draft

Allow caching subcircuits#470
ohuettenhofer wants to merge 2 commits into
develfrom
circuits_as_gates

Conversation

@ohuettenhofer

Copy link
Copy Markdown
Collaborator

This adds the cached_subcircuit function which converts a QCircuit object to a SubcircuitGate object.
When this is added to another circuit, it is treated like a gate (unlike a normal circuit where all the gates are appended directly to the existing gates, and there's no subcircuit). This means that it only needs to be compiled once, and should also save some memory.

This is currently a very simple implementation that only caches the Tequila Compilation, nothing backend specific, but it can already speed up circuit Compilation significantly:

The following code takes me around 10 seconds to run:

import time
import tequila as tq
from tequila import CircuitCompiler
from tequila.circuit.gates import cached_subcircuit

subcircuit = tq.QCircuit()
for i in range(10):
    subcircuit += tq.gates.Ry(angle=i, target=0)

circuit = tq.QCircuit()
for i in range(100):
    circuit += subcircuit

start = time.time()
compiled = CircuitCompiler.error_correctable_gate_set(1e-6).compile_circuit(circuit)
print(f"Compilation time: {time.time() - start} s")

Replacing circuit += subcircuit with circuit += cached_subcircuit(subcircuit) decreases this time to ~0.7 seconds, while (in theory) being functionally equivalent.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant