Esempio n. 1
0
def test_core_multyinput():
  g=QGraph({})
  i1,g=addinput(g,1)
  i2,g=addinput(g,1)
  o1,g=addop(g,pairop(opX(),opX()),[i1,i2])
  s=evaluate({i1:braket([1]),i2:braket([0])},g,schedule(g))
  assert_allclose(s[o1].mat,braket([0,1]).mat)
Esempio n. 2
0
def test_core_112():
  g=QGraph({})
  i1,g=addinput(g,2)
  o1,g=addop(g,pairop(opH(),opX()),[i1])
  s=evaluate({i1:braket([0,0])},g,schedule(g))
  print(s[o1].mat)
  assert_allclose(s[o1].mat,[0.,1./sqrt(2),0.,1./sqrt(2)])
Esempio n. 3
0
def test_core_111_i2():
  g=QGraph({})
  i1,g=addinput(g,1)
  o1,g=addop(g,opI(),[i1])
  i2,g=addinput(g,1)
  o2,g=addop(g,opX(),[i2])
  o3,g=addop(g,pairop(opI(),opI()),[o1,o2])
  s=evaluate({i1:braket([0]),i2:braket([0])},g,schedule(g))
  assert_allclose(s[o3].mat,[0.,1.,0.,0,])
  assert_allclose(s[o3].mat,braket([0,1]).mat)
Esempio n. 4
0
def test_core_111_opmatrix():
  g=QGraph({})
  i1,g=addinput(g,2)
  o1,g=addop(g,pairop(opI(),opX()),[i1])
  s=opmatrix(g,schedule(g))
  print(s[o1].mat)
  assert_allclose(s[o1].mat,[[0.,1.,0.,0.],
                             [1.,0.,0.,0.],
                             [0.,0.,0.,1.],
                             [0.,0.,1.,0.]])
Esempio n. 5
0
def test_core_112_opmatrix_i2():
  g=QGraph({})
  i1,g=addinput(g,1)
  o1,g=addop(g,opH(),[i1])
  i2,g=addinput(g,1)
  o2,g=addop(g,opX(),[i2])
  o3,g=addop(g,pairop(opI(),opI()),[o1,o2])
  s=opmatrix(g,schedule(g))
  print(s[o3].mat)
  assert_allclose(s[o3].mat,
                  [[ 0.      ,  1./sqrt(2),  0.      ,  1./sqrt(2)],
                   [ 1./sqrt(2),  0.      ,  1./sqrt(2),  0.      ],
                   [ 0.      ,  1./sqrt(2),  0.      , -1./sqrt(2)],
                   [ 1./sqrt(2),  0.      , -1./sqrt(2),  0.      ]])
Esempio n. 6
0
def test_core_18():
  g=QGraph({})
  i1,g=addinput(g,1)
  o1,g=addop(g,opX(),[i1])
  s=evaluate({i1:QVec([1.,0.])},g,schedule(g))
  assert_allclose(s[o1].mat,[0.,1.])