"""Run FAST-VQE on LiH using AWS Braket SV1."""

# snippet-start: import-snippet
from braket.devices import Devices

import qrunch as qc

# snippet-end: import-snippet


def main() -> float:
    """Run FAST-VQE on LiH as the first script."""
    # Build molecular configuration for Lithium Hydride (LiH) molecule.
    molecular_configuration = qc.build_molecular_configuration(
        molecule=[
            ("H", 0.0, 0.0, 0.0),
            ("Li", 1.5474, 0.0, 0.0),
        ],
        basis_set="sto3g",
    )

    # Build the ground state problem.
    problem_builder = qc.problem_builder_creator().ground_state().standard().create()
    ground_state_problem = problem_builder.build_restricted(molecular_configuration)

    # snippet-start: braket-backend-snippet
    # Create an Amazon Braket SV1 sampler
    braket_sampler = qc.sampler_creator().backend().choose_backend().amazon_braket(Devices.Amazon.SV1).create()

    # Use a FAST gate selector with the Braket sampler
    gate_selector = qc.gate_selector_creator().fast().with_sampler(braket_sampler).with_shots(10).create()

    fast_vqe_calculator = (
        qc.calculator_creator().vqe().iterative().standard().with_gate_selector(gate_selector).create()
    )
    # snippet-end: braket-backend-snippet

    result = fast_vqe_calculator.calculate(ground_state_problem)

    return result.total_energy.value


if __name__ == "__main__":
    print(f"Total energy: {main()}")  # noqa: T201
