Open dh-dz opened 2 years ago
Hmm, there's currently not a super simple way to do this but one possibility should be something like the following:
from quimb.tensor.circuit import fsimg_param_gen
def fsimg_fixed(params, fixed_angles):
theta = params[0]
return fsimg_param_gen([theta, *fixed_angles])
# assuming tn == circ.uni etc.
for t in tn['FSIMG']:
# directly update the `PTensor` with the partial fsimg generator
t.params = t.params[:1]
t.fn = functools.partial(fsimg_fixed, fixed_angles=t.params[1:])
PArray
gatesor in fact you can probably also something do:
from quimb.tensor.array_ops import PArray
for where in gates:
G = PArray(
fn=functools.partial(fsimg_fixed, fixed_angles=qu.randn(4)),
params=np.array([theta0])
)
circ.apply_gate_raw(G, where, tags='FSIMG_THETA')
I haven't tried either so they may need some tweaking, but let me know how you get on!
I am using FSIMG gates to build the quantum circuit, but want to only optimize theta parameter while fixing the other four as constants when running the optimizer. Is there a way to do that? Thank you!