import hoomd
import io


def test_table_pressure(simulation_factory, two_particle_snapshot_factory):
    """Test that write.table can log MD pressure values."""
    thermo = hoomd.md.compute.ThermodynamicQuantities(hoomd.filter.All())
    snap = two_particle_snapshot_factory()
    if snap.communicator.rank == 0:
        snap.particles.velocity[:] = [[-2, 0, 0], [2, 0, 0]]
    sim = simulation_factory(snap)
    sim.operations.add(thermo)

    integrator = hoomd.md.Integrator(dt=0.0001)
    integrator.methods.append(
        hoomd.md.methods.NVT(hoomd.filter.All(), tau=1, kT=1))
    sim.operations.integrator = integrator

    logger = hoomd.logging.Logger(categories=['scalar'])
    logger.add(thermo)
    output = io.StringIO("")
    table_writer = hoomd.write.Table(1, logger, output)
    sim.operations.writers.append(table_writer)

    sim.run(1)

import hoomd
import io
import numpy


def test_table_pressure(simulation_factory, two_particle_snapshot_factory):
    """Test that write.table can log MD pressure values."""
    thermo = hoomd.md.compute.ThermodynamicQuantities(hoomd.filter.All())
    snap = two_particle_snapshot_factory()
    if snap.communicator.rank == 0:
        snap.particles.velocity[:] = [[-2, 0, 0], [2, 0, 0]]
    sim = simulation_factory(snap)
    sim.operations.add(thermo)

    integrator = hoomd.md.Integrator(dt=0.0)
    integrator.methods.append(
        hoomd.md.methods.NVT(hoomd.filter.All(), tau=1, kT=1))
    sim.operations.integrator = integrator

    logger = hoomd.logging.Logger(categories=['scalar'])
    logger.add(thermo, quantities=['pressure'])
    output = io.StringIO("")
    table_writer = hoomd.write.Table(1, logger, output)
    sim.operations.writers.append(table_writer)

    sim.run(1)

    output_lines = output.getvalue().split('\n')
    ideal_gas_pressure = (2 * thermo.translational_kinetic_energy / 3
                          / sim.state.box.volume)
    numpy.testing.assert_allclose(float(output_lines[1]),
                                  ideal_gas_pressure,
                                  rtol=0.2)

Add output check on the pressure quantity
Add output check on the pressure quantity

  import hoomd
  import io
+ import numpy
  
  
  def test_table_pressure(simulation_factory, two_particle_snapshot_factory):
      """Test that write.table can log MD pressure values."""
      thermo = hoomd.md.compute.ThermodynamicQuantities(hoomd.filter.All())
      snap = two_particle_snapshot_factory()
      if snap.communicator.rank == 0:
          snap.particles.velocity[:] = [[-2, 0, 0], [2, 0, 0]]
      sim = simulation_factory(snap)
      sim.operations.add(thermo)
  
-     integrator = hoomd.md.Integrator(dt=0.0001)
+     integrator = hoomd.md.Integrator(dt=0.0)
      integrator.methods.append(
          hoomd.md.methods.NVT(hoomd.filter.All(), tau=1, kT=1))
      sim.operations.integrator = integrator
  
      logger = hoomd.logging.Logger(categories=['scalar'])
-     logger.add(thermo)
+     logger.add(thermo, quantities=['pressure'])
      output = io.StringIO("")
      table_writer = hoomd.write.Table(1, logger, output)
      sim.operations.writers.append(table_writer)
  
      sim.run(1)
  
+     output_lines = output.getvalue().split('\n')
+     ideal_gas_pressure = (2 * thermo.translational_kinetic_energy / 3
+                           / sim.state.box.volume)
+     numpy.testing.assert_allclose(float(output_lines[1]),
+                                   ideal_gas_pressure,
+                                   rtol=0.2)
+ 
Add output check on the pressure quantity
## Code Before:
import hoomd
import io


def test_table_pressure(simulation_factory, two_particle_snapshot_factory):
    """Test that write.table can log MD pressure values."""
    thermo = hoomd.md.compute.ThermodynamicQuantities(hoomd.filter.All())
    snap = two_particle_snapshot_factory()
    if snap.communicator.rank == 0:
        snap.particles.velocity[:] = [[-2, 0, 0], [2, 0, 0]]
    sim = simulation_factory(snap)
    sim.operations.add(thermo)

    integrator = hoomd.md.Integrator(dt=0.0001)
    integrator.methods.append(
        hoomd.md.methods.NVT(hoomd.filter.All(), tau=1, kT=1))
    sim.operations.integrator = integrator

    logger = hoomd.logging.Logger(categories=['scalar'])
    logger.add(thermo)
    output = io.StringIO("")
    table_writer = hoomd.write.Table(1, logger, output)
    sim.operations.writers.append(table_writer)

    sim.run(1)

## Instruction:
Add output check on the pressure quantity
## Code After:
import hoomd
import io
import numpy


def test_table_pressure(simulation_factory, two_particle_snapshot_factory):
    """Test that write.table can log MD pressure values."""
    thermo = hoomd.md.compute.ThermodynamicQuantities(hoomd.filter.All())
    snap = two_particle_snapshot_factory()
    if snap.communicator.rank == 0:
        snap.particles.velocity[:] = [[-2, 0, 0], [2, 0, 0]]
    sim = simulation_factory(snap)
    sim.operations.add(thermo)

    integrator = hoomd.md.Integrator(dt=0.0)
    integrator.methods.append(
        hoomd.md.methods.NVT(hoomd.filter.All(), tau=1, kT=1))
    sim.operations.integrator = integrator

    logger = hoomd.logging.Logger(categories=['scalar'])
    logger.add(thermo, quantities=['pressure'])
    output = io.StringIO("")
    table_writer = hoomd.write.Table(1, logger, output)
    sim.operations.writers.append(table_writer)

    sim.run(1)

    output_lines = output.getvalue().split('\n')
    ideal_gas_pressure = (2 * thermo.translational_kinetic_energy / 3
                          / sim.state.box.volume)
    numpy.testing.assert_allclose(float(output_lines[1]),
                                  ideal_gas_pressure,
                                  rtol=0.2)
