Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New Technique: Equivalent Circuit Averaging #2265

Open
natestemen opened this issue Apr 3, 2024 · 1 comment
Open

New Technique: Equivalent Circuit Averaging #2265

natestemen opened this issue Apr 3, 2024 · 1 comment
Assignees
Labels
needs/agreed-design Needs a plan of action that is agreed upon to complete. new technique For proposed new techniques

Comments

@natestemen
Copy link
Member

Background

Equivalent Circuit Averaging (ECA) is a quantum error mitigation technique introduced in Optimized SWAP networks with equivalent circuit averaging for QAOA as a technique which

randomizes over degrees of freedom in the quantum circuit compilation to reduce the impact of systematic coherent errors.

Crucially, this technique relies on having a compiler that is able to take into account those degrees of freedom. Last year, @edyounis (lead developer of BQSKit) approached us with the idea of adding this as a technique in Mitiq, using the BQSKit compiler as the tool to do this. Ed helped us write some basic code to prototype what this could look like, and it's demonstrated in this notebook. When reviewing the code together this week and discussing the fact that it currently runs quite slowly, Ed noted that there are a myriad of ways to speed it up by not asking for a full compilation pass. @edyounis, can you provide some more details on how we might go about speeding this up?

Implementation

There's (at least) one big decision we have to make when thinking about the design and implementation of this technique and that's answering the question do we expect the user to have compiled the circuit for their desired backend before performing ECA?

Option 1: compilation in the executor

First, the way in which we normally ask users to engage with Mitiq by just handing us their circuit of interest and operating on that. Here, we are generally agnostic to whether the circuit has been pre-compiled for a specific backend or not, but there are times when we might potentially add in gates that could be outside the compiled gateset (e.g. dynamical decoupling inserting $XX$ or $XYXY$ gate sequences).

sequenceDiagram
    autonumber
    actor Programmer
    Programmer->>Mitiq: Quantum circuit
    Mitiq->>Executor: ECA circuits
    Note right of Mitiq: using BQSKit
    Executor->>Executor: compile (for specific backend)
    Executor->>Mitiq: expectation values
    Mitiq->>Programmer: average expectation value
Loading

Option 2: compilation ahead of ECA

The second possible workflow requires that the user compile their circuit before passing it to Mitiq. Ed mentioned their might be benefits to this approach, as having a shorter, compiled circuit, would make the ECA process even quicker. Ed if there are more details here as to why this approach might be advantageous, please do add!

It is possible to imagine Mitiq subsumes the "Compile" step in the diagram below, but allowing the user to pass a device topology and gateset for "Mitiq" to compile with (using BQSKit) before starting the ECA process.

sequenceDiagram
    autonumber
    actor Programmer
    Programmer->>Compile: Quantum circuit 
    Compile->>Mitiq: compiled circuit
    Mitiq->>Executor: ECA circuits
    Note right of Mitiq: using BQSKit
    Executor->>Mitiq: expectation values
    Mitiq->>Programmer: average expectation value
Loading

Existing implementations

Infleqtion has implemented ECA as part of superstaq's aqt_compile function.

@natestemen natestemen self-assigned this Apr 3, 2024
@natestemen natestemen added the needs/agreed-design Needs a plan of action that is agreed upon to complete. label Apr 3, 2024
@edyounis
Copy link

edyounis commented Apr 5, 2024

can you provide some more details on how we might go about speeding this up?

Sure. I think starting with a simple resynthesis workflow with different seeds is a good place to start.

from bqskit.compiler import Compiler
from bqskit.passes import SetRandomSeedPass
from bqskit.passes import QuickPartitioner
from bqskit.passes import ForEachBlockPass
from bqskit.passes import QSearchSynthesisPass
from bqskit.passes import UnfoldPass

num_eca_circuits = ...

bqskit_circuit = ...

workflow = [
    QuickPartitioner(3),
    ForEachBlockPass(
        QSearchSynthesisPass(),
        replace_filter = "less-than-multi",
    ),
    UnfoldPass()
]

eca_circuits = []

with Compiler() as compiler:
    for i in range(num_eca_circuits): # maybe randomize i?
        seeded_workflow = [SetRandomSeedPass(i)] + workflow
        eca_circuit = compiler.compile(bqskit_circuit, seeded_workflow)
        eca_circuits.append(eca_circuit)

If needed, there are still ways to improve performance and quality, where structural differences in the ECA circuits measure quality. There will likely be some trade-offs to explore for this use case.

Both options for an ECA workflow with BQSKit will work. I am not 100% sure, but I do think that operating after compilation will produce results faster, while operating before compilation will produce more variety. One important note about the previous code, is that the compilation will not respect circuit topology or gate set. So running it after compilation may make it unexecutable given a specific backend. If you would like to instruct it to maintain both topology and gateset of a given hardware, we can build a MachineModel and use the SetModelPass to start the workflow.

@natestemen natestemen added the new technique For proposed new techniques label Apr 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs/agreed-design Needs a plan of action that is agreed upon to complete. new technique For proposed new techniques
Projects
None yet
Development

No branches or pull requests

2 participants