When using a parametrized xacc::CompositeInstruction created using the IR, the values for variables that are fed in using the () operator (or by using ->operator()(params)) are not substituted consistently, depending only on the name of the variable. For example, for the following circuit:
Rx(alpha[0]) q0
Ry(alpha[0]) q0
Rx(beta[0]) q1
U1(beta[0]) q1
Measure q0
Measure q1
When the following code is run:
auto vars = instructions->getVariables();
std::cout << "Variables: ";
for (auto& elem: vars) {
std::cout << elem << ",";
}
std::cout << "\n\n";
std::vector<double> param_vec(2);
param_vec[0] = M_PI_2;
param_vec[1] = M_PI_4;
std::cout << "Parameter vector: [";
for (auto& elem: param_vec) {
std::cout << elem << ",";
}
std::cout << "]\n\n";
std::shared_ptr<xacc::CompositeInstruction> evaled_circ =
(*instructions)(param_vec);
std::cout << evaled_circ->toString() << "\n";
This is the resultant output:
Variables: beta[0],alpha[0],
Parameter vector: [1.5708,0.785398,]
Rx(6.93907e-310) q0
Ry(6.93907e-310) q0
Rx(6.93907e-310) q1
U1(6.93907e-310) q1
Measure q0
Measure q1
Meaning the CompositeInstruction recognizes the variables, but instead keeps the values of the parameters as 0. Instead, if the names of the variables are changed to simply be "alpha" and "beta", resulting in the following circuit:
Rx(alpha) q0
Ry(alpha) q0
Rx(beta) q1
U1(beta) q1
Measure q0
Measure q1
The above code runs as expected:
Variables: beta,alpha,
Parameter vector: [1.5708,0.785398,]
Rx(1.5708) q0
Ry(1.5708) q0
Rx(0.785398) q1
U1(0.785398) q1
Measure q0
Measure q1
This is an interesting issue, and definitely one that presents a problem if trying to build up separate vectors of parameters. Any insight would be appreciated.
When using a parametrized xacc::CompositeInstruction created using the IR, the values for variables that are fed in using the () operator (or by using
->operator()(params)) are not substituted consistently, depending only on the name of the variable. For example, for the following circuit:When the following code is run:
This is the resultant output:
Meaning the
CompositeInstructionrecognizes the variables, but instead keeps the values of the parameters as 0. Instead, if the names of the variables are changed to simply be "alpha" and "beta", resulting in the following circuit:The above code runs as expected:
This is an interesting issue, and definitely one that presents a problem if trying to build up separate vectors of parameters. Any insight would be appreciated.