Return the all-zero state on N qubits
184586
def zero_state(qubits: Union[int, Qubits]) -> State:
    """"""
    N, qubits = qubits_count_tuple(qubits)
    ket = np.zeros(shape=[2] * N)
    ket[(0,) * N] = 1
    return State(ket, qubits)
405717
def IntGreaterThanZero(n):
    """"""
    try:
        n = int(n)
    except:
        raise ValueError("%s is not an integer" % n)
    if n <= 0:
        raise ValueError("%d is not > 0" % n)
    else:
        return n
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)
472599
def _run_gates(self, gates, n_qubits, ctx):
        """"""
        for gate in gates:
            action = self._get_action(gate)
            if action is not None:
                ctx = action(gate, ctx)
            else:
                ctx = self._run_gates(gate.fallback(n_qubits), n_qubits, ctx)
        return ctx
876339
def numpartition_qaoa(n_step, nums, minimizer=None, sampler=None):
    
    hamiltonian = pauli.Expr.zero()
    for i, x in enumerate(nums):
        hamiltonian += pauli.Z[i] * x
    hamiltonian = (hamiltonian ** 2).simplify()

    return vqe.Vqe(vqe.QaoaAnsatz(hamiltonian, n_step), minimizer, sampler)
40023
def sY(qubit: Qubit, coefficient: complex = 1.0) -> Pauli:
    """"""
    return Pauli.sigma(qubit, 'Y', coefficient)
1252699
def get_measure_probabilities(wf, qubit):
    
    n_qubits = len(wf.shape)
    all_inds = list(range(n_qubits))

    return np.einsum(np.conj(wf), all_inds,
                     wf, all_inds,
                     [int(qubit)])
469595
def su(self) -> 'Gate':
        """"""
        rank = 2**self.qubit_nb
        U = asarray(self.asoperator())
        U /= np.linalg.det(U) ** (1/rank)
        return Gate(tensor=U, qubits=self.qubits)
726735
function uniqStates(states) {
    var seen = {}, a = [], path, i, n;

    for (i = 0, n = states.length; i < n; i++) {
      if (!states[i]) { continue; }
      path = states[i].path();
      if (!seen[path]) {
        a.push(states[i]);
        seen[path] = true;
      }
    }

    return a;
  }
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]
1210390
def _bulk_to_linear(M, N, L, qubits):
    ""
    return [2 * L * N * x + 2 * L * y + L * u + k for x, y, u, k in qubits]
954403
def reset(self):
        
        self.wf.fill(0)
        self.wf[(0,) * self.n_qubits] = complex(1.0, 0)
        return self
24892
def _get_gate_tensor_and_qubits(gate: Gate):
    
    if len(gate.params) > 0:
        matrix = QUANTUM_GATES[gate.name](*gate.params)
    else:
        matrix = QUANTUM_GATES[gate.name]

    qubit_inds = [q.index for q in gate.qubits]

    # e.g. 2-qubit matrix is 4x4; turns into (2,2,2,2) tensor.
    tensor = np.reshape(matrix, (2,) * len(qubit_inds) * 2)

    return tensor, qubit_inds
420694
def reset_state(self):
        """"""
        self.y = self.y0.copy()
        self.dy = np.zeros(self.dmps)   
        self.ddy = np.zeros(self.dmps)  
        self.cs.reset_state()
573808
def qubit_pairs_to_qubit_order(
    qubit_pairs: Sequence[Sequence[ops.Qid]]
    ) -> List[ops.Qid]:
    

    if set(len(qubit_pair) for qubit_pair in qubit_pairs) != set((2,)):
        raise ValueError(
            'set(len(qubit_pair) for qubit_pair in qubit_pairs) != '
            'set((2,))')
    n_pairs = len(qubit_pairs)
    qubits = [] # type: List[ops.Qid]
    for i in range(0, 2 * (n_pairs // 2), 2):
        qubits += [qubit_pairs[i][0], qubit_pairs[i + 1][0],
                   qubit_pairs[i][1], qubit_pairs[i + 1][1]]
    if n_pairs % 2:
        qubits += list(qubit_pairs[-1])
    return qubits
739802
def _generate_a_indptr(num_states, s_indices, out):
    
    idx = 0
    out[0] = 0
    for s in range(num_states-1):
        while(s_indices[idx] == s):
            idx += 1
        out[s+1] = idx
    out[num_states] = len(s_indices)
1211873
def _zerosamestates(self, A):
        

        for pair in self.samestates:
            A[pair[0], pair[1]] = 0
            A[pair[1], pair[0]] = 0