tensorcircuit.interfaces.numpy#
Interface wraps quantum function as a numpy function
- tensorcircuit.interfaces.numpy.np_interface(fun: Callable[[...], Any], jit: bool = True) Callable[[...], Any]#
Convert
funon ML backend into a numpy function- Example
K = tc.set_backend("tensorflow") def f(params, n): c = tc.Circuit(n) for i in range(n): c.rx(i, theta=params[i]) for i in range(n-1): c.cnot(i, i+1) r = K.real(c.expectation_ps(z=[n-1])) return r n = 3 f_np = tc.interfaces.numpy_interface(f, jit=True) f_np(np.ones([n]), n) # 0.1577285
- Parameters
fun (Callable[..., Any]) – The quantum function
jit (bool, optional) – whether to jit
fun, defaults to True
- Returns
The numpy interface compatible version of
fun- Return type
Callable[…, Any]
- tensorcircuit.interfaces.numpy.numpy_interface(fun: Callable[[...], Any], jit: bool = True) Callable[[...], Any][source]#
Convert
funon ML backend into a numpy function- Example
K = tc.set_backend("tensorflow") def f(params, n): c = tc.Circuit(n) for i in range(n): c.rx(i, theta=params[i]) for i in range(n-1): c.cnot(i, i+1) r = K.real(c.expectation_ps(z=[n-1])) return r n = 3 f_np = tc.interfaces.numpy_interface(f, jit=True) f_np(np.ones([n]), n) # 0.1577285
- Parameters
fun (Callable[..., Any]) – The quantum function
jit (bool, optional) – whether to jit
fun, defaults to True
- Returns
The numpy interface compatible version of
fun- Return type
Callable[…, Any]