예제 #1
0
    def __init__(self, operator, t=1, k=20, mode='local'):
        super().__init__([t])

        if not is_hermitian(operator):
            raise ValueError("Hamiltonian must be Hermitian.")

        if (not isinstance(k, int)) or k <= 0:
            raise ValueError("Argument k must be a postive integer.")

        if mode == 'local':
            boson_operator = prune_unused_indices(operator)
        elif mode == 'global':
            boson_operator = operator

        if isinstance(boson_operator, QuadOperator):
            boson_operator = get_boson_operator(boson_operator, hbar=sf.hbar)

        self.layer = trotter_layer(boson_operator, t, k)
        self.num_layers = k

        num_modes = max([op[0] for term in operator.terms for op in term]) + 1

        if mode == 'local':
            self.ns = num_modes
        elif mode == 'global':
            # pylint: disable=protected-access
            self.ns = pu.Program_current_context.num_subsystems
예제 #2
0
 def test_boson_form(self):
     """Test bosonic form is correct"""
     H = normal_ordered(get_boson_operator(self.H, hbar=self.hbar))
     expected = BosonOperator('0 1', -1)
     expected += BosonOperator('0 1^', -1)
     expected += BosonOperator('0^ 1', -1)
     expected += BosonOperator('0^ 1^', -1)
     self.assertEqual(H, expected)
예제 #3
0
 def test_boson_form(self, hbar):
     """Test bosonic form is correct"""
     H = normal_ordered(get_boson_operator(self.H, hbar=hbar))
     expected = BosonOperator('0 1', -1)
     expected += BosonOperator('0 1^', -1)
     expected += BosonOperator('0^ 1', -1)
     expected += BosonOperator('0^ 1^', -1)
     assert H == expected
예제 #4
0
 def test_boson_form(self):
     """Test bosonic form is correct"""
     self.logTestName()
     H = normal_ordered(get_boson_operator(self.H, hbar=self.hbar))
     expected = BosonOperator('0 0', -0.5)
     expected += BosonOperator('0^ 0', -1)
     expected += BosonOperator('0^ 0^', -0.5)
     expected += BosonOperator('', -0.5)
     self.assertEqual(H, expected)
예제 #5
0
    def __init__(self, operator, t=1, k=20, mode='local', hbar=None):
        super().__init__([t, operator])

        try:
            # pylint: disable=protected-access
            self.hbar = _Engine._current_context.hbar
        except AttributeError:
            if hbar is None:
                raise ValueError(
                    "Either specify the hbar keyword argument, "
                    "or use this operator inside an engine context.")
            else:
                self.hbar = hbar

        if not is_hermitian(operator):
            raise ValueError("Hamiltonian must be Hermitian.")

        if (not isinstance(k, int)) or k <= 0:
            raise ValueError("Argument k must be a postive integer.")

        if mode == 'local':
            boson_operator = prune_unused_indices(operator)
        elif mode == 'global':
            boson_operator = operator

        if isinstance(boson_operator, QuadOperator):
            boson_operator = get_boson_operator(boson_operator, hbar=self.hbar)

        self.layer = trotter_layer(boson_operator, t, k)
        self.num_layers = k

        num_modes = max([op[0] for term in operator.terms for op in term]) + 1

        if mode == 'local':
            self.ns = num_modes
        elif mode == 'global':
            # pylint: disable=protected-access
            self.ns = _Engine._current_context.num_subsystems
예제 #6
0
 def test_hermitian(self):
     """Test output is hermitian"""
     self.logTestName()
     H, _ = xdisplacement(self.x)
     self.assertTrue(is_hermitian(H))
     self.assertTrue(is_hermitian(get_boson_operator(H, hbar=self.hbar)))
예제 #7
0
 def test_hermitian(self):
     """Test output is hermitian"""
     self.logTestName()
     self.assertTrue(is_hermitian(self.H))
     self.assertTrue(
         is_hermitian(get_boson_operator(self.H, hbar=self.hbar)))
예제 #8
0
 def test_hermitian(self):
     """Test output is hermitian"""
     H, _ = zdisplacement(self.p)
     self.assertTrue(is_hermitian(H))
     self.assertTrue(is_hermitian(get_boson_operator(H, hbar=self.hbar)))
예제 #9
0
 def test_hermitian(self, hbar):
     """Test output is hermitian"""
     H, _ = xdisplacement(self.x)
     assert is_hermitian(H)
     assert is_hermitian(get_boson_operator(H, hbar=hbar))
예제 #10
0
 def test_hermitian(self, hbar):
     """Test output is hermitian"""
     assert is_hermitian(self.H)
     assert is_hermitian(get_boson_operator(self.H, hbar=hbar))