Skip to content

Properly get number of jobs in information panel#11087

Open
ric394 wants to merge 2 commits into
APSIMInitiative:masterfrom
ric394:11052DisplayCorrectNumberOfSimulations
Open

Properly get number of jobs in information panel#11087
ric394 wants to merge 2 commits into
APSIMInitiative:masterfrom
ric394:11052DisplayCorrectNumberOfSimulations

Conversation

@ric394

@ric394 ric394 commented Mar 12, 2026

Copy link
Copy Markdown
Contributor

resolves #11052

Shows only the actual total number of jobs to be run in the information panel.

@ric394 ric394 added the Ready for Software Review Add this to your pull request when you would like it to be reviewed by the software team label Mar 12, 2026
@ric394 ric394 requested review from Copilot March 12, 2026 05:09

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR addresses issue #11052 by ensuring the “jobs/simulations to run” count shown in the information panel reflects only enabled jobs (excluding disabled simulations).

Changes:

  • Added an Enabled property to IRunnable and implemented it across runnable job types.
  • Updated SimulationGroup to only add enabled jobs to the job manager (affecting job totals and what gets run).
  • Added small forwarding/utility enablement properties on some simulation-related types.

Reviewed changes

Copilot reviewed 15 out of 15 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
Tests/UnitTests/APSIMShared/MockJob.cs Implements new IRunnable.Enabled contract for unit test job stubs.
Models/Storage/WriteTableCommand.cs Implements Enabled for datastore write command jobs.
Models/Storage/RevertCheckpointCommand.cs Implements Enabled for datastore revert command jobs.
Models/Storage/EmptyCommand.cs Implements Enabled for datastore empty command jobs.
Models/Storage/DeleteRowsCommand.cs Implements Enabled for datastore delete-rows command jobs.
Models/Storage/DeleteCheckpointCommand.cs Implements Enabled for datastore delete-checkpoint command jobs.
Models/Storage/CleanCommand.cs Implements Enabled for datastore clean command jobs.
Models/Storage/AddCheckpointCommand.cs Implements Enabled for datastore add-checkpoint command jobs.
Models/Core/Simulation.cs Adds IsEnabled forwarding property (in addition to existing Enabled).
Models/Core/Run/SimulationGroup.cs Filters runnable jobs by job.Enabled before adding to the run queue.
Models/Core/Run/SimulationDescription.cs Exposes Enabled for a simulation description (currently unsafe for null base simulation).
Models/Core/Run/EmptyJob.cs Implements Enabled for the placeholder “no jobs” runnable.
APSIM.Shared/JobRunning/JobRunnerSleepJob.cs Implements Enabled for sleep job.
APSIM.Shared/JobRunning/JobManager.cs Reorders using directives (no functional change).
APSIM.Shared/JobRunning/IRunnable.cs Extends IRunnable with a new Enabled property.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

}

/// <summary>Returns true if the job is enabled.</summary>
public bool Enabled => baseSimulation.Enabled;

Copilot AI Mar 12, 2026

Copy link

Choose a reason for hiding this comment

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

SimulationDescription.Enabled dereferences baseSimulation without a null check, but SimulationDescription is constructed with sim == null in several places (e.g. graph descriptor splitting and unit tests). This will throw NullReferenceException as soon as any caller reads Enabled (including the new filtering logic). Consider returning a safe default when baseSimulation is null (or store an explicit enabled flag on the description).

Suggested change
public bool Enabled => baseSimulation.Enabled;
public bool Enabled => baseSimulation?.Enabled ?? true;

Copilot uses AI. Check for mistakes.
Comment on lines 289 to +293
storage.Writer.Clean(names, false);
}
foreach (IRunnable job in jobs)
Add(job);
if (job.Enabled)
Add(job);

Copilot AI Mar 12, 2026

Copy link

Choose a reason for hiding this comment

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

The datastore clean step builds names from all jobs, including those which will now be skipped due to job.Enabled == false. This can delete existing results for disabled simulations which aren't actually going to be run. Consider filtering jobs by Enabled (or checking Enabled when collecting names) so only enabled simulations are cleaned.

Copilot uses AI. Check for mistakes.
Comment on lines 291 to +293
foreach (IRunnable job in jobs)
Add(job);
if (job.Enabled)
Add(job);

Copilot AI Mar 12, 2026

Copy link

Choose a reason for hiding this comment

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

The new job.Enabled filter changes which simulations/jobs are added to the run. Given this is user-visible (fixes the info panel counter) and affects execution, it would be good to add a unit test covering a disabled simulation/job not contributing to the total and not being executed (e.g. in existing RunnerTests).

Copilot uses AI. Check for mistakes.
Comment on lines +16 to +18
/// <summary> Returns true if the job is enabled</summary>
bool Enabled { get; }

Copilot AI Mar 12, 2026

Copy link

Choose a reason for hiding this comment

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

Adding Enabled to the public IRunnable interface is a breaking API change for any external implementers of IRunnable (source/binary). If this interface is used outside this repo, consider a non-breaking alternative (e.g. a new optional interface like IEnableableRunnable, an extension method, or a default interface implementation if the project targets a language/runtime which supports it).

Copilot uses AI. Check for mistakes.
Comment thread Models/Core/Simulation.cs
Comment on lines +100 to +102
/// <summary>Is Enabled?</summary>
public bool IsEnabled => Enabled;

Copilot AI Mar 12, 2026

Copy link

Choose a reason for hiding this comment

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

Simulation.IsEnabled is a new public property which just forwards to the existing Enabled property from Model. Since it isn’t referenced elsewhere in the codebase, it adds API surface area without changing behaviour; consider removing it and using Enabled directly to avoid confusion/duplication.

Suggested change
/// <summary>Is Enabled?</summary>
public bool IsEnabled => Enabled;

Copilot uses AI. Check for mistakes.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

@par456

par456 commented Mar 30, 2026

Copy link
Copy Markdown
Collaborator

I think this can be done in a much simpler way. Rather than extend IRunnable, how about instead in SimulationGroup, check if the job is of type Simulation, if it is, cast it to a Simumlation and check the enabled status. If it is not, just add it to the list. That'll make this much cleaner.

@par456 par456 added Contributor Action Required Denotes a PR requiring further contribution from a contributor and removed Ready for Software Review Add this to your pull request when you would like it to be reviewed by the software team labels Mar 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Contributor Action Required Denotes a PR requiring further contribution from a contributor

Projects

None yet

Development

Successfully merging this pull request may close these issues.

The simulations counter includes disabled simulations

3 participants