Skip to content

Commit

Permalink
fix bindings of update_quantum_circuit
Browse files Browse the repository at this point in the history
  • Loading branch information
Glacialte committed Jan 21, 2025
1 parent 969ab33 commit 6374e88
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 12 deletions.
12 changes: 10 additions & 2 deletions exe/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,17 @@ def main():

print(operator.to_json())

states = StateVectorBatched(3, 3)
states = StateVectorBatched.Haar_random_state(2, 3)
prx = gate.ParamRX(0, 2.0, [1])
pry = gate.ParamRY(1, 2.0, [2])
params = {
"rx": [0.0, 0.1, 0.2],
"ry": [0.3, 0.4, 0.5]
}
circuit.add_param_gate(prx, "rx")
circuit.add_param_gate(pry, "ry")
circuit.update_quantum_state(states, params)
print(states.to_json())


if __name__ == "__main__":
main()
15 changes: 5 additions & 10 deletions include/scaluq/circuit/circuit.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,8 @@ void bind_circuit_circuit_hpp(nb::module_& m) {
nb::overload_cast<const Circuit<Fp>&>(&Circuit<Fp>::add_circuit),
"Add all gates in specified circuit. Given gates are copied.")
.def("update_quantum_state",
&Circuit<Fp>::update_quantum_state,
static_cast<void (Circuit<Fp>::*)(StateVector<Fp>&, const std::map<std::string, Fp>&)
const>(&Circuit<Fp>::update_quantum_state),
"Apply gate to the StateVector. StateVector in args is directly updated. If the "
"circuit contains parametric gate, you have to give real value of parameter as "
"dict[str, float] in 2nd arg.")
Expand All @@ -146,13 +147,11 @@ void bind_circuit_circuit_hpp(nb::module_& m) {
"Apply gate to the StateVector. StateVector in args is directly updated. If the "
"circuit contains parametric gate, you have to give real value of parameter as "
"\"name=value\" format in kwargs.")
.def("update_quantum_state",
[](const Circuit<Fp>& circuit, StateVector<Fp>& state) {
circuit.update_quantum_state(state);
})
.def(
"update_quantum_state",
&Circuit<Fp>::update_quantum_state,
static_cast<void (Circuit<Fp>::*)(StateVectorBatched<Fp>&,
const std::map<std::string, std::vector<Fp>>&) const>(
&Circuit<Fp>::update_quantum_state),
"Apply gate to the StateVectorBatched. StateVectorBatched in args is directly updated. "
"If the circuit contains parametric gate, you have to give real value of parameter as "
"dict[str, list[float]] in 2nd arg.")
Expand All @@ -168,10 +167,6 @@ void bind_circuit_circuit_hpp(nb::module_& m) {
"Apply gate to the StateVectorBatched. StateVectorBatched in args is directly updated. "
"If the circuit contains parametric gate, you have to give real value of parameter as "
"\"name=[value1, value2, ...]\" format in kwargs.")
.def("update_quantum_state",
[](const Circuit<Fp>& circuit, StateVectorBatched<Fp>& states) {
circuit.update_quantum_state(states);
})
.def("copy", &Circuit<Fp>::copy, "Copy circuit. All the gates inside is copied.")
.def("get_inverse",
&Circuit<Fp>::get_inverse,
Expand Down

0 comments on commit 6374e88

Please sign in to comment.