Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix visualisation crashes in notebooks #21

Closed
4 tasks done
kwabenantim opened this issue Jun 27, 2023 · 2 comments · Fixed by #30
Closed
4 tasks done

Fix visualisation crashes in notebooks #21

kwabenantim opened this issue Jun 27, 2023 · 2 comments · Fixed by #30
Assignees
Labels
bug Something isn't working

Comments

@kwabenantim
Copy link
Member

kwabenantim commented Jun 27, 2023

Description
PyChaste visualisations crash routinely in notebooks.

To Do

  • Reproduce problem.
  • Fix problem (if possible).
  • Recover gently from unavoidable crashes.
  • Add additional tests if necessary.
@kwabenantim
Copy link
Member Author

kwabenantim commented Aug 4, 2023

To Reproduce

import chaste
from chaste.cell_based import (
    CellsGeneratorNoCellCycleModel_2,
    ConstantTargetAreaModifier2,
    DifferentiatedCellProliferativeType,
    FarhadifarForce2,
    OffLatticeSimulation2_2,
    SetupNotebookTest, 
    VertexBasedCellPopulation2
)
from chaste.core import RandomNumberGenerator
from chaste.mesh import VoronoiVertexMeshGenerator
from chaste.visualization import JupyterNotebookManager, VtkScene2

chaste.init()
SetupNotebookTest()
RandomNumberGenerator.Instance().Reseed(1)
generator = chaste.mesh.VoronoiVertexMeshGenerator(6, 6, 1)
mesh = generator.GetMesh()
mesh.SetDistanceForT3SwapChecking(1.0)

cell_type = DifferentiatedCellProliferativeType()
cell_generator = CellsGeneratorNoCellCycleModel_2()
cells = cell_generator.GenerateBasicRandom(mesh.GetNumElements(), cell_type)

cell_population = VertexBasedCellPopulation2(mesh, cells)
cell_population.AddCellWriterCellVolumesWriter()
scene = VtkScene2()
scene.SetCellPopulation(cell_population)
nb_manager = JupyterNotebookManager()
nb_manager.vtk_show(scene, height=300)

Displays image in notebook here.

simulation = OffLatticeSimulation2_2(cell_population)

output_path = "Results"
file_handler = chaste.core.OutputFileHandler(output_path)
simulation.SetOutputDirectory(output_path)

simulation.SetEndTime(100)
simulation.SetDt(0.01)
simulation.SetSamplingTimestepMultiple(10)

force = FarhadifarForce2()
force.SetAreaElasticityParameter(1.0)
force.SetPerimeterContractilityParameter(0.04)
force.SetLineTensionParameter(0.12)
force.SetBoundaryLineTensionParameter(0.12)
simulation.AddForce(force)

target_area_modifier = ConstantTargetAreaModifier2()
simulation.AddSimulationModifier(target_area_modifier)

simulation.Solve()
nb_manager.vtk_show(scene, height=300)

Displays image in notebook here.

scene = VtkScene2()
scene.SetCellPopulation(simulation.rGetCellPopulation())
nb_manager.vtk_show(scene, height=300)

Jupyter kernel dies here. Colab displays image in notebook here.

scene = VtkScene2()
scene.SetCellPopulation(simulation.rGetCellPopulation())
nb_manager.vtk_show(scene, height=300)

Colab kernel dies here.

@kwabenantim
Copy link
Member Author

Fix

Reset renderer list after each call to JupyterNotebookManager::vtk_show():

self.renderWindow.RemoveRenderer(renderer)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant