예제 #1
0
 def test_permutation_without_expansion(self, permutation):
     base = qutip.tensor([qutip.rand_unitary(2) for _ in permutation])
     test = gates.expand_operator(base,
                                  N=len(permutation),
                                  targets=permutation)
     expected = base.permute(_apply_permutation(permutation))
     np.testing.assert_allclose(test.full(), expected.full(), atol=1e-15)
예제 #2
0
 def test_cyclic_permutation(self):
     operators = [qutip.sigmax(), qutip.sigmaz()]
     test = gates.expand_operator(qutip.tensor(*operators), N=3,
                                  targets=[0, 1], cyclic_permutation=True)
     base_expected = qutip.tensor(*operators, qutip.qeye(2))
     expected = [base_expected.permute(x)
                 for x in [[0, 1, 2], [1, 2, 0], [2, 0, 1]]]
     assert len(expected) == len(test)
     for element in expected:
         assert element in test
예제 #3
0
 def test_general_qubit_expansion(self, n_targets):
     # Test all permutations with the given number of targets.
     n_qubits = 5
     operation = qutip.rand_unitary(2**n_targets, dims=[[2]*n_targets]*2)
     for targets in itertools.permutations(range(n_qubits), n_targets):
         expected = _tensor_with_entanglement([qutip.qeye(2)] * n_qubits,
                                              operation, targets)
         test = gates.expand_operator(operation, n_qubits, targets)
         np.testing.assert_allclose(test.full(), expected.full(),
                                    atol=1e-15)
예제 #4
0
 def test_cnot_explicit(self):
     test = gates.expand_operator(gates.cnot(), 3, [2, 0]).full()
     expected = np.array([[1, 0, 0, 0, 0, 0, 0,
                           0], [0, 0, 0, 0, 0, 1, 0, 0],
                          [0, 0, 1, 0, 0, 0, 0,
                           0], [0, 0, 0, 0, 0, 0, 0, 1],
                          [0, 0, 0, 0, 1, 0, 0,
                           0], [0, 1, 0, 0, 0, 0, 0, 0],
                          [0, 0, 0, 0, 0, 0, 1, 0],
                          [0, 0, 0, 1, 0, 0, 0, 0]])
     np.testing.assert_allclose(test, expected, atol=1e-15)
예제 #5
0
 def test_non_qubit_systems(self, dimensions):
     n_qubits = len(dimensions)
     for targets in itertools.permutations(range(n_qubits), 2):
         operators = [qutip.rand_unitary(dimension) if n in targets
                      else qutip.qeye(dimension)
                      for n, dimension in enumerate(dimensions)]
         expected = qutip.tensor(*operators)
         base_test = qutip.tensor(*[operators[x] for x in targets])
         test = gates.expand_operator(base_test, N=n_qubits,
                                      targets=targets, dims=dimensions)
         assert test.dims == expected.dims
         np.testing.assert_allclose(test.full(), expected.full())