コード例 #1
0
def benchmark_jordan_wigner_sparse(n_qubits):
    """Benchmark the speed at which a FermionOperator is mapped to a matrix.

    Args:
        n_qubits: The number of qubits in the example.

    Returns:
        runtime: The time in seconds that the benchmark took.
    """
    # Initialize a random FermionOperator.
    molecular_operator = random_interaction_operator(n_qubits)
    fermion_operator = get_fermion_operator(molecular_operator)

    # Map to SparseOperator class.
    start_time = time.time()
    _ = jordan_wigner_sparse(fermion_operator)
    runtime = time.time() - start_time
    return runtime
コード例 #2
0
 def qubit_generator_matrix(self) -> np.ndarray:
     """The matrix G such that the gate's unitary is exp(-i t G) with
     exponent t."""
     return jordan_wigner_sparse(self.fermion_generator,
                                 self.num_qubits()).toarray()