def test_operations_setting(simulation_factory, lattice_snapshot_factory):
    sim = simulation_factory()
    sim.create_state_from_snapshot(lattice_snapshot_factory())

    def check_operation_setting(sim, old_operations, new_operations):
        assert sim.operations is not new_operations
        assert new_operations._simulation is None
        assert old_operations._simulation is sim
        scheduled = old_operations._scheduled
        sim.operations = new_operations
        assert sim.operations is new_operations
        assert new_operations._simulation is sim
        assert old_operations._simulation is None
        if scheduled:
            assert new_operations._scheduled
            assert not old_operations._scheduled

    operations = hoomd.Operations()
    # Add some operations to test the setting
    operations += hoomd.update.BoxResize(trigger=40,
                                         box1=hoomd.Box.cube(10),
                                         box2=hoomd.Box.cube(20),
                                         variant=hoomd.variant.Ramp(
                                             0, 1, 0, 100))
    operations += hoomd.write.GSD(filename="foo.gsd", trigger=10)
    operations += hoomd.write.Table(10,
                                    logger=hoomd.logging.Logger(['scalar']))
    operations.tuners.clear()
    # Check setting before scheduling
    check_operation_setting(sim, sim.operations, operations)

    sim.run(0)
    # Check setting after scheduling
    new_operations = hoomd.Operations()
    new_operations += hoomd.update.BoxResize(trigger=80,
                                             box1=hoomd.Box.cube(300),
                                             box2=hoomd.Box.cube(20),
                                             variant=hoomd.variant.Ramp(
                                                 0, 1, 0, 100))
    new_operations += hoomd.write.GSD(filename="bar.gsd", trigger=20)
    new_operations += hoomd.write.Table(20,
                                        logger=hoomd.logging.Logger(['scalar'
                                                                     ]))
    check_operation_setting(sim, sim.operations, new_operations)
Exemple #2
0
def test_len():
    operations = hoomd.Operations()
    # ParticleSorter automatically added
    assert len(operations) == 1
    operations.tuners.clear()
    assert len(operations) == 0

    operations.integrator = FakeIntegrator()
    operations.updaters.append(
        hoomd.update.FilterUpdater(1, [hoomd.filter.Type(["A"])]))
    operations.writers.append(hoomd.write.GSD(1, "filename.gsd"))

    assert len(operations) == 3
Exemple #3
0
def test_iter():
    operations = hoomd.Operations()
    # ParticleSorter automatically added
    assert len(list(operations)) == 1

    operations.updaters.append(
        hoomd.update.FilterUpdater(1, [hoomd.filter.Type(["A"])]))
    operations.writers.append(hoomd.write.GSD(1, "filename.gsd"))

    expected_list = (operations._tuners[:] + operations._updaters[:] +
                     operations._writers[:])
    assert list(operations) == expected_list

    operations.integrator = FakeIntegrator()
    expected_list.insert(2, operations.integrator)
    assert list(operations) == expected_list