def test_number_of_node_levels_one_raises_error(self):
     setting.reset()
     setting.HypercubicSetting(beta=1.0, dimension=3, system_length=1.0)
     setting.set_number_of_node_levels(1)
     with self.assertRaises(ConfigurationError):
         self._event_handler_to_root_unit_motion = RootLeafUnitActiveSwitcher(
             chain_length=0.5, aim_mode="leaf_unit_active")
Exemple #2
0
 def test_separation_vector_system_length_two(self):
     setting.HypercubicSetting(beta=1.0, dimension=3, system_length=2.0)
     position_one = [1.7, 0.1, 1.5]
     position_two = [0.4, 1.0, 1.4]
     self.assertAlmostEqualList(
         setting.periodic_boundaries.separation_vector(
             position_one, position_two), [0.7, 0.9, -0.1])
Exemple #3
0
 def setUp(self) -> None:
     # Build up two dipoles to test everything
     self._root_nodes = [Node(), Node()]
     self._root_nodes[0].add_child(
         Node(Particle(position=[0, 0], charge={"e": 1})))
     self._root_nodes[0].add_child(
         Node(Particle(position=[0.1, 0.05], charge={"e": -1})))
     self._root_nodes[1].add_child(
         Node(Particle(position=[0.9, 0.8], charge={"e": 1})))
     self._root_nodes[1].add_child(
         Node(Particle(position=[0.9, 0.75], charge={"e": -1})))
     for node in self._root_nodes:
         position = [
             sum(leaf_node.value.position[index] * leaf_node.weight
                 for leaf_node in node.children) for index in range(2)
         ]
         node.value = Particle(position=position)
     setting.HypercubicSetting(beta=1.0, dimension=3, system_length=1.0)
     setting.number_of_node_levels = 2
     setting.number_of_root_nodes = 2
     setting.number_of_nodes_per_root_node = 2
     # Test the combination used throughout the application in JFV 1.0.0.0
     physical_state = TreePhysicalState()
     lifting_state = TreeLiftingState()
     self._state_handler = TreeStateHandler(physical_state, lifting_state)
 def setUp(self) -> None:
     setting.HypercubicSetting(beta=1.0, dimension=3, system_length=1.0)
     setting.set_number_of_node_levels(2)
     self._event_handler_to_root_unit_motion = RootLeafUnitActiveSwitcher(
         chain_length=0.5, aim_mode="root_unit_active")
     self._event_handler_to_leaf_unit_motion = RootLeafUnitActiveSwitcher(
         chain_length=0.7, aim_mode="leaf_unit_active")
Exemple #5
0
 def test_integer_casting_dimension(self):
     setting.reset()
     # noinspection PyTypeChecker
     setting.HypercubicSetting(beta=1.0, dimension=2.8, system_length=1.0)
     self.assertEqual(setting.dimension, 2)
     self.assertEqual(hypercubic_setting.dimension, 2)
     self.assertEqual(hypercuboid_setting.dimension, 2)
Exemple #6
0
    def setUp(self) -> None:
        setting.HypercubicSetting(beta=1.0, dimension=2, system_length=1.0)
        setting.set_number_of_node_levels(1)
        self._estimator_without_charge_mock = mock.MagicMock(
            spec_set=Estimator)
        self._estimator_without_charge_mock.derivative_bound.side_effect = mock_derivative_bound
        self._estimator_with_charge_mock = mock.MagicMock(spec_set=Estimator)
        self._estimator_with_charge_mock.derivative_bound.side_effect = mock_derivative_bound
        # Mock a 4 * 4 cell system
        cells_mock = mock.MagicMock(spec_set=Cells)
        cells_mock.yield_cells.side_effect = [
            iter([i for i in range(16)]) for _ in range(2)
        ]
        cells_mock.cell_min.side_effect = mock_cell_min
        cells_mock.cell_max.side_effect = mock_cell_max
        cells_mock.excluded_cells = mock_excluded_cells
        self._cell_bounding_potential_without_charge = CellBoundingPotential(
            estimator=self._estimator_without_charge_mock)
        self._cell_bounding_potential_with_charge = CellBoundingPotential(
            estimator=self._estimator_with_charge_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(
                    cells_mock, 1.0, False)
                self._cell_bounding_potential_with_charge.initialize(
                    cells_mock, 2.0, True)
Exemple #7
0
 def test_separation_vector_system_length_one(self):
     setting.HypercubicSetting(beta=1.0, dimension=3, system_length=1.0)
     position_one = [0.5, 0.6, 0.3]
     position_two = [0.2, 0.1, 0.9]
     self.assertAlmostEqualList(
         setting.periodic_boundaries.separation_vector(
             position_one, position_two), [-0.3, -0.5, -0.4],
         places=13)
Exemple #8
0
 def setUp(self) -> None:
     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)
Exemple #9
0
 def test_dimension_unequal_three_raises_error(self):
     setting.reset()
     setting.HypercubicSetting(beta=1.0, dimension=2, system_length=1.0)
     setting.dimension = 2
     with self.assertRaises(ConfigurationError):
         MergedImageCoulombPotential(alpha=3.45,
                                     fourier_cutoff=6,
                                     position_cutoff=2,
                                     prefactor=1.0)
     setting.reset()
     setting.HypercubicSetting(beta=1.0, dimension=1, system_length=1.0)
     setting.dimension = 1
     with self.assertRaises(ConfigurationError):
         MergedImageCoulombPotential(alpha=3.45,
                                     fourier_cutoff=6,
                                     position_cutoff=2,
                                     prefactor=1.0)
 def setUp(self) -> None:
     setting.HypercubicSetting(beta=1.0, dimension=3, system_length=1.0)
     self._event_handler_one = InitialChainStartOfRunEventHandler(
         initial_direction_of_motion=0,
         speed=1.0,
         initial_active_identifier=[0])
     self._event_handler_two = InitialChainStartOfRunEventHandler(
         initial_direction_of_motion=2,
         speed=0.5,
         initial_active_identifier=[0, 1])
Exemple #11
0
 def test_correct_periodic_boundary_separation_length_half(self):
     setting.HypercubicSetting(beta=1.0, dimension=4, system_length=0.5)
     separation = [-0.25, -0.3, 0.4, 0.25]
     setting.periodic_boundaries.correct_separation(separation)
     self.assertAlmostEqualList(separation, [-0.25, 0.2, -0.1, -0.25],
                                places=13)
     separation = [-0.1, 0.1, 0.0, 0.05]
     setting.periodic_boundaries.correct_separation(separation)
     self.assertAlmostEqualList(separation, [-0.1, 0.1, 0.0, 0.05],
                                places=13)
Exemple #12
0
 def test_correct_periodic_boundary_separation_entry_length_one(self):
     setting.HypercubicSetting(beta=1.0, dimension=4, system_length=1.0)
     separation = [-0.5, -0.3, 0.4, 0.5]
     separation[3] = setting.periodic_boundaries.correct_separation_entry(
         separation[3], 3)
     self.assertAlmostEqualList(separation, [-0.5, -0.3, 0.4, -0.5],
                                places=13)
     separation = [-0.6, 1.3, 0.4, 0.9]
     separation[0] = setting.periodic_boundaries.correct_separation_entry(
         separation[0], 0)
     self.assertAlmostEqualList(separation, [0.4, 1.3, 0.4, 0.9], places=13)
Exemple #13
0
 def setUp(self) -> None:
     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)
     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)
Exemple #14
0
 def test_correct_periodic_boundary_separation_length_one(self):
     setting.HypercubicSetting(beta=1.0, dimension=4, system_length=1.0)
     separation = [-0.5, -0.3, 0.4, 0.5]
     setting.periodic_boundaries.correct_separation(separation)
     self.assertAlmostEqualList(separation, [-0.5, -0.3, 0.4, -0.5],
                                places=13)
     separation = [-0.6, 1.3, 0.4, 0.9]
     setting.periodic_boundaries.correct_separation(separation)
     self.assertAlmostEqualList(separation, [0.4, 0.3, 0.4, -0.1],
                                places=13)
     setting.system_length = None
     setting.system_length_over_two = None
     setting.dimension = None
 def setUp(self) -> None:
     setting.HypercubicSetting(beta=1.0, dimension=2, system_length=1.0)
     self._potential_mock_without_charge = mock.MagicMock(
         spec_set=InvertiblePotential)
     self._potential_mock_without_charge.number_separation_arguments = 1
     self._potential_mock_without_charge.number_charge_arguments = 0
     self._potential_mock_with_charge = mock.MagicMock(
         spec_set=InvertiblePotential)
     self._potential_mock_with_charge.number_separation_arguments = 1
     self._potential_mock_with_charge.number_charge_arguments = 2
     self._event_handler_without_charge = TwoLeafUnitEventHandler(
         potential=self._potential_mock_without_charge)
     self._event_handler_with_charge = TwoLeafUnitEventHandler(
         potential=self._potential_mock_with_charge, charge="charge")
Exemple #16
0
 def test_correct_periodic_boundary_position_system_length_two(self):
     setting.HypercubicSetting(beta=1.0, dimension=3, system_length=2.0)
     position = [0.1, 1.4, 1.9]
     setting.periodic_boundaries.correct_position(position)
     self.assertEqual(position, [0.1, 1.4, 1.9])
     position = [0.0, 0.4, 2.0]
     setting.periodic_boundaries.correct_position(position)
     self.assertAlmostEqualList(position, [0.0, 0.4, 0.0])
     position = [-0.3, 1.4, 3.9]
     setting.periodic_boundaries.correct_position(position)
     self.assertAlmostEqualList(position, [1.7, 1.4, 1.9], places=13)
     position = [-10.0, 102.231, 0.999999]
     setting.periodic_boundaries.correct_position(position)
     self.assertAlmostEqualList(position, [0.0, 0.231, 0.999999], places=13)
Exemple #17
0
 def test_correct_periodic_boundary_position_entry_system_length_one(self):
     setting.HypercubicSetting(beta=1.0, dimension=3, system_length=1.0)
     position = [0.1, 0.4, 0.9]
     position[0] = setting.periodic_boundaries.correct_position_entry(
         position[0], 0)
     self.assertEqual(position, [0.1, 0.4, 0.9])
     position = [0.0, 0.4, 1.0]
     position[1] = setting.periodic_boundaries.correct_position_entry(
         position[1], 1)
     self.assertAlmostEqualList(position, [0.0, 0.4, 1.0], places=13)
     position = [-0.3, 1.4, 3.9]
     position[2] = setting.periodic_boundaries.correct_position_entry(
         position[2], 2)
     self.assertAlmostEqualList(position, [-0.3, 1.4, 0.9], places=13)
     position = [-10.0, 102.231, 0.999999]
     position[1] = setting.periodic_boundaries.correct_position_entry(
         position[1], 1)
     self.assertAlmostEqualList(position, [-10.0, 0.231, 0.999999],
                                places=13)
    def setUp(self) -> None:
        setting.HypercubicSetting(beta=1.0, dimension=2, system_length=1.0)
        # Set this for the initial extraction of charge
        setting.set_number_of_node_levels(1)

        self._estimator_without_charge_mock = mock.MagicMock(
            spec_set=Estimator)
        self._estimator_without_charge_mock.derivative_bound.side_effect = mock_derivative_bound
        self._estimator_with_charge_mock = mock.MagicMock(spec_set=Estimator)
        self._estimator_with_charge_mock.derivative_bound.side_effect = mock_derivative_bound
        # Mock a 4 * 4 cell system
        cells_mock = mock.MagicMock(spec_set=PeriodicCells)
        cells_mock.yield_cells.side_effect = [
            iter([i for i in range(16)]) for _ in range(4)
        ]
        cells_mock.cell_min.side_effect = mock_cell_min
        cells_mock.cell_max.side_effect = mock_cell_max
        cells_mock.excluded_cells = mock_excluded_cells
        self._estimator_without_charge_mock.potential.number_separation_arguments = 1
        self._estimator_without_charge_mock.potential.number_charge_arguments = 0
        self._estimator_with_charge_mock.potential.number_separation_arguments = 1
        self._estimator_with_charge_mock.potential.number_charge_arguments = 2
        self._event_handler_without_charge = LeafUnitCellVetoEventHandler(
            estimator=self._estimator_without_charge_mock)
        self._event_handler_with_charge = LeafUnitCellVetoEventHandler(
            estimator=self._estimator_with_charge_mock, charge="charge")

        # relevant id length will be set later in each test
        root_cnodes = [
            Node(
                Unit(identifier=(0, ),
                     position=[0.1, 0.2, 0.3],
                     charge={"charge": 2.0}))
        ]
        # Redirect stdout to the null device while initializing the estimator
        with open(os.devnull, 'w') as devnull:
            with contextlib.redirect_stdout(devnull):
                self._event_handler_without_charge.initialize(
                    cells_mock, None, root_cnodes)
                self._event_handler_with_charge.initialize(
                    cells_mock, None, root_cnodes)
Exemple #19
0
    def setUp(self) -> None:
        setting.HypercubicSetting(beta=1.0, dimension=2, system_length=1.0)
        self._potential_mock_without_charge = mock.MagicMock(
            spec_set=Potential)
        self._potential_mock_without_charge.number_separation_arguments = 1
        self._potential_mock_without_charge.number_charge_arguments = 0
        self._cell_bounding_potential_mock_without_charge = mock.MagicMock(
            spec_set=CellBoundingPotential)
        self._cell_bounding_potential_mock_without_charge.number_separation_arguments = 1
        self._cell_bounding_potential_mock_without_charge.number_charge_arguments = 0
        self._event_handler_without_charge = TwoLeafUnitCellBoundingPotentialEventHandler(
            potential=self._potential_mock_without_charge,
            bounding_potential=self.
            _cell_bounding_potential_mock_without_charge)

        self._potential_mock_with_charge = mock.MagicMock(spec_set=Potential)
        self._potential_mock_with_charge.number_separation_arguments = 1
        self._potential_mock_with_charge.number_charge_arguments = 2
        self._cell_bounding_potential_mock_with_charge = mock.MagicMock(
            spec_set=CellBoundingPotential)
        self._cell_bounding_potential_mock_with_charge.number_separation_arguments = 1
        self._cell_bounding_potential_mock_with_charge.number_charge_arguments = 2
        self._event_handler_with_charge = TwoLeafUnitCellBoundingPotentialEventHandler(
            potential=self._potential_mock_with_charge,
            bounding_potential=self._cell_bounding_potential_mock_with_charge,
            charge="charge")
        self._cells_mock = mock.MagicMock(spec_set=PeriodicCells)
        root_cnodes = [
            Node(
                Unit(identifier=(0, ),
                     position=[0.1, 0.2, 0.3],
                     charge={"charge": 2.0}))
        ]
        self._event_handler_without_charge.initialize(self._cells_mock,
                                                      root_cnodes)
        self._event_handler_with_charge.initialize(self._cells_mock,
                                                   root_cnodes)
Exemple #20
0
 def setUp(self) -> None:
     setting.HypercubicSetting(beta=2, dimension=5, system_length=1.5)
 def setUp(self) -> None:
     setting.HypercubicSetting(beta=1.0, dimension=3, system_length=1.0)
     self._event_handler = SameActivePeriodicDirectionEndOfChainEventHandler(chain_length=0.7)
 def setUp(self) -> None:
     setting.HypercubicSetting(beta=1.0, dimension=3, system_length=1.0)
     self._event_handler_one = FixedIntervalDumpingEventHandler(dumping_interval=0.5,
                                                                output_handler="some_output_handler")
     self._event_handler_two = FixedIntervalDumpingEventHandler(dumping_interval=1.3, output_handler="output")
Exemple #23
0
 def setUp(self) -> None:
     setting.HypercubicSetting(beta=1.0, dimension=2, system_length=1.0)
     self._cells_mock = mock.MagicMock(spec_set=Cells)
     self._event_handler = CellBoundaryEventHandler()
Exemple #24
0
 def test_next_image_length_two(self):
     setting.HypercubicSetting(beta=1.0, dimension=3, system_length=2.0)
     self.assertEqual(setting.periodic_boundaries.next_image(1.9, 1), 3.9)
Exemple #25
0
 def test_dimension_zero_raises_error(self):
     setting.reset()
     with self.assertRaises(AttributeError):
         setting.HypercubicSetting(beta=1, dimension=0, system_length=1.0)
Exemple #26
0
 def setUp(self) -> None:
     setting.HypercubicSetting(beta=1.0, dimension=3, system_length=1.0)
     self._event_handler_one = FinalTimeEndOfRunEventHandler(end_of_run_time=0.5,
                                                             output_handler="some_output_handler")
     self._event_handler_two = FinalTimeEndOfRunEventHandler(end_of_run_time=1.3, output_handler="output")
Exemple #27
0
 def test_next_image_length_one(self):
     setting.HypercubicSetting(beta=1.0, dimension=3, system_length=1.0)
     self.assertEqual(setting.periodic_boundaries.next_image(0.4, 0), 1.4)
 def test_new_initialize_hypercubic_setting_raises_error(self):
     with self.assertRaises(AttributeError):
         setting.HypercubicSetting(beta=1.0, dimension=3, system_length=1.0)
Exemple #29
0
 def test_negative_system_length_raises_error(self):
     setting.reset()
     with self.assertRaises(AttributeError):
         setting.HypercubicSetting(beta=1, dimension=3, system_length=-3.2)