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
executable: TheExecutableto set the parameter on.name: The name of the memory region to set a value for.index: The index into the memory region where the value should be set.value: The value to set forname[index].
Safety
executablemust be the result ofexecutable_from_quilnamemust be a valid, non-NULL, nul-terminated string. It must also live untilexecutableis 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
thetawas a larger vector (e.g.DECLARE theta REAL[2]) then you would set the other indexes likeset_param(exe, "theta", index, another_value).