• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

feihoo87 / waveforms / 6893865468

16 Nov 2023 04:49PM UTC coverage: 43.147% (+0.7%) from 42.467%
6893865468

push

github

feihoo87
update

7 of 17 new or added lines in 4 files covered. (41.18%)

588 existing lines in 10 files now uncovered.

7436 of 17234 relevant lines covered (43.15%)

3.87 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/waveforms/quantum/rb.py
1
import random
×
2

3
import numpy as np
×
4

5
from waveforms.qlisp.simulator.simple import seq2mat
×
6

7
from .clifford import cliffordOrder
×
UNCOV
8
from .clifford.clifford import (generateTwoQubitCliffordSequence, inv,
×
9
                                mat2index, mul)
UNCOV
10
from .clifford.seq2mat import seq2qlisp
×
11

UNCOV
12
_index2seq = [[seq] for seq in generateTwoQubitCliffordSequence()]
×
13

UNCOV
14
from ..qlisp import mapping_qubits
×
15

16

17
def circuit_to_index(circuit: list) -> int:
×
18
    if not circuit:
×
19
        return 0
×
20
    mat = seq2mat(circuit)
×
21
    if mat.shape[0] == 2:
×
22
        mat = np.kron(np.eye(2), mat)
×
UNCOV
23
    return mat2index(mat)
×
24

25

26
def index_to_circuit(index: int, qubits=(0, ), base=None, rng=None) -> list:
×
27
    if len(qubits) > 2:
×
28
        raise ValueError('Only support 1 or 2 qubits')
×
29
    if rng is None:
×
30
        rng = random.Random()
×
31
    if base is None:
×
32
        base = _index2seq
×
33
    seq = rng.choice(base[index])
×
34
    if len(qubits) == 1:
×
35
        seq = (seq[1], )
×
UNCOV
36
    return seq2qlisp(seq, range(len(qubits)))
×
37

38

UNCOV
39
def generateRBCircuit(qubits, cycle, seed=None, interleaves=[], base=None):
×
40
    """Generate a random Clifford RB circuit.
41

42
    Args:
43
        qubits (list): The qubits to use.
44
        cycle (int): The cycles of clifford sequence.
45
        seed (int): The seed for the random number generator.
46
        interleaves (list): The interleaves to use.
47
        base (list): The basic two-qubit Clifford sequence.
48

49
    Returns:
50
        list: The RB circuit.
51
    """
52
    if isinstance(qubits, (str, int)):
×
UNCOV
53
        qubits = {0: qubits}
×
54
    else:
UNCOV
55
        qubits = {i: q for i, q in enumerate(qubits)}
×
56

UNCOV
57
    MAX = cliffordOrder(len(qubits))
×
58

UNCOV
59
    interleaves_index = circuit_to_index(interleaves)
×
60

61
    ret = []
×
62
    index = 0
×
UNCOV
63
    rng = random.Random(seed)
×
64

65
    for _ in range(cycle):
×
66
        i = rng.randrange(MAX)
×
67
        index = mul(i, index)
×
68
        ret.extend(index_to_circuit(i, qubits, base, rng))
×
69
        index = mul(interleaves_index, index)
×
UNCOV
70
        ret.extend(interleaves)
×
71

UNCOV
72
    ret.extend(index_to_circuit(inv(index), qubits, base, rng))
×
73

UNCOV
74
    return mapping_qubits(ret, qubits)
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc