Join two state vectors into a larger qubit state
321087
def join_states(*states: State) -> State:
    """"""
    vectors = [ket.vec for ket in states]
    vec = reduce(outer_product, vectors)
    return State(vec.tensor, vec.qubits)
678516
def append_state(self, s, is_widened_state=False):
        

        if not is_widened_state:
            self.all_states.append(s)
            self.state = s

        else:
            self.widened_state = s
714193
private void ssMergeForward(int PA, int first, int middle, int last, int buf,
                                int depth) {
        // PA, first, middle, last, buf are pointers to SA
        int a, b, c, bufend;// pointers to SA
        int t, r;

        bufend = buf + (middle - first) - 1;
        ssBlockSwap(buf, first, middle - first);

        for (t = SA[a = first], b = buf, c = middle; ; ) {
            r = ssCompare(PA + SA[b], PA + SA[c], depth);
            if (r < 0) {
                do {
                    SA[a++] = SA[b];
                    if (bufend <= b) {
                        SA[bufend] = t;
                        return;
                    }
                    SA[b++] = SA[a];
                }
                while (SA[b] < 0);
            } else if (r > 0) {
                do {
                    SA[a++] = SA[c];
                    SA[c++] = SA[a];
                    if (last <= c) {
                        while (b < bufend) {
                            SA[a++] = SA[b];
                            SA[b++] = SA[a];
                        }
                        SA[a] = SA[b];
                        SA[b] = t;
                        return;
                    }
                }
                while (SA[c] < 0);
            } else {
                SA[c] = ~SA[c];
                do {
                    SA[a++] = SA[b];
                    if (bufend <= b) {
                        SA[bufend] = t;
                        return;
                    }
                    SA[b++] = SA[a];
                }
                while (SA[b] < 0);

                do {
                    SA[a++] = SA[c];
                    SA[c++] = SA[a];
                    if (last <= c) {
                        while (b < bufend) {
                            SA[a++] = SA[b];
                            SA[b++] = SA[a];
                        }
                        SA[a] = SA[b];
                        SA[b] = t;
                        return;
                    }
                }
                while (SA[c] < 0);
            }
        }

    }
96984
def set_io_qubits(qubit_count):
    """"""
    input_qubits = [cirq.GridQubit(i, 0) for i in range(qubit_count)]
    output_qubit = cirq.GridQubit(qubit_count, 0)
    return (input_qubits, output_qubit)
211908
def concat(self, one, two):
        """"""
        if not len(one) == len(two) == 6:
            raise ValueError("bad sequ. length")
        self.a, self.b, self.c, self.d, self.e, self.f = TOOLS._concat_matrix(one, two)
        return self
1074106
def permute(self, qubits: Qubits) -> 'Density':
        """"""
        vec = self.vec.permute(qubits)
        return Density(vec.tensor, vec.qubits, self._memory)
193402
def almost_identity(gate: Gate) -> bool:
    """"""
    N = gate.qubit_nb
    return np.allclose(asarray(gate.asoperator()), np.eye(2**N))
360033
def random_state(qubits: Union[int, Qubits]) -> State:
    """"""
    N, qubits = qubits_count_tuple(qubits)
    ket = np.random.normal(size=([2] * N)) \
        + 1j * np.random.normal(size=([2] * N))
    return State(ket, qubits).normalize()
92956
def make_oracle(input_qubits,
                output_qubit,
                secret_factor_bits,
                secret_bias_bit):
    """"""

    if secret_bias_bit:
        yield cirq.X(output_qubit)

    for qubit, bit in zip(input_qubits, secret_factor_bits):
        if bit:
            yield cirq.CNOT(qubit, output_qubit)
1254821
def _bulk_to_chimera(M, N, L, qubits):
    ""
    return [(q // N // L // 2, (q // L // 2) % N, (q // L) % 2, q % L) for q in qubits]
894364
def _split_sequences_singletraj(dtraj, nstates, lag):
    
    sall = [[] for _ in range(nstates)]
    res_states = []
    res_seqs = []

    for t in range(len(dtraj)-lag):
        sall[dtraj[t]].append(dtraj[t+lag])

    for i in range(nstates):
        if len(sall[i]) > 0:
            res_states.append(i)
            res_seqs.append(np.array(sall[i]))
    return res_states, res_seqs
801583
def xor_nonlocal_decompose(qubits: Iterable[raw_types.Qid],
                           onto_qubit: raw_types.Qid
                          ) -> Iterable[raw_types.Operation]:
    """"""
    for qubit in qubits:
        if qubit != onto_qubit:
            yield common_gates.CNOT(qubit, onto_qubit)
1828
def sZ(qubit: Qubit, coefficient: complex = 1.0) -> Pauli:
    """"""
    return Pauli.sigma(qubit, 'Z', coefficient)
1080395
def combine(self, a, b):
        """"""

        for l in (a, b):
            for x in l:
                yield x
1198415
def permute(self, qubits: Qubits) -> 'QubitVector':
        """"""

        if qubits == self.qubits:
            return self

        N = self.qubit_nb
        assert len(qubits) == N

        # Will raise a value error if qubits don't match
        indices = [self.qubits.index(q) for q in qubits]  # type: ignore
        perm: List[int] = []
        for rr in range(0, self.rank):
            perm += [rr * N + idx for idx in indices]
        tensor = bk.transpose(self.tensor, perm)

        return QubitVector(tensor, qubits)
409569
def p_state(self, state):
        ''''''
        state[0] = State(state[1][0], state[1][1], state[1][2], state[1][3], state[2])
376093
def kron(a, b):
    """"""
    if hasattr(a, '__kron__'):
        return a.__kron__(b)
    if a is None:
        return b
    else:
        raise ValueError(
            'Kron is waiting for two TT-vectors or two TT-matrices')