Skip to content

Commit

Permalink
Adding a check for the vector size and formatting
Browse files Browse the repository at this point in the history
Signed-off-by: Sachin Pisal <[email protected]>
  • Loading branch information
sacpis committed Dec 31, 2024
1 parent 14ddeb1 commit ebee965
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
8 changes: 8 additions & 0 deletions python/utils/OpaqueArguments.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<size_t>();
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<py::str>(arg)) {
arg = py::cast<std::string>(arg);
Expand Down
6 changes: 3 additions & 3 deletions runtime/cudaq/algorithms/observe.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit ebee965

Please sign in to comment.