Skip to content

Add get_checkpoint_id() function to simulator_access#6941

Merged
tjhei merged 2 commits into
geodynamics:mainfrom
danieldouglas92:add-checkpoint-id-getter
Apr 27, 2026
Merged

Add get_checkpoint_id() function to simulator_access#6941
tjhei merged 2 commits into
geodynamics:mainfrom
danieldouglas92:add-checkpoint-id-getter

Conversation

@danieldouglas92
Copy link
Copy Markdown
Contributor

This PR creates a function that enables other ASPECT plugins to access the last checkpoint id created by ASPECT. This is something that is currently useful for my postdoc work, and may also be useful to other groups who are coupling ASPECT to external softwares.

Copy link
Copy Markdown
Member

@tjhei tjhei left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ideally, we would return the current checkpoint id while a checkpoint is being written (I know that this is why you want this function 😄 ). Sadly,

last_checkpoint_id = checkpoint_id;

currently happens after we call save:

But we could update the id before instead. Thoughts?

Comment thread include/aspect/simulator_access.h Outdated

/**
* Return the ID of the last checkpoint. This is not the current checkpoint ID
* being written, but the last checkpoint that was written. This is useful for
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please be more specific what this returns if you call this while a checkpoint is being written (inside save inside a plugin)? It might make sense to add a test with a simple plugin that prints this number to the screen.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moving the assignment of last_checkpoint_id made it so that when this function is called within an overrided save() the checkpoint that is about be written is returned!

@danieldouglas92 danieldouglas92 force-pushed the add-checkpoint-id-getter branch 3 times, most recently from 8887998 to 4e6db45 Compare April 23, 2026 02:15
@danieldouglas92 danieldouglas92 force-pushed the add-checkpoint-id-getter branch 4 times, most recently from 8b9a9f2 to 94c5a14 Compare April 23, 2026 14:37
Comment thread tests/get_checkpoint_id.cc Outdated

#include <aspect/simulator.h>

const unsigned int checkpoint_id = this->get_checkpoint_id();
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you have to attach to a signal and print this information during runtime.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see

simulator_access.get_pcout() << "Signal start_timestep triggered!" << std::endl;

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this what was missing?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No. You will need to attach to a signal and print when the signal fires, otherwise you have no SimulatorAccess.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahhh your other comment hadn't loaded for some reason when I asked. I'll take a look at that example

@danieldouglas92 danieldouglas92 force-pushed the add-checkpoint-id-getter branch 4 times, most recently from 7c85f9f to c5bca8f Compare April 24, 2026 19:00
@danieldouglas92
Copy link
Copy Markdown
Contributor Author

@tjhei I'm not sure why the dealii-master tester is failing to compile, but what I have right now shows that the new function gets the checkpoint_id, but the id that gets printed in the test lags behind the actual checkpoint being written because the start_timestep signal obviously happens before checkpointing. I ended up just going with this because it was simpler. I initially tried using the pre_checkpoint_store_user_data signal but this requires a triangulation type to be passed to it which seemed complicated to do in a simple test, plus the signal would still have the same issue given that it happens at line 363 in checkpoint_restart.cc and last_checkpoint_id is updated at line 375.

@danieldouglas92
Copy link
Copy Markdown
Contributor Author

To properly show that it's getting the correct checkpoint_id when this function is meant to be used (in an overridden save() function), I guess I would need to create a new signal?

@tjhei
Copy link
Copy Markdown
Member

tjhei commented Apr 25, 2026

To properly show that it's getting the correct checkpoint_id when this function is meant to be used (in an overridden save() function), I guess I would need to create a new signal?

You just need any plugin that implements save. Something like:

    template <int dim>
    class MyPostprocessor : public Postprocess::Interface<dim>, public ::aspect::SimulatorAccess<dim>
    {
      public:
        /**
         * Generate graphical output from the current solution.
         */
        virtual
        std::pair<std::string,std::string>
        execute (TableHandler &statistics);

        /**
         * Save the state of this object.
         */
        void save (std::map<std::string, std::string> &status_strings) const override;
    };

    template <int dim>
    std::pair<std::string,std::string>
    MyPostprocessor<dim>::execute (TableHandler &statistics)
    {}

    template <int dim>
    void
    MyPostprocessor<dim>::save ([TableHandler &statistics)](std::map<std::string, std::string> &status_strings)
    {
std::cout << this->get_current_checkpoint_id() << std::endl;
}



namespace aspect
{
  namespace Benchmark
  {
    ASPECT_REGISTER_POSTPROCESSOR(MyPostprocessor,
                                  "MyPostprocessor",
                                  "")

Make sure you add this postprocessor to the list of active ones.

@danieldouglas92 danieldouglas92 force-pushed the add-checkpoint-id-getter branch from c5bca8f to be7a37d Compare April 25, 2026 18:17
@danieldouglas92
Copy link
Copy Markdown
Contributor Author

@tjhei Thanks for helping with setting up this test, this should be good now! It shows the current checkpoint id that is being written in the screen output

@danieldouglas92 danieldouglas92 force-pushed the add-checkpoint-id-getter branch from be7a37d to bfc1521 Compare April 25, 2026 18:21
@tjhei tjhei changed the title Add get_last_checkpoint_id() function to simulator_access Add get_checkpoint_id() function to simulator_access Apr 26, 2026
Comment thread include/aspect/simulator_access.h Outdated
get_output_directory () const;

/**
* Return the ID of the checkpoint that ASPECT is currently writing.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* Return the ID of the checkpoint that ASPECT is currently writing.
* Return the ID of the checkpoint that ASPECT is currently writing or was last written.

Comment thread tests/get_checkpoint_id/log.txt Outdated
@@ -0,0 +1,113 @@
-----------------------------------------------------------------------------
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

delete this file

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!

@danieldouglas92 danieldouglas92 force-pushed the add-checkpoint-id-getter branch 3 times, most recently from b96c8ca to 7b231a1 Compare April 26, 2026 20:24
@danieldouglas92 danieldouglas92 force-pushed the add-checkpoint-id-getter branch from 7b231a1 to ceabf63 Compare April 27, 2026 15:07
@tjhei tjhei merged commit f7f8463 into geodynamics:main Apr 27, 2026
8 of 9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants