def setUp(self) -> None: hypercubic_setting.HypercubicSetting(beta=1.0, dimension=2, system_length=1.0) setting.set_number_of_node_levels(1) setting.set_number_of_nodes_per_root_node(1) setting.set_number_of_root_nodes(1) self._estimator_mock = mock.MagicMock(spec_set=Estimator) self._estimator_mock.derivative_bound.side_effect = mock_derivative_bound self._estimator_mock.charge_correction_factor = mock_charge_correction_factor # self._cells has the cell 0 with cell_min at the origin as the zero cell. self._cells = CuboidPeriodicCells(cells_per_side=[4, 4], neighbor_layers=1) self._cell_bounding_potential_without_charge = CellBoundingPotential( estimator=self._estimator_mock) self._cell_bounding_potential_with_charge = CellBoundingPotential( estimator=self._estimator_mock) # Redirect stdout to the null device while initializing the estimator with open(os.devnull, 'w') as devnull: with contextlib.redirect_stdout(devnull): self._cell_bounding_potential_without_charge.initialize( self._cells, False) self._cell_bounding_potential_with_charge.initialize( self._cells, True)
def test_reset(self): setting.set_number_of_root_nodes(5) setting.set_number_of_nodes_per_root_node(3) setting.set_number_of_node_levels(2) setting.reset() self.assertIsNone(setting.beta) self.assertIsNone(hypercubic_setting.beta) self.assertIsNone(hypercuboid_setting.beta) self.assertIsNone(setting.dimension) self.assertIsNone(hypercubic_setting.dimension) self.assertIsNone(hypercuboid_setting.dimension) self.assertIsNone(setting.random_position) self.assertIsNone(hypercubic_setting.random_position) self.assertIsNone(hypercuboid_setting.random_position) self.assertIsNone(setting.periodic_boundaries) self.assertIsNone(hypercubic_setting.periodic_boundaries) self.assertIsNone(hypercuboid_setting.periodic_boundaries) self.assertIsNone(setting.number_of_root_nodes) self.assertIsNone(hypercubic_setting.number_of_root_nodes) self.assertIsNone(hypercuboid_setting.number_of_root_nodes) self.assertIsNone(setting.number_of_nodes_per_root_node) self.assertIsNone(hypercubic_setting.number_of_nodes_per_root_node) self.assertIsNone(hypercuboid_setting.number_of_nodes_per_root_node) self.assertIsNone(setting.number_of_node_levels) self.assertIsNone(hypercubic_setting.number_of_node_levels) self.assertIsNone(hypercuboid_setting.number_of_node_levels) self.assertIsNone(hypercubic_setting.system_length) self.assertIsNone(hypercuboid_setting.system_lengths) self.assertIsNone(hypercubic_setting.system_length_over_two) self.assertIsNone(hypercuboid_setting.system_lengths_over_two)
def __init__(self, random_node_creator: RandomNodeCreator, number_of_root_nodes: int) -> None: """ The constructor of the RandomInputHandler class. The constructor sets the number of root nodes, the number of nodes per root node and the number of node levels in the setting package. Parameters ---------- random_node_creator : input_output_handler.input_handler.random_node_creator.RandomNodeCreator The random node creator which creates a single random root node. number_of_root_nodes : int The number of root nodes to create. """ log_init_arguments( logging.getLogger(__name__).debug, self.__class__.__name__, random_node_creator=random_node_creator.__class__.__name__, number_of_root_nodes=number_of_root_nodes) super().__init__() setting.set_number_of_root_nodes(number_of_root_nodes) setting.set_number_of_nodes_per_root_node( random_node_creator.number_of_nodes_per_root_node) setting.set_number_of_node_levels( random_node_creator.number_of_node_levels) self._random_node_creator = random_node_creator
def setUp(self) -> None: hypercubic_setting.HypercubicSetting(beta=1.0, dimension=3, system_length=1.0) # Set these so the settings are initialized setting.set_number_of_root_nodes(2) setting.set_number_of_nodes_per_root_node(2) setting.set_number_of_node_levels(1) # noinspection PyArgumentEqualDefault self._potential = InversePowerCoulombBoundingPotential(prefactor=1.6)
def test_initialized(self): self.assertFalse(hypercubic_setting.initialized()) self.assertFalse(hypercuboid_setting.initialized()) setting.set_number_of_root_nodes(3) self.assertFalse(hypercubic_setting.initialized()) self.assertFalse(hypercuboid_setting.initialized()) setting.set_number_of_nodes_per_root_node(1) self.assertFalse(hypercubic_setting.initialized()) self.assertFalse(hypercuboid_setting.initialized()) setting.set_number_of_node_levels(1) self.assertFalse(hypercubic_setting.initialized()) self.assertTrue(hypercuboid_setting.initialized())
def test_dimension_unequal_three_raises_error(self): setting.reset() hypercubic_setting.HypercubicSetting(beta=1.0, dimension=2, system_length=1.0) # Set these so the settings are initialized setting.set_number_of_root_nodes(2) setting.set_number_of_nodes_per_root_node(2) setting.set_number_of_node_levels(1) with self.assertRaises(ConfigurationError): self._potential = InversePowerCoulombBoundingPotential( prefactor=1.6)
def setUpSystemLengthTwo(self) -> None: hypercubic_setting.HypercubicSetting(beta=1.0, dimension=3, system_length=2.0) setting.set_number_of_root_nodes(2) setting.set_number_of_nodes_per_root_node(2) setting.set_number_of_node_levels(1) self._potential = MergedImageCoulombPotential(alpha=3.45, fourier_cutoff=6, position_cutoff=2, prefactor=1.0) self._variant_potential = MergedImageCoulombPotential( alpha=5.0, fourier_cutoff=9, position_cutoff=2)
def test_dimension_unequal_three_raises_error(self): hypercubic_setting.HypercubicSetting(beta=1.0, dimension=2, system_length=1.0) setting.set_number_of_root_nodes(2) setting.set_number_of_nodes_per_root_node(2) setting.set_number_of_node_levels(1) with self.assertRaises(ConfigurationError): MergedImageCoulombPotential(alpha=3.45, fourier_cutoff=6, position_cutoff=2, prefactor=1.0) setting.reset() hypercubic_setting.HypercubicSetting(beta=1.0, dimension=1, system_length=1.0) setting.set_number_of_root_nodes(2) setting.set_number_of_nodes_per_root_node(2) setting.set_number_of_node_levels(1) with self.assertRaises(ConfigurationError): MergedImageCoulombPotential(alpha=3.45, fourier_cutoff=6, position_cutoff=2, prefactor=1.0)
def test_integer_casting_number_of_nodes_per_root_node(self): setting.set_number_of_nodes_per_root_node(33.0) self.assertEqual(setting.number_of_nodes_per_root_node, 33) self.assertIsNone(hypercubic_setting.number_of_nodes_per_root_node) self.assertEqual(hypercuboid_setting.number_of_nodes_per_root_node, 33)
def test_number_of_nodes_per_root_node_zero_raises_error(self): with self.assertRaises(AttributeError): setting.set_number_of_nodes_per_root_node(0)
def test_set_number_of_nodes_per_root_node(self): setting.set_number_of_nodes_per_root_node(2) self.assertEqual(setting.number_of_nodes_per_root_node, 2) self.assertIsNone(hypercubic_setting.number_of_nodes_per_root_node) self.assertEqual(hypercuboid_setting.number_of_nodes_per_root_node, 2)