Class AbstractSpartanModel<SpartanModelConfigType extends org.spartan.api.engine.config.SpartanModelConfig>
java.lang.Object
org.spartan.internal.engine.model.AbstractSpartanModel<SpartanModelConfigType>
- All Implemented Interfaces:
AutoCloseable, org.spartan.api.engine.SpartanModel<SpartanModelConfigType>
- Direct Known Subclasses:
AutoEncoderCompressorModelImpl, CuriosityDrivenRecurrentSoftActorCriticModelImpl, DoubleDeepQNetworkModelImpl, ProximalPolicyOptimizationSpartanModelImpl, RecurrentSoftActorCriticModelImpl
public abstract class AbstractSpartanModel<SpartanModelConfigType extends org.spartan.api.engine.config.SpartanModelConfig>
extends Object
implements org.spartan.api.engine.SpartanModel<SpartanModelConfigType>
Abstract base for SpartanModel with FFM memory management and Zero-GC tick().
The tick() method contains NO allocations - safe for high-frequency calls. Scalar parameters (agentId, counts) are now passed as primitives directly to C++.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final intprotected final MemorySegmentprotected final longprotected final Arenaprotected final SpartanModelConfigTypeprotected final MemorySegmentprotected final org.spartan.api.engine.context.SpartanContextprotected final Stringprotected final MemorySegmentprotected final intprotected static final intSIMD padding in number of doubles. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedAbstractSpartanModel(@NotNull String identifier, long agentIdentifier, SpartanModelConfigType config, @NotNull org.spartan.api.engine.context.SpartanContext context, @NotNull Arena sharedArena, long modelWeightCount, long configSegmentSize, int actionSize) -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()@NotNull org.spartan.api.engine.SpartanModel<SpartanModelConfigType> voidprotected voidexecuteNativeTick(double reward) @NotNull MemorySegmentlongprotected abstract @NotNull MemorySegmentprotected abstract intdouble@NotNull Stringprotected abstract org.spartan.api.engine.config.SpartanModelTypeReturns the model type for this instance.@NotNull MemorySegment@NotNull org.spartan.api.engine.context.SpartanContextbooleanvoidprotected voidvoidregister()protected voidrelease()Unregisters from C++ and releases resources.protected static intrequireContextSize(@NotNull org.spartan.api.engine.context.SpartanContext context) voidvoidvoidsetLiveExplorationRate(double newEpsilon) voidtick()protected abstract void
-
Field Details
-
SIMD_PADDING_DOUBLES
protected static final int SIMD_PADDING_DOUBLESSIMD padding in number of doubles.The C++ native code uses SIMD operations To prevent SIMD overreads from causing access violations when buffers end at page boundaries, we add significant padding to all buffer allocations. Increased from 4 to 128 to provide maximum safety margin.
- See Also:
-
arena
-
agentIdentifier
protected final long agentIdentifier -
config
protected final SpartanModelConfigType extends org.spartan.api.engine.config.SpartanModelConfig config -
context
protected final org.spartan.api.engine.context.SpartanContext context -
configSegment
-
modelWeightsBuffer
-
actionOutputBuffer
-
modelWeightsCount
protected final int modelWeightsCount -
actionCount
protected final int actionCount -
identifier
-
-
Constructor Details
-
AbstractSpartanModel
protected AbstractSpartanModel(@NotNull @NotNull String identifier, long agentIdentifier, @NotNull SpartanModelConfigType config, @NotNull @NotNull org.spartan.api.engine.context.SpartanContext context, @NotNull @NotNull Arena sharedArena, long modelWeightCount, long configSegmentSize, int actionSize)
-
-
Method Details
-
requireContextSize
protected static int requireContextSize(@NotNull @NotNull org.spartan.api.engine.context.SpartanContext context) -
register
public void register()- Specified by:
registerin interfaceorg.spartan.api.engine.SpartanModel<SpartanModelConfigType extends org.spartan.api.engine.config.SpartanModelConfig>
-
tick
public void tick()- Specified by:
tickin interfaceorg.spartan.api.engine.SpartanModel<SpartanModelConfigType extends org.spartan.api.engine.config.SpartanModelConfig>
-
executeNativeTick
protected void executeNativeTick(double reward) -
postTickActions
protected void postTickActions() -
close
public void close()- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceorg.spartan.api.engine.SpartanModel<SpartanModelConfigType extends org.spartan.api.engine.config.SpartanModelConfig>
-
getAgentIdentifier
public long getAgentIdentifier()- Specified by:
getAgentIdentifierin interfaceorg.spartan.api.engine.SpartanModel<SpartanModelConfigType extends org.spartan.api.engine.config.SpartanModelConfig>
-
getIdentifier
- Specified by:
getIdentifierin interfaceorg.spartan.api.engine.SpartanModel<SpartanModelConfigType extends org.spartan.api.engine.config.SpartanModelConfig>
-
getSpartanContext
@NotNull public @NotNull org.spartan.api.engine.context.SpartanContext getSpartanContext()- Specified by:
getSpartanContextin interfaceorg.spartan.api.engine.SpartanModel<SpartanModelConfigType extends org.spartan.api.engine.config.SpartanModelConfig>
-
getSpartanModelConfig
- Specified by:
getSpartanModelConfigin interfaceorg.spartan.api.engine.SpartanModel<SpartanModelConfigType extends org.spartan.api.engine.config.SpartanModelConfig>
-
getActionOutputBuffer
- Specified by:
getActionOutputBufferin interfaceorg.spartan.api.engine.SpartanModel<SpartanModelConfigType extends org.spartan.api.engine.config.SpartanModelConfig>
-
getModelWeightsBuffer
- Specified by:
getModelWeightsBufferin interfaceorg.spartan.api.engine.SpartanModel<SpartanModelConfigType extends org.spartan.api.engine.config.SpartanModelConfig>
-
isRegistered
public boolean isRegistered()- Specified by:
isRegisteredin interfaceorg.spartan.api.engine.SpartanModel<SpartanModelConfigType extends org.spartan.api.engine.config.SpartanModelConfig>
-
saveModel
public void saveModel(@NotNull @NotNull Path filePath) throws org.spartan.api.exception.SpartanPersistenceException - Specified by:
saveModelin interfaceorg.spartan.api.engine.SpartanModel<SpartanModelConfigType extends org.spartan.api.engine.config.SpartanModelConfig>- Throws:
org.spartan.api.exception.SpartanPersistenceException
-
loadModel
public void loadModel(@NotNull @NotNull Path filePath) throws org.spartan.api.exception.SpartanPersistenceException - Specified by:
loadModelin interfaceorg.spartan.api.engine.SpartanModel<SpartanModelConfigType extends org.spartan.api.engine.config.SpartanModelConfig>- Throws:
org.spartan.api.exception.SpartanPersistenceException
-
copy
@NotNull public @NotNull org.spartan.api.engine.SpartanModel<SpartanModelConfigType> copy(@NotNull @NotNull String newIdentifier) - Specified by:
copyin interfaceorg.spartan.api.engine.SpartanModel<SpartanModelConfigType extends org.spartan.api.engine.config.SpartanModelConfig>
-
getModelType
protected abstract org.spartan.api.engine.config.SpartanModelType getModelType()Returns the model type for this instance. Each subclass must provide its own type.- Returns:
- the model type
-
setLiveExplorationRate
public void setLiveExplorationRate(double newEpsilon) - Specified by:
setLiveExplorationRatein interfaceorg.spartan.api.engine.SpartanModel<SpartanModelConfigType extends org.spartan.api.engine.config.SpartanModelConfig>
-
getEpisodeReward
public double getEpisodeReward()- Specified by:
getEpisodeRewardin interfaceorg.spartan.api.engine.SpartanModel<SpartanModelConfigType extends org.spartan.api.engine.config.SpartanModelConfig>
-
resetEpisode
public void resetEpisode()- Specified by:
resetEpisodein interfaceorg.spartan.api.engine.SpartanModel<SpartanModelConfigType extends org.spartan.api.engine.config.SpartanModelConfig>
-
decayExploration
public void decayExploration()- Specified by:
decayExplorationin interfaceorg.spartan.api.engine.SpartanModel<SpartanModelConfigType extends org.spartan.api.engine.config.SpartanModelConfig>
-
release
protected void release()Unregisters from C++ and releases resources.This method is called by the framework when the model is no longer needed. Subclasses should not override this method.
-
writeConfigToSegment
protected abstract void writeConfigToSegment() -
getCriticWeightsBufferInternal
-
getCriticWeightsCount
protected abstract int getCriticWeightsCount()
-