def test_calc_Expec_Pauli_Hamil() -> None:
    """Test calculating the expectation value of a PauliHamil"""
    env = utils.createQuestEnv()()
    qubits = utils.createQureg()(4, env)
    pauli_hamil = utils.createPauliHamil()(number_qubits=4,
                                           number_pauliprods=1)
    workspace = utils.createQureg()(4, env)
    a = cheat.calcExpecPauliHamil()(
        qureg=qubits,
        pauli_hamil=pauli_hamil,
        workspace=workspace,
    )
    npt.assert_almost_equal(a, 0.0)
Example #2
0
def test_PauliHamil() -> None:
    """Testing the creation, destruction and reporting of a PauliHamil"""
    env = utils.createQuestEnv()()
    pauli_hamil = utils.createPauliHamil()(number_qubits=5,
                                           number_pauliprods=3)
    cheat.initPauliHamil()(pauli_hamil=pauli_hamil,
                           coeffs=[0.1, 0.2, 0.3, 0.2, 0.4],
                           codes=[[2, 1, 3], [1, 2, 0], [3, 0, 0], [3, 0, 0],
                                  [3, 0, 0]])
    utils.reportPauliHamil()(pauli_hamil=pauli_hamil)
    result_type = utils.reportPauliHamil().restype
    argument_type = utils.reportPauliHamil().argtype

    assert result_type == "floats/integers"
    assert argument_type == ["Coefficient", "PauliMatrix"]

    utils.destroyPauliHamil()(pauli_hamil=pauli_hamil)
def test_init_functions(init) -> None:
    """Test init functions

    initZeroState, initPlusState, initDebugState, initBlankState, initClassicalState,
    initPureState, initStateFromAmps, initPauliHamil
    """
    env = utils.createQuestEnv()()
    qubits = utils.createQureg()(3, env)
    initialisation = init[0]()
    args = init[1]

    if args[0] == 'qureg':
        args[0] = qubits
    elif args[0] == 'pauli':
        args[0] = utils.createPauliHamil()(number_qubits=3,
                                           number_pauliprods=3)

    initialisation(*args)
Example #4
0
                matrix[i, co] = cComplex.real + 1j * cComplex.imag
            else:
                cComplex = cheat.getAmp()(qureg=qubits, index=i)
                matrix[i, co] = cComplex.real + 1j * cComplex.imag
    return matrix


@pytest.mark.parametrize(
    "applied",
    [(ops.applyDiagonalOp, [(5, utils.createQuestEnv()())]),
     (ops.applyMatrix2, [2, np.array([[0, 1], [2, 1]])]),
     (ops.applyMatrix4, [1, 3, 'matrix']),
     (ops.applyMatrixN, [[1, 2], 'matrix']),
     (ops.applyMultiControlledMatrixN, [[1, 2], [3, 4], 'matrix']),
     (ops.applyPauliHamil, [
         utils.createPauliHamil()(5, 2),
         utils.createQureg()(5, utils.createQuestEnv()())
     ]),
     (ops.applyPauliSum, [[[0, 1, 2, 3], [3, 2, 1, 0]], [0.4, 0.3],
                          utils.createQureg()(5, utils.createQuestEnv()())]),
     (ops.applyTrotterCircuit, [utils.createPauliHamil()(5, 2), 0.7, 1, 2])])
def test_apply_functions(applied) -> None:
    """Test all non-deprecated apply functions"""
    env = utils.createQuestEnv()()
    qubits = utils.createQureg()(5, env)
    cheat.initZeroState()(qureg=qubits)
    op = applied[0]()
    positional_args = applied[1]
    matrix = np.array([[1, 0, 0, 1], [0, 2, 0, 2], [2, 0, 2, 0], [1, 0, 0, 1]])
    if positional_args[-1] == 'matrix':
        args = [qubits]
Example #5
0
            elif control is True:
                cComplex = cheat.getAmp()(qureg=qubits, index=i + 4)
                matrix[i, co] = cComplex.real + 1j * cComplex.imag
            else:
                cComplex = cheat.getAmp()(qureg=qubits, index=i)
                matrix[i, co] = cComplex.real + 1j * cComplex.imag
    return matrix


@pytest.mark.parametrize("applied", [
    (ops.applyDiagonalOp, [(5, utils.createQuestEnv()()), 'Neither']),
    (ops.applyMatrix2, [2, np.array([[0, 1], [2, 1]]), 'Neither']),
    (ops.applyMatrix4, [1, 3, 'matrix']),
    (ops.applyMatrixN, [[1, 2], 'matrix']),
    (ops.applyMultiControlledMatrixN, [[1, 2], [3, 4], 'matrix']),
    (ops.applyPauliHamil, [utils.createPauliHamil()(5, 2),
                           utils.createQureg()(5, utils.createQuestEnv()()), 'pauli'],),
    (ops.applyPauliSum, [[[0, 1, 2, 3, 0], [3, 2, 1, 0, 0]], [0.4, 0.3],
                         utils.createQureg()(5, utils.createQuestEnv()()), 'Neither']),
    (ops.applyTrotterCircuit, [utils.createPauliHamil()(5, 2), 0.7, 1, 2, 'pauli'])
    ])
def test_apply_functions(applied: Tuple[Any, List]) -> None:
    """Test all non-deprecated apply functions"""
    env = utils.createQuestEnv()()
    qubits = utils.createQureg()(5, env)
    cheat.initZeroState()(qureg=qubits)
    op = applied[0]()
    positional_args = applied[1]
    matrix = np.array([[1, 0, 0, 1], [0, 2, 0, 2], [2, 0, 2, 0], [1, 0, 0, 1]])
    last_element: str = positional_args.pop()
    if last_element == 'matrix':