set_param

Set the value of a parameter on an Executable for parametric execution.

Definition

void set_param(struct Executable *executable, char *name, unsigned int index, double value);

Arguments

  1. executable: The Executable to set the parameter on.
  2. name: The name of the memory region to set a value for.
  3. index: The index into the memory region where the value should be set.
  4. value: The value to set for name[index].

Safety

  1. executable must be the result of executable_from_quil
  2. name must be a valid, non-NULL, nul-terminated string. It must also live until executableis freed.

Example

Adapted from pyQuil

With a program like this one:

    char *PARAMETRIZED_PROGRAM =
        "DECLARE ro BIT\n"
        "DECLARE theta REAL\n"

        "RX(pi / 2) 0\n"
        "RZ(theta) 0\n"
        "RX(-pi / 2) 0\n"

        "MEASURE 0 ro[0]\n";

We've declared a region called theta that is used as a parameter. This parameter must be injected for any executions. You might have a loop which looks like this, where you execute on multiple different parameters:

    for (int step = 0; step < STEPS; step++) {
        theta = step * step_size;
        set_param(exe, "theta", 0, theta);

        ExecutionResult *result = execute_on_qvm(exe);
        
        // Do things with result...

        free_execution_result(result);
    }

In that example, exe is an Executable which would have been previously allocated using executable_from_quil.

Make sure to free each ExecutionResult in the loop to avoid leaking memory!

If theta was a larger vector (e.g. DECLARE theta REAL[2]) then you would set the other indexes like set_param(exe, "theta", index, another_value).