Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parameter substitution for xacc::CompositeInstruction using operator() is inconsistent #575

Open
daanish-qb opened this issue Aug 23, 2023 · 0 comments

Comments

@daanish-qb
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant