Comments (7)
Good question, since the topology of the circuit is a static information (shape information of the whole tensor network for the circuit), it is unable to jit in general even if you can use jax integer as the index number. However, in many interesting cases, depends on your specific use cases, you can find some way to smartly encode the problem and enable jit. So if you like, you can share your exact use case so that I can figure out whether the problem under simulation is jittable or not.
from tensorcircuit.
Hi @refraction-ray , thanks for the timely reply! I see why we must treat the topology as static. I'm okay with that. But since I'm inputing the topology as a list of indices, and list is non-hashable and therefore cannot be used as a static argument in jax.jit. Do you have any suggestions on how to work around on that? For example, my code is like (arch for architecture, a list of (i, j) specifying the positions to apply two qubit gates):
def apply_circuit(c, arch, unitary):
assert len(arch) == len(unitary)
for i in range(len(arch)):
c.any(int(arch[i][0]), int(arch[i][1]), unitary=unitary[i])
return c
Many thanks in advance!
from tensorcircuit.
# Apply X on given indices while jittable
n = 6
K = tc.set_backend("jax")
cand = K.stack([K.eye(2), tc.gates.pauli_gates[1].tensor])
def apply_gates(c, inds):
inds = K.cast(inds, "int32")
mpos = []
for i in range(n):
mpos.append(tc.gates.Gate(cand[inds[i]]))
gate_applied = tc.quantum.QuOperator([m[0] for m in mpos], [m[1] for m in mpos])
c.mpo(*range(n), mpo=gate_applied)
return c
@K.jit
def cal_loss(inds):
c = tc.Circuit(n)
c = apply_gates(c, inds)
for i in range(n-1):
c.cx(i, i+1)
return K.real(c.expectation_ps(z=[1]))
cal_loss(K.convert_to_tensor([0, 1, 0, 0, 1, 0]))
A smart way to around I just think of that might help, feel free to ask more if this paradigm not fits
from tensorcircuit.
Thanks @refraction-ray , this works well! I'm wondering how to generalize this to 2-qubit gates. I think we can use [0, 0, 0, 1, 2] to specify indices. But it's not clear how to consturct the mpos list while kepping cand an array. I tried the following
def apply_circuit(c, arch, unitary):
assert len(arch) == len(unitary)
iden = jnp.eye(2)
n = c._nqubits
for i in range(len(arch)):
u = tc.gates.Gate(unitary[i].reshape(2, 2, 2, 2))
cand = [tc.gates.Gate(iden), [u[0], u[2]], [u[1], u[3]]]
mpos = [cand[arch[i, j]] for j in range(n)]
mpo = tc.quantum.QuOperator([m[0] for m in mpos], [m[1] for m in mpos])
c.mpo(*range(n), mpo=mpo)
return c
but it's still non jittable, because cand is not an array. Any thoughts on that? Thanks!
from tensorcircuit.
two-qubit gate is more subtle, if the layout is more specified, say brickwall or ladder, i.e. the two qubit gates are always applied in adjacent indices, it is okay to jit using similar approaches. However, if all-to-all couplings are possible to apply two-qubit gates, for now, it is hard to efficiently jit (maybe there is also a clever way, just I fail to recongnize )
from tensorcircuit.
I see. Thanks for your suggestions!
from tensorcircuit.
btw, i will be at tsinghua U in 10-15 Aug, if you are there by then, we can meet offline. You can drop me an email for wechat id to connect if you are available.
from tensorcircuit.
Related Issues (20)
- increase the abundance of the QAOA tutorial HOT 1
- docker file need updating HOT 2
- Wired input and output of function "c.amplitude" HOT 3
- Enhance <QAOA portfolio tutorial> HOT 4
- Fermion Gaussian State Simulator HOT 3
- Stabilizer simulator
- Backend agnostic implementation of quantum Hamiltonian generation
- Support trainable adptive circuit HOT 2
- Implementation of SHVQE with QAS HOT 1
- tensor network representation of a tensor circuit HOT 2
- Allow sparse matrix as circuit input HOT 3
- AttributeError: module 'tensorflow' has no attribute 'sparse' HOT 2
- Bug in qiskit circuit parsing HOT 2
- jit compile circuit with any gate HOT 2
- `copy` operation of DM circuit forgets previous `apply_general_kraus` operations HOT 1
- MPS circuit with JIT compilation HOT 8
- Sampling from circuit does not give proper bitstring HOT 4
- Add Jittor backend HOT 3
- Stabilizer simulation example utilizing stim backend
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from tensorcircuit.