plugins.PythonPlugin

plugins.PythonPlugin(spec)

A cadjoint kind, filled by an object imported into this process.

The object is whatever spec.object ("module:attribute") names, imported on first use and held for the life of the plugin. It must satisfy the kind’s Protocol in :mod:cadjoint.plugins.contracts; a kind with no contract (a third party’s own) is accepted as is, and its apply calls the object itself.

Parameters

Name Type Description Default
spec PluginSpec A transport="python" spec. required

Attributes

Name Description
capabilities See :class:Capabilities; in_process is always among the features.
component The imported object (resolved on first use).
contract_version The contract version the object declares (None if it declares none).
inputs The primary method’s parameters, with their Differentiable tags.
method The bound method the kind’s contract names (the object itself otherwise).
outputs The primary method’s result, under the key "result".
version The object’s own version, else the spec’s, else "unknown".

Methods

Name Description
apply Call the contract’s method with the payload as keywords.
as_jax The object’s own JAX callable — the contract’s bound method.
close Drop the reference; the next use imports again.
probe Import the object and check it speaks this cadjoint’s contract.
schema_hash sha256: of the kind’s contract signature (see :func:contract_signature).
vjp jax.vjp of the contract’s method with respect to the named inputs.

apply

plugins.PythonPlugin.apply(inputs=None, **kwargs)

Call the contract’s method with the payload as keywords.

Returns

Name Type Description
dict[str, Any] {"result": value} — one key, because a contract method
dict[str, Any] returns one object.

as_jax

plugins.PythonPlugin.as_jax()

The object’s own JAX callable — the contract’s bound method.

Unlike :meth:TesseractPlugin.as_jax nothing is wrapped: the method carries its own custom_vjp and is called with keywords inside the caller’s trace.

close

plugins.PythonPlugin.close()

Drop the reference; the next use imports again.

probe

plugins.PythonPlugin.probe(strict=True)

Import the object and check it speaks this cadjoint’s contract.

Parameters

Name Type Description Default
strict bool Raise on a contract-version or version mismatch (the default); False reports and leaves the judgement to the caller. True

Returns

Name Type Description
The PluginProbe class:PluginProbe; status is "ok" when the
PluginProbe object imports and satisfies the Protocol.

Raises

Name Type Description
PluginMismatch When strict and the object declares a contract version other than :data:CONTRACT_VERSION, or a version other than the spec’s.
RuntimeError When the object cannot be imported.

schema_hash

plugins.PythonPlugin.schema_hash()

sha256: of the kind’s contract signature (see :func:contract_signature).

vjp

plugins.PythonPlugin.vjp(inputs, vjp_inputs, vjp_outputs, cotangent_vector)

jax.vjp of the contract’s method with respect to the named inputs.

The derivative is the object’s own (its custom_vjp); this only arranges the call.

Raises

Name Type Description
ValueError For a kind whose contract carries no derivative, or an output other than "result".