def _execute_and_read_result(
    quantum_computer: QuantumComputer,
    executable: QuantumExecutable,
    measurement_id_map: dict[str, str],
    resolver: cirq.ParamResolverOrSimilarType,
    memory_map: dict[sympy.Expr | str, int | float | Sequence[int] | Sequence[float]] | None = None,
) -> cirq.Result:
    """Execute the `pyquil.api.QuantumExecutable` and parse the measurements into
    a `cirq.Result`.

    Args:
        quantum_computer: The `pyquil.api.QuantumComputer` on which to execute
            and from which to read results.
        executable: The fully compiled `pyquil.api.QuantumExecutable` to run.
        measurement_id_map: A dict mapping cirq measurement keys to pyQuil
            read out regions.
        resolver: The `cirq.ParamResolverOrSimilarType` to include on
            the returned `cirq.Result`.
        memory_map: A dict of values to write to memory values on the
            `quantum_computer`. The `pyquil.api.QuantumAbstractMachine` reads these
            v_execute_and_read_resultalues into memory regions on the pre-compiled
            `executable` during execution.

    Returns:
        A `cirq.Result` with measurements read from the `quantum_computer`.

    Raises:
        ValueError: measurement_id_map references an undefined pyQuil readout region.
    """

    # convert all atomic memory values into 1-length lists
    if memory_map is not None:
        for region_name, value in memory_map.items():
            if not isinstance(region_name, str):
                raise ValueError(f'Symbols not valid for region name {region_name}')
            value = [value] if not isinstance(value, Sequence) else value
            memory_map[region_name] = value

    qam_execution_result = quantum_computer.qam.run(executable, memory_map)  # type: ignore

    measurements = {}
    # For every key, value in QuilOutput#measurement_id_map, use the value to read
    # Rigetti QCS results and assign to measurements by key.
    for cirq_memory_key, pyquil_region in measurement_id_map.items():
        readout = qam_execution_result.get_register_map().get(pyquil_region)
        if readout is None:
            raise ValueError(f'readout data does not have values for region "{pyquil_region}"')
        measurements[cirq_memory_key] = readout
    logger.debug(f"measurement_id_map {measurement_id_map}")
    logger.debug(f"measurements {measurements}")

    # collect results in a cirq.Result.
    result = cirq.ResultDict(
        params=cast(cirq.ParamResolver, resolver or cirq.ParamResolver({})),
        measurements=measurements,
    )
    return result
Execute the `pyquil.api.QuantumExecutable` and parse the measurements into
    a `cirq.Result`.

    Args:
        quantum_computer: The `pyquil.api.QuantumComputer` on which to execute
            and from which to read results.
        executable: The fully compiled `pyquil.api.QuantumExecutable` to run.
        measurement_id_map: A dict mapping cirq measurement keys to pyQuil
            read out regions.
        resolver: The `cirq.ParamResolverOrSimilarType` to include on
            the returned `cirq.Result`.
        memory_map: A dict of values to write to memory values on the
            `quantum_computer`. The `pyquil.api.QuantumAbstractMachine` reads these
            v_execute_and_read_resultalues into memory regions on the pre-compiled
            `executable` during execution.

    Returns:
        A `cirq.Result` with measurements read from the `quantum_computer`.

    Raises:
        ValueError: measurement_id_map references an undefined pyQuil readout region.
    
cirq-rigetti/cirq_rigetti/circuit_sweep_executors.py