Skip to content

Commit

Permalink
Ignore Simulation::getSimulationConfig from python/swig wrapping
Browse files Browse the repository at this point in the history
Closes #689
  • Loading branch information
ptheywood committed Sep 8, 2021
1 parent 0bdc908 commit 1d3889c
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 24 deletions.
2 changes: 1 addition & 1 deletion swig/python/flamegpu.i
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ class FLAMEGPURuntimeException : public std::exception {
// Ignore const'd accessors for configuration structs, which were mutable in python.
%ignore flamegpu::CUDASimulation::getCUDAConfig;
%ignore flamegpu::CUDAEnsemble::getConfig;
// %ignore flamegpu::Simulation::getConfig; // This doesn't currently exist
%ignore flamegpu::Simulation::getSimulationConfig; // This doesn't currently exist

// Ignore the detail namespace, as it's not intended to be user-facing
%ignore flamegpu::detail;
Expand Down
44 changes: 26 additions & 18 deletions tests/swig/python/gpu/test_cuda_simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,77 +38,77 @@ def test_argparse_inputfile_long(self):
m = pyflamegpu.ModelDescription("test_argparse_inputfile_long")
c = pyflamegpu.CUDASimulation(m)
argv = [ "prog.exe", "--in", "test" ]
assert c.getSimulationConfig().input_file == ""
assert c.SimulationConfig().input_file == ""
with pytest.raises(pyflamegpu.FLAMEGPURuntimeException) as e: # exception::UnsupportedFileType exception
c.initialise(argv)
assert e.value.type() == "UnsupportedFileType"
assert c.getSimulationConfig().input_file == argv[2]
assert c.SimulationConfig().input_file == argv[2]
# Blank init resets value to default
argv = []
c.initialise(argv)
assert c.getSimulationConfig().input_file == ""
assert c.SimulationConfig().input_file == ""

def test_argparse_inputfile_short(self):
m = pyflamegpu.ModelDescription("test_argparse_inputfile_short")
c = pyflamegpu.CUDASimulation(m)
argv = [ "prog.exe", "-i", "I_DO_NOT_EXIST.xml" ]
assert c.getSimulationConfig().input_file == ""
assert c.SimulationConfig().input_file == ""
with pytest.raises(pyflamegpu.FLAMEGPURuntimeException) as e: # exception::InvalidInputFile
c.initialise(argv)
assert e.value.type() == "InvalidInputFile"
assert c.getSimulationConfig().input_file == argv[2]
assert c.SimulationConfig().input_file == argv[2]
# Blank init resets value to default
argv = []
c.initialise(argv)
assert c.getSimulationConfig().input_file == ""
assert c.SimulationConfig().input_file == ""

def test_argparse_steps_long(self):
m = pyflamegpu.ModelDescription("test_argparse_steps_long")
c = pyflamegpu.CUDASimulation(m)
argv = [ "prog.exe", "--steps", "12" ]
assert c.getSimulationConfig().steps == 1
assert c.SimulationConfig().steps == 1
c.initialise(argv)
assert c.getSimulationConfig().steps == 12
assert c.SimulationConfig().steps == 12
# Blank init resets value to default
argv = []
c.initialise(argv)
assert c.getSimulationConfig().steps == 1
assert c.SimulationConfig().steps == 1

def test_argparse_steps_short(self):
m = pyflamegpu.ModelDescription("test_argparse_steps_short")
c = pyflamegpu.CUDASimulation(m)
argv = [ "prog.exe", "-s", "12" ]
assert c.getSimulationConfig().steps == 1
assert c.SimulationConfig().steps == 1
c.initialise(argv)
assert c.getSimulationConfig().steps == 12
assert c.SimulationConfig().steps == 12
# Blank init resets value to default
argv = []
c.initialise(argv)
assert c.getSimulationConfig().steps == 1
assert c.SimulationConfig().steps == 1

def test_argparse_randomseed_long(self):
m = pyflamegpu.ModelDescription("test_argparse_randomseed_long")
c = pyflamegpu.CUDASimulation(m)
argv = [ "prog.exe", "--random", "12" ]
assert c.getSimulationConfig().random_seed != 12
assert c.SimulationConfig().random_seed != 12
c.initialise(argv)
assert c.getSimulationConfig().random_seed == 12
assert c.SimulationConfig().random_seed == 12
# Blank init resets value to default
argv = []
c.initialise(argv)
assert c.getSimulationConfig().random_seed != 12
assert c.SimulationConfig().random_seed != 12

def test_argparse_randomseed_short(self):
m = pyflamegpu.ModelDescription("test_argparse_randomseed_short")
c = pyflamegpu.CUDASimulation(m)
argv = [ "prog.exe", "-r", "12" ]
assert c.getSimulationConfig().random_seed != 12
assert c.SimulationConfig().random_seed != 12
c.initialise(argv)
assert c.getSimulationConfig().random_seed == 12
assert c.SimulationConfig().random_seed == 12
# Blank init resets value to default
argv = []
c.initialise(argv)
assert c.getSimulationConfig().random_seed != 12
assert c.SimulationConfig().random_seed != 12

def test_argparse_device_long(self):
m = pyflamegpu.ModelDescription("test_argparse_device_long")
Expand Down Expand Up @@ -405,3 +405,11 @@ def test_AgentID_MultipleStatesUniqueIDs(self):

assert len(ids_original) == len(pop_out_a) + len(pop_out_b)
assert len(ids_copy) == len(pop_out_a) + len(pop_out_b)


# Ensure that Simulation::getSimulationConfig() is disabled, as it would be mutable
def test_ignored_getSimulationConfig(self):
m = pyflamegpu.ModelDescription("test_ignored_getSimulationConfig")
c = pyflamegpu.CUDASimulation(m)
with pytest.raises(AttributeError):
c.getSimulationConfig()
10 changes: 5 additions & 5 deletions tests/swig/python/io/test_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,11 +227,11 @@ def io_test_fixture(IO_FILENAME):
am.SimulationConfig().input_file = IO_FILENAME
am.applyConfig()
# Validate config matches
assert am.getSimulationConfig().random_seed == 654321
assert am.getSimulationConfig().steps == 123
assert am.getSimulationConfig().timing == True
assert am.getSimulationConfig().verbose == False
assert am.getSimulationConfig().input_file == IO_FILENAME
assert am.SimulationConfig().random_seed == 654321
assert am.SimulationConfig().steps == 123
assert am.SimulationConfig().timing == True
assert am.SimulationConfig().verbose == False
assert am.SimulationConfig().input_file == IO_FILENAME
assert am.CUDAConfig().device_id == 0;
pop_a_in = pyflamegpu.AgentVector(a)
pop_b_in = pyflamegpu.AgentVector(b)
Expand Down

0 comments on commit 1d3889c

Please sign in to comment.