Sage: picklingΒΆ

>>> from sage.all import * 
>>> from qitensor import qubit, set_qitensor_printoptions 
>>> # use Sage's nice array formatting
>>> set_qitensor_printoptions(str_use_sage=True) 
>>> ha = qubit('a', dtype=SR) 
>>> hb = qubit('b', dtype=SR) 
>>> (x, y) = var('x y') 
>>> s = ha.array([1, x]) 
>>> t = hb.array([1, y]) 
>>> Q = s*t 
>>> Q 
HilbertArray(|a,b>,
[  1]
[  y]
[---]
[  x]
[x*y])
>>> R = loads(dumps(Q)) 
>>> R 
HilbertArray(|a,b>,
[  1]
[  y]
[---]
[  x]
[x*y])
>>> Q == R 
True
>>> Q is R 
False
>>> Q.space is R.space 
True

Test of long-term storage:

>>> T = loads('x\x9c}R[o\xd30\x14\xb6\x9d\xb6\xdb<6`\xdc\xc7}O\x9d*U\xb4\xa2\x12/\x08u\x15L,\xd0\x89d\xe9D\xa5*r\\\xa7\t\xca\xcdN2%\x88\x07xX\xab\xfdjp\x9a\x8eV\x15"\xb2\x12\xe7\x9c\xef\x96\xe3\xfcD\x94\xbb\t\x0b\xe2P4\x89\x10$\xc7f\x1a\x086N)3/Z\x98\xc3e;\x8e\x08ekmDM\xd3J]/q\x03\xd3\xc4\xb6\x08\xbfK,K0WF\xbcR_\x91NB\x7f\x8dZ\xad\x1b\x90\xc8\xa5\x02\x15Nym\x89\xb5\tMB\x91\xe3c\x11\xa6\xd1i\xd4\xcb\xa9\xe7R\xf3\xba\xca7Tt\xa9\xf1\xcd\x95\\d\xc2,\x123\xdbe\xdex\xcdd\x8b\x16\xddf\x9c\xfbV(U\x9a\xc2\r&8q\x98\xa9/*ZQ\xe0\xf8P\xe3\xdbR\xf5\xc6U?\xd1\xf8\x8eSd\xb3\xe4*\xb3\xed:\x9bN\xd9\xb9\xc9$\xe8\x96\xa3\x8c\xe4\xe3\xf6T\xe3{4H\xfd(o\xd2P\xb0\xa6\x9f\xca1,f(\x18\r\x838\x11)\x95\xb3\xb8S\xa2p0.\xbb\xfc\xae\n.\xa5\xfaL\xe3\xf7\xea*T\x91\x8a\xa6\x0b\xc88\xc9#\x86\xf9}\x03\x9d\xbe)\xcc%\xe4A]U\x0c\xf8\xa3\xdf\xef\x9f\xfc\x96\xd7\xfc\xa6\xbeK\xac\xab\x11\x7fX_\xfb<\x96E\x82\xc5\xb1\x1b\x06\xf8\xfdr\xcb\x1f\x1d\xfe\xe2\xfb*\x18\x19\xceqW\xeb)\xb530\xe9\x9e|\xa3\xed\x0f\xc1P\xef\xe4\xe4\xbc\x13\xd0\xbc\x13Y\x81\xe6\r\xdb\x83\xbc\xe7\xb7\x1c\xd2\x1e\xd8\xb2\xfejx>\xf6\xe8$\xca\xba\x03\xe3\xe8\xf3\xd7\x81N\xbf|L\x81\x0edX&\\\n\xa8G\xe2\x18\x14\x19L\x96\x01X\x05P\x81h\x0f\x1e(3\xcb)L\x1fKS\xfe\xc4\x8091\x1as\xebj\x19uA\xccA@|\xb6\xe4W\x00D\x18\xec\xa3\x05\xfbi\xc1~f\xc0\xec\xdf\xec\xec\xff\xec\xe7\x05\xfb\x85<\xc8L\xfa3#\x9b+\xec\xcaC\xbaN]j-T\xe4\xac\x120\x9f\xcb\xa7\xae\xfe\xfa\xed\xea7\x86\xcc\xb6e\xd4\xf0\x82\t\xe2yf\xf9\xfe\xd7uG\xa9 \x8c\x0e\x14\xa5\x85\x8e6\xf0V\xb1\xdf\xaea\xd0\x00:l \x1dR8\xb3Xb\xc9\x7f\xe5e\xf3\x0fq\xd4\x17m') 
>>> T 
HilbertArray(|a,b>,
[  1]
[  y]
[---]
[  x]
[x*y])
>>> Q == T 
True
>>> Q is T 
False
>>> Q.space is T.space 
True

Previous topic

Pickle

Next topic

Creation of channel from a function

This Page