question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

The problem

There is a need to support unrolling to a broader set of gate basis (see #3086). Additionally, supporting multiple decompositions are growing (see #3067).

Use cases

Our unrolling mechanism should support the following situations:

  • UC1 “circular” decompositions: should be able to handle situations like CX -> Rxx -> CX.
  • UC2 Decomposition to unitary: If the basis supports unitary and there is no further possible decomposition for a gate that is not in the basis, the gate should be transformed to unitary.
  • UC3 Consider the cost of synthesis: The unitary -> U transformation is particularly expensive. While it should be possible, unrolling should consider that cost.
  • UC4 A user should be able to add a new possible decomposition for a gate or to choose which decomposition should be used.

Optional features

It would be nice to also support the following situations:

  • OF1 @chriseclectic requires some gates to be reduced to unitary, even when they are in the basis. Currently, this is solved with labels.
basis: [h, unitary]
--[h]--[h]--   =>  --[unitary]--[h]--

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:7 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
1ucian0commented, Sep 28, 2019

Proposal: multiple prioritized decompositions

Supporting multiple possible decomposition per gate might allow to signal the unroller on how to unroll each gate until the basis gate set is reached. The decompositions are sorted by preference. ie, in cx: [{h, cz}, {rxx}, {unitary}], cx will be decomposed as {h, cz} before trying {rxx}.

Consider the coming examples using the following decomposition rules:

cx: [{h, cz}, {rxx}, {unitary}]
rxx: [{cx}, {unitary}]
cz: [{h, cx}, {unitary}]
h: [{u}, {unitary}]
u: [{unitary}]
unitary: [{u}]  # via synthesis

cuasi-implementation:

def decompose(gate, basis, visited=None):
    if gate in basis:
        return [gate]

    if visited is None:
        visited = set()

    if gate in visited:
        return [None]  # No decomposition was found on this branch

    visited.add(gate)  #avoids inf loops

    decompositions = decompositions_db[gate]
    for decomposition in decompositions:
        candidate = []
        for subgate in decomposition:
            candidate.append(decompose(subgate, basis, visited))
        if None not in candidate:  # is it a valid decomposition?
            return candidate  # once a valid decomposition is found, return it.
    return None  # no decomposition was found

for gate in circuit:
    circuit.replace(gate, decompose(gate, basis))  #replaces gate with its decomposition
  • The visited set avoids infinite recursion (UC1).
  • If a particular gate instance prefers a particular decomposition over another one, it needs to reorder its decompositions property to express the new priority order (UC4 OF1)
  • By default, unitary is the lowest priority for all the gates (except unitary) (UC2)
  • Synthesis is only considered (by default) if the circuit has a unitary and the basis has u (UC3).

To implement this proposal:

  • .definition can be removed.
  • decompositions is a list of DAGs.
  • DAGs should provide a way to know “its basis” i.e. the gates that are used in the DAG.
  • A mechanism to rearrange and add decompositions is needed.

Problems:

  • When there are more than one possible decompositions, it’s not defined which is prefered. For example, cx can be decomposed to the basis {rxx, u} as cx->[h, cz]->[[u], [u]] or cx->rxx. This can be fixed by first constructing the decomposition tree and then analyzing it to search for the shortest path (to improve the efficiency of the unroller) or the shortest result (to improve the depth of the resulting circuit).

Footnotes: [1] Since order of the gates and repetition can be ignored to the purpose of the problem, the examples are in terms of set. However, this does not implies that the possible implementation should.

0reactions
shaimachcommented, Oct 3, 2019

IMHO, gate mapping is an arbitrary directed graph: one may specify multiple decompositions per gate, and loops are allowed.

The backend defines the set of physically implemented gates (or in case of a simulator, all of them), which then allows the graph to be transformed into a DAG via Breadth-first search (BFS) from the physical gates.

This way we separate gate mappings from the physical basis set.

Read more comments on GitHub >

github_iconTop Results From Across the Web

[RFC] Heuristics to throttle the complette unrolling
This patch reduces unrolling on loops having many branches or calls on the > > hot patch. I found that for applu speedup...
Read more >
[LLVMdev] [RFC] Heuristic for complete loop unrolling
[LLVMdev] [RFC] Heuristic for complete loop unrolling. Hal Finkel hfinkel at anl.gov. Sat Jan 24 06:25:19 PST 2015. Previous message: [LLVMdev] [RFC] ...
Read more >
Offer attributes for controlling loop optimizations #2219 - GitHub
For example, Clang has #pragma loop which allow the programmer to guide loop unrolling, vectorization, and other optimizations.
Read more >
RFC 6234: US Secure Hash Algorithms (SHA and SHA-based ...
As with RFC 4634, code to perform SHA-based Hashed Message Authentication ... as a cycle and the loop unrolled, rather than doing the...
Read more >
RFC 302 (v1) Unrolling loops and tail recursion - nntp.perl.org
This and other RFCs are available on the web at http://dev.perl.org/rfc/ =head1 TITLE Unrolling loops and tail recursion =head1 VERSION Maintainer: Simon ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found