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
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)
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
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)
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
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)))
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)))
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)))
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))
def test_hermitian(self, hbar): """Test output is hermitian""" assert is_hermitian(self.H) assert is_hermitian(get_boson_operator(self.H, hbar=hbar))