diff --git a/python/utils/OpaqueArguments.h b/python/utils/OpaqueArguments.h index 46afd2fedc8..7f88473df58 100644 --- a/python/utils/OpaqueArguments.h +++ b/python/utils/OpaqueArguments.h @@ -99,6 +99,14 @@ inline py::args simplifiedValidateInputArguments(py::args &args) { if (shape.size() != 1) throw std::runtime_error("Cannot pass ndarray with shape != (N,)."); + // Vector size validation + size_t size = shape[0].cast(); + if (size == 0 || (size & (size - 1)) != 0) { + throw std::invalid_argument(fmt::format( + "Invalid vector size: {}. Vector size must be a power of 2.", + size)); + } + arg = args[i].attr("tolist")(); } else if (py::isinstance(arg)) { arg = py::cast(arg); diff --git a/runtime/cudaq/algorithms/observe.h b/runtime/cudaq/algorithms/observe.h index 407a528013a..dfaa7c93414 100644 --- a/runtime/cudaq/algorithms/observe.h +++ b/runtime/cudaq/algorithms/observe.h @@ -59,9 +59,9 @@ concept ObserveCallValid = /// @param shots number of shots to run for the given kernel, or -1 if not /// applicable. /// @param noise noise model to use for the sample operation -/// @param num_trajectories is the optional number of trajectories to be used when -/// computing the expectation values in the presence of noise. This parameter is -/// only applied to simulation backends that support noisy +/// @param num_trajectories is the optional number of trajectories to be used +/// when computing the expectation values in the presence of noise. This +/// parameter is only applied to simulation backends that support noisy /// simulation of trajectories. struct observe_options { int shots = -1;