4
$\begingroup$

I was trying to write a more elaborate circuit based on Qiskit's tutorial here: https://qiskit.org/textbook/ch-machine-learning/machine-learning-qiskit-pytorch.html

When I came to the training part, I realised that the way this network is written, the only trainable parameters are actually the input (or rather, the encoding of the input). However, I would like to write a circuit where the trainable parameters are not directly related to the input, like the weights in classical neural networks. More specifically, the encoding is supposed to be seperate from the actual trainable circuit, and the rotation parameters need to somehow be accessible to PyTorch as trainable parameters. I don't know if this is even possible to do with PyTorch's autograd, or if I would have to write the entire gradient descent process myself?

$\endgroup$
1

1 Answer 1

2
$\begingroup$

Writing a circuit where the trainable parameters are not directly related to the input is doable. You could set an initial parameters (angles in the most cases) by yourself instead of encoding the input data.

The following references may help you

https://qiskit.org/documentation/machine-learning/tutorials/01_neural_networks.html

# construct parametrized circuit
params1 = [Parameter("input1"), Parameter("weight1")]
qc1 = QuantumCircuit(1)
qc1.h(0)
qc1.ry(params1[0], 0)
qc1.rx(params1[1], 0)
qc_sfn1 = StateFn(qc1)

# construct cost operator
H1 = StateFn(PauliSumOp.from_list([("Z", 1.0), ("X", 1.0)]))

# combine operator and circuit to objective function
op1 = ~H1 @ qc_sfn1
print(op1)

where Parameter("weight1")represent trainable weights

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.