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
Customizing parametrized tensors #115
Comments
Hi, I'm not totally sure I understand this question - with the |
Yeah, let’s say if I want to implement something like:
T = np.zeros([2,2])
T[0][0] = np.exp((J+h))
T[1][0] = np.exp(-1*(J))
T[0][1] = np.exp(-1*(J))
T[1][1] = np.exp((J-h))
where J and h are parameters; can I do that? Thanks!
… On Mar 28, 2022, at 12:32 PM, Johnnie Gray ***@***.***> wrote:
Hi, I'm not totally sure I understand this question - with the gate function you can apply an arbitrary array already. Maybe you could give some more specific details?
—
Reply to this email directly, view it on GitHub <#115 (comment)>, or unsubscribe <https://github.com/notifications/unsubscribe-auth/ANRXQL7PW3QZBJ4EH5BVHFDVCHUJPANCNFSM5RX36EVA>.
You are receiving this because you authored the thread.
|
I think you're already there! just call |
Oh I think I didn't parse the In which case have a look in Lines 382 to 411 in 28dc9dd
that implements the function in a However, if you just want to construct the TN and contract it e.g., then the parametrized machinery is not necessary. |
Yeah that’s exactly what I needed. Thanks for the reference!
… On Mar 28, 2022, at 3:57 PM, Johnnie Gray ***@***.***> wrote:
Oh I think I didn't parse the parametrized in the title of this issue, is the aim to optimize the TN w.r.t to the parameters, and thus you need PTensor instances?
In which case have a look in circuit.py at how this is achieved for the preset gates. e.g.:
https://github.com/jcmgray/quimb/blob/28dc9dd222001b4336e33a147ad4bb442cb38455/quimb/tensor/circuit.py#L382-L411 <https://github.com/jcmgray/quimb/blob/28dc9dd222001b4336e33a147ad4bb442cb38455/quimb/tensor/circuit.py#L382-L411>
that implements the function in a autoray compatible way (so many backends can be used), and creates a parametrized array which you could then optimize with respect to.
However, if you just want to construct the TN and contract it e.g., then the parametrized machinery is not necessary.
—
Reply to this email directly, view it on GitHub <#115 (comment)>, or unsubscribe <https://github.com/notifications/unsubscribe-auth/ANRXQLZQUPYGIHVSQKU5TA3VCIMM7ANCNFSM5RX36EVA>.
You are receiving this because you authored the thread.
|
Hi @jcmgray, I'm trying to create a custom parameterised gate for applying to a quantum circuit. I have tried to copy how 'fsim' is implemented in circuit.py:
After plugging this into a loss-function/optimizer, the apply_gate is causing the error |
This line: ALL_PARAM_GATES = ONE_QUBIT_PARAM_GATES | TWO_QUBIT_PARAM_GATES redefines Long term it might be worth adding adding an API so that we can add more custom gates easily. |
As of 576edce, you should be able to just use: def givens_param_gen(theta):
a = do('cos', theta)
b = do('sin', theta)
data = [[1, 0, 0, 0],
[0, a, -b, 0],
[0, b, a, 0],
[0, 0, 0, 1]]
return ops.asarray(data)
register_param_gate('GIVENS', givens_param_gen, num_qubits=2) I'd happily accept a PR adding this gate to |
Oh, sorry; I guess the question is: does the autodiff part apply to customed functions like this?
… On Mar 28, 2022, at 3:46 PM, Johnnie Gray ***@***.***> wrote:
psi.gate_
|
Yes, any part of |
Hi, when constructing a TN with psi.gate_(), is it possible customize your tensor? (e.g., fix off diagonal terms or define certain functions in the tensor) Thanks!
The text was updated successfully, but these errors were encountered: