In [1]:
Copied!
import jaxquantum as jqt
import jax.numpy as jnp
import jaxquantum as jqt
import jax.numpy as jnp
--------------------------------------------------------------------------- ModuleNotFoundError Traceback (most recent call last) Cell In[1], line 1 ----> 1 import jaxquantum as jqt 2 import jax.numpy as jnp ModuleNotFoundError: No module named 'jaxquantum'
Qarray¶
The Qarray is the fundamental building block of jaxquantum
. It is heavily inspired by QuTiP's Qobj and built to be compatible with JAX
patterns.
In [2]:
Copied!
N = 50
state = jqt.basis(N, 0)
displaced_state = jqt.displace(N, 2.0) @ state
displaced_state.to_dm().header
N = 50
state = jqt.basis(N, 0)
displaced_state = jqt.displace(N, 2.0) @ state
displaced_state.to_dm().header
--------------------------------------------------------------------------- NameError Traceback (most recent call last) Cell In[2], line 2 1 N = 50 ----> 2 state = jqt.basis(N, 0) 3 displaced_state = jqt.displace(N, 2.0) @ state 4 displaced_state.to_dm().header NameError: name 'jqt' is not defined
In [3]:
Copied!
pts = jnp.linspace(-4, 4, 100)
jqt.plot_wigner(displaced_state, pts)
pts = jnp.linspace(-4, 4, 100)
jqt.plot_wigner(displaced_state, pts)
--------------------------------------------------------------------------- NameError Traceback (most recent call last) Cell In[3], line 1 ----> 1 pts = jnp.linspace(-4, 4, 100) 2 jqt.plot_wigner(displaced_state, pts) NameError: name 'jnp' is not defined
Batching¶
A crucial difference between a Qarray and Qobj is its bdim
or batch dimension. This enables us to seamlessly use batching and numpy broadcasting in calculations using Qarray objects.
In [4]:
Copied!
N = 50
state = jqt.basis(N, 0)
displaced_state = jqt.displace(N, jnp.array([[0.0, 0.5, 1.0],[1.5,2.0,2.5]])) @ state
displaced_state.header
N = 50
state = jqt.basis(N, 0)
displaced_state = jqt.displace(N, jnp.array([[0.0, 0.5, 1.0],[1.5,2.0,2.5]])) @ state
displaced_state.header
--------------------------------------------------------------------------- NameError Traceback (most recent call last) Cell In[4], line 2 1 N = 50 ----> 2 state = jqt.basis(N, 0) 3 displaced_state = jqt.displace(N, jnp.array([[0.0, 0.5, 1.0],[1.5,2.0,2.5]])) @ state 5 displaced_state.header NameError: name 'jqt' is not defined
In [5]:
Copied!
pts = jnp.linspace(-4, 4, 100)
jqt.plot_wigner(displaced_state[0][0], pts)
jqt.plot_wigner(displaced_state[0][2], pts)
jqt.plot_wigner(displaced_state[1][1], pts)
pts = jnp.linspace(-4, 4, 100)
jqt.plot_wigner(displaced_state[0][0], pts)
jqt.plot_wigner(displaced_state[0][2], pts)
jqt.plot_wigner(displaced_state[1][1], pts)
--------------------------------------------------------------------------- NameError Traceback (most recent call last) Cell In[5], line 1 ----> 1 pts = jnp.linspace(-4, 4, 100) 2 jqt.plot_wigner(displaced_state[0][0], pts) 3 jqt.plot_wigner(displaced_state[0][2], pts) NameError: name 'jnp' is not defined
Constructing a batched Qarray manually¶
In [6]:
Copied!
N = 50
a = jqt.displace(N, 0.0)
b = jqt.displace(N, 1.0)
c = jqt.displace(N, 2.0)
arr1 = jqt.Qarray.from_array([[a,b,c],[a,b,c]])
arr2 = jqt.displace(N, jnp.array([[0.0, 1.0, 2.0],[0.0, 1.0, 2.0]]))
jnp.max(jnp.abs(arr1[0][1].data-arr2[0][1].data))
N = 50
a = jqt.displace(N, 0.0)
b = jqt.displace(N, 1.0)
c = jqt.displace(N, 2.0)
arr1 = jqt.Qarray.from_array([[a,b,c],[a,b,c]])
arr2 = jqt.displace(N, jnp.array([[0.0, 1.0, 2.0],[0.0, 1.0, 2.0]]))
jnp.max(jnp.abs(arr1[0][1].data-arr2[0][1].data))
--------------------------------------------------------------------------- NameError Traceback (most recent call last) Cell In[6], line 2 1 N = 50 ----> 2 a = jqt.displace(N, 0.0) 3 b = jqt.displace(N, 1.0) 4 c = jqt.displace(N, 2.0) NameError: name 'jqt' is not defined