an.verify.constraints#
Constraints: declarative statements a lint checks and a solver may enforce (an#497).
A constraint says something about the world the shots show that must stay true:
a node does not jump within a shot, two solids do not pass through each other, a
prop meets the body it is drawn on. It is declared once and has up to two faces
(the constraints catalogue, misc/docs/constraints_catalogue.md):
a check: a lint, run by
an validatethrough the semantic-check registry (an.genres.SemanticCheck). It reads aan.ir.validate.ValidationContextand adds findings toctx.report;a term, optional: the residual the kinematic layer’s solver drives to zero, for a constraint that is enforced as well as checked.
Nonemeans lint-only, and that is the legitimate default rather than a stub: draw order is derived from depth and continuity comes from solving each frame from the previous one, so neither has a residual.
Every constraint ships as a lint before it is a term, and a term never replaces
the lint: what the solver produces is checked again by the same check.
The one example a genre or a later batch copies (P2’s joint_violation):
>>> def joint_check(ctx):
... "Every joint of ctx.shot holds at every sampled instant, else ctx.report.add(...)."
>>> def joint_term(state):
... "The solver's residual for one joint: zero when its two bodies meet there."
... return 0.0
>>> JOINT = Constraint("joint_violation", joint_check, term=joint_term,
... description="a joint's two bodies meet at the joint")
>>> check = JOINT.semantic_check()
>>> check.name, check.stage, check.order == DFLT_ORDER, JOINT.term is joint_term
('joint_violation', 'shot', True, True)
A genre registers it like any check (Genre(checks=(JOINT.semantic_check(),)));
the core’s own are CONSTRAINTS, registered when this module is imported
(an.ir imports it, so validate_semantic always has them, the way the core’s
other checks are registered when an.ir.validate is).
The core’s constraints:
continuity(an#508, catalogue B1): a node does not jump within a shot unless asetsays so, and a value is not held for less than a frame.discontinuities()is the pure function under it.solidity(an#509, catalogue A2): two solids (characters and props) whose boxes overlap, with nostage.afterbetween them, are drawn through each other.solid_overlaps()is the pure function under it.draw_order(an#510, catalogue A3): two entities painted one way in one shot and the other way in a later one, with no change ofstage.afterbetween them.order_flips()is the pure function under it. (The within-shot half, painted order against world depth for a member in motion, is the lowering’s:an.ir.world.depth_order_problems, reported as adraw_ordernote.)jump_cut(catalogue C4, the 30-degree rule): two consecutive shots of one subject from nearly the same angle and size.jump_cut_between()is the pure function under it.object_permanence(catalogue C1): an entity shown, then absent for whole shots, then shown again with notime_jumpbetween and no entrance; and one entity drawn twice in a shot.vanishings()is the pure function under it.held_item(catalogue A4, the weld): an item declared held by a node (Shot.welds) stays at its offset from the carrier between pick-up and release.weld_drifts()is the pure function under it.rigidity(catalogue A5): an entity that declaresoverrides: {rigid: true}keeps its aspect (scale_xagainstscale_y) through the shot; one that declaresoverrides: {preserve_volume: true}keepsscale_x * scale_y.shape_drifts()is the pure function under it. Opt-in, since thesquash_stretchpreset deforms on purpose.motion_style(catalogue B2, B5): the style pack’smotiontargets, measured on the compiled shot:smoothness(the log dimensionless jerk of each move) andanticipation(a big move is preceded by a small counter-move).move_jerk()andunanticipated()are the pure functions under it.Silent when the pack declares no
motion. Arcs and overlap are not built.gravity(catalogue B4): under a style pack that declaresgravity, an entity declaringoverrides: {airborne: {from, until}}follows a parabola (constant downward acceleration) and does not hover.airborne_faults()is the pure function under it. Unsupported falls and hangs wait on supports (catalogue A1) and joints.causality(catalogue B7): a shot sound cue that names its visiblecause(aCueAnchor) is not ahead of it (error pastCAUSE_TOLERANCE) and sits within the audio-visual sync window(warning).
av_offset_fault()is the pure function under it. Dialogue and lip-sync consistency are not built.cue_event: a shot sound cue timed by a hold event (at: {when: musket, event: land}) names an event the compiled shot has, and one timed by an authored change (at: {when: book/body, changes: state, to: page_l}, an#815) asetortweenthe shot has (error, listing what there is, else aninfoline with its second).light(catalogue D1): under the scene’s onemeta.light, a member whose art declaresmetadata.shaded_side(oroverrides.shaded_side) is shaded on the side facing away from it, read where that side faces on screen as the shot opens (mirrors and rotations above the art included).shading_disagrees()is the pure function under it.flatart is exempt; a flip mid-shot is not read.
Module Attributes
The core's constraints, in the order their checks run within a stage. |
|
always on, since it reports on whichever compile-based checks ran ( |
Functions
|
The style pack's gravity ( |
|
How a sound at |
|
What is wrong with a flight sampled as |
|
The log dimensionless jerk |
|
The moves of at least |
|
The first of |
|
The first instant of |
|
The entities that vanish and return with nothing to explain it. |
|
|
|
The document of |
|
Say, once per shot, that the compile-based checks did NOT run on a shot that does not compile, at |
|
|
|
Every instant in |
|
Step-held values shown for less than a frame: two |
Classes
|
One constraint: a declarative statement with a |
|
One clip's change of one channel: from |
|
The |
|
The item of weld |
|
|
|
A numeric channel of |
|
A step-held value of |
- an.verify.constraints.CONSTRAINTS: tuple[Constraint, ...] = (Constraint(name='continuity', check=<function check_continuity>, stage='shot', order=200.0, description='a node does not jump within a shot unless a set says so (an#508)', term=None), Constraint(name='solidity', check=<function check_solidity>, stage='shot', order=200.0, description='two solids are not drawn through each other unless one is placed after (an#509)', term=None), Constraint(name='draw_order', check=<function check_draw_order>, stage='finish', order=200.0, description='two entities are painted in the same order in every shot unless `after` changes (an#510)', term=None), Constraint(name='jump_cut', check=<function check_jump_cut>, stage='finish', order=200.0, description='consecutive shots of one subject differ by 30 degrees or a shot size', term=None), Constraint(name='object_permanence', check=<function check_object_permanence>, stage='finish', order=200.0, description='an entity does not vanish and return across shots, nor appear twice in one (catalogue C1)', term=None), Constraint(name='held_item', check=<function check_held_item>, stage='shot', order=200.0, description='an item declared held stays at its offset from its carrier between pick-up and release (catalogue A4)', term=None), Constraint(name='rigidity', check=<function check_rigidity>, stage='shot', order=200.0, description='an entity declared rigid keeps its proportions, one declared volume-preserving keeps its area (catalogue A5)', term=None), Constraint(name='motion_style', check=<function check_motion_style>, stage='shot', order=200.0, description='moves are as smooth, and big moves as anticipated, as the style pack declares (catalogue B2, B5)', term=None), Constraint(name='gravity', check=<function check_gravity>, stage='shot', order=200.0, description='an entity declared airborne follows a parabola and does not hover under a style that declares gravity (catalogue B4)', term=None), Constraint(name='causality', check=<function check_causality>, stage='shot', order=200.0, description='a sound cue that names its visible cause is not ahead of it, and is within the audio-visual sync window (catalogue B7)', term=None), Constraint(name='cue_event', check=<function check_cue_event>, stage='shot', order=200.0, description='a sound cue timed by a hold event (`at: {when: item, event: land}`) or an authored change (`at: {when: node, changes: state}`) names one the shot has', term=None), Constraint(name='light', check=<function check_light>, stage='shot', order=200.0, description="every member's art is shaded on the side the scene's one light implies (catalogue D1)", term=None), Constraint(name='lettering', check=<function check_lettering>, stage='shot', order=200.0, description='art that declares lettering is never drawn mirrored without its mirror drawing (an#819)', term=None))#
The core’s constraints, in the order their checks run within a stage.
- class an.verify.constraints.Constraint(name, check, stage='shot', order=200.0, description='', term=None)[source]#
Bases:
objectOne constraint: a declarative statement with a
checkand, optionally, aterm.check(ctx)is SemanticCheck-shaped (it adds findings toctx.report);stage,orderanddescriptionare the registry’s.termis the solver residual hook the kinematic layer’ssolvepass consumes: a callable returning the residual(s), zero when the constraint holds, in the units of the constrained quantity.Noneis lint-only.>>> c = Constraint("holds", lambda ctx: None, stage="finish", order=5.0) >>> c.semantic_check().stage, c.term ('finish', None)
- class an.verify.constraints.Discontinuity(target, property, at, before, after, cause, deliberate)[source]#
Bases:
objectA numeric channel of
targetthat jumps atat(seconds into the shot).
- class an.verify.constraints.Move(key, start, end, delta)[source]#
Bases:
objectOne clip’s change of one channel: from
starttoends, bydelta.
- an.verify.constraints.NOT_COMPILED: SemanticCheck = SemanticCheck(name='not_compiled', run=<function check_not_compiled>, stage='finish', order=1000.0, description='a shot the compile-based checks could not compile says they did not run')#
always on, since it reports on whichever compile-based checks ran (
onlyincluded).- Type:
The one line a shot that does not compile gets (an#551)
- class an.verify.constraints.ShapeDrift(entity, quantity, at, ratio)[source]#
Bases:
objectThe
quantity(aspectorvolume) ofentityisratiotimes its start atats.
- class an.verify.constraints.ShortHold(target, property, at, value, held_s)[source]#
Bases:
objectA step-held value of
target’spropertyshown for less than a frame.
- class an.verify.constraints.Vanishing(entity, before, after)[source]#
Bases:
objectentityis in shotbeforeand again in shotafter(timeline indices) but in none of the shots between.
- class an.verify.constraints.WeldDrift(index, at, distance)[source]#
Bases:
objectThe item of weld
indexisdistancepx from where it is held, atats.
- an.verify.constraints.airborne_faults(ys, dt, *, strength=None)[source]#
What is wrong with a flight sampled as
ys(screen y, down is positive) everydts:hover(level for more thanHOVER_FRAMES),straight(no downward acceleration: not a throw),not_parabolic(the acceleration is not constant),strength(not the declared pull).>>> g = 1200.0 >>> arc = [-300 * (i / 30) + 0.5 * g * (i / 30) ** 2 for i in range(20)] >>> airborne_faults(arc, 1 / 30) [] >>> airborne_faults([i * 5.0 for i in range(20)], 1 / 30) ['straight'] >>> airborne_faults([40.0] * 20, 1 / 30) ['hover'] >>> airborne_faults(arc, 1 / 30, strength=300.0) ['strength']
- an.verify.constraints.av_offset_fault(sound_t, cause_t)[source]#
How a sound at
sound_tsits against its visible cause atcause_t(seconds):Noneinside the window, else"early"(sound ahead, past the window),"late"(behind), or"before_cause"(ahead by more thanCAUSE_TOLERANCE).>>> av_offset_fault(1.0, 1.02), av_offset_fault(1.1, 1.0) (None, None) >>> av_offset_fault(1.0, 1.1), av_offset_fault(1.2, 1.0) ('early', 'late') >>> av_offset_fault(0.5, 1.0) 'before_cause'
- an.verify.constraints.check_not_compiled(ctx)[source]#
Say, once per shot, that the compile-based checks did NOT run on a shot that does not compile, at
an.verify.vision.FAILURE_SEVERITY: a check that could not look must never read as a check that passed (an#551).Runs at
finishover the compiles the shot checks asked for (the memo underCOMPILED_KEY), so it says nothing when no compile-based check ran. Silent for a shot with an entity whose store was not supplied (checks not asked for are not broken). The cause is given in full unless a finding on the shot already says it (_already_said()), then “reported above”. Folds in the action-target check’s own skip.>>> from an.ir.schema import SceneIR, Shot >>> from an.ir.validate import ValidationContext, ValidationReport >>> ctx = ValidationContext(SceneIR(timeline=[Shot(id="a"), Shot(id="b")]), ValidationReport(), {}) >>> ctx.memo[(COMPILED_KEY, 0)] = (None, ValueError("step_hz 1000 is not a divisor of fps")) >>> ctx.memo[(COMPILED_KEY, 1)] = (None, ValueError("step_hz 1000 is not a divisor of fps")) >>> ctx.report.add("error", "timeline/1/step_hz", "step_hz 1000 is not a divisor of fps.") >>> check_not_compiled(ctx) >>> [(f.severity, f.ir_path) for f in ctx.report.findings[1:]] [('warning', 'timeline/0'), ('warning', 'timeline/1')] >>> [f.description.split("(")[-1] for f in ctx.report.findings[1:]] ['ValueError: step_hz 1000 is not a divisor of fps).', 'ValueError, reported above).']
- Return type:
- an.verify.constraints.compile_outcome(ctx)[source]#
ctx.shotcompiled asan rendercompiles it (an.stage.compile.compile_as_rendered()), once per validation: the stores validate was given stand in for the mall and the frame rate is the render’s whenan validate --fpssays. Every compile-based check reads this one document.
- an.verify.constraints.compiled_shot(ctx)[source]#
The document of
compile_outcome(),Nonefor a shot the stage does not render or that does not compile. A constraint says nothing about a shot it could not see; thenot_compiledcheck says, once per shot, that it could not (check_not_compiled()).
- an.verify.constraints.continuity_findings(doc, *, duration, fps, path='')[source]#
[(severity, ir path, message)]for a compiled shot’s jumps and short holds.
- an.verify.constraints.discontinuities(timeline, *, rest, duration)[source]#
Every instant in
(0, duration]where a numeric value oftimelinejumps: the pose read just before the instant and just after it differ beyondCONTINUITY_TOLERANCE.restis each(target, property)’s value while nothing writes it (the node’s own transform); a key absent from both the pose andrestis not judged.A tween with a
fromthe node is not at jumps where it starts; two tweens on one property jump where the later one starts and again where it ends and the earlier one shows through; a loop whose last pose is not its first jumps at each restart. Asetis a jump the author wrote: it is reported withdeliberate=True, for the caller to leave alone.>>> from an.timing.channel import Channel, Keyframe >>> from an.timing.clip import Clip >>> from an.timing.timeline import PlacedClip, Timeline, Track >>> rise = Clip("rise", 1.0, [Channel("a", "y", [Keyframe(0.0, 3.0, "linear"), Keyframe(1.0, 10.0)])]) >>> tl = Timeline(2.0, [Track("a", [PlacedClip(rise, start_time=0.5)])]) >>> (d,) = discontinuities(tl, rest={("a", "y"): 0.0}, duration=2.0) >>> d.at, d.before, d.after, d.cause, d.deliberate (0.5, 0.0, 3.0, 'start', False) >>> hold = Clip("hold", 1.5, [Channel("a", "y", [Keyframe(0.0, 3.0, "step")])]) >>> tl = Timeline(2.0, [Track("a", [PlacedClip(hold, start_time=0.5), PlacedClip(rise, start_time=0.5)])]) >>> discontinuities(tl, rest={("a", "y"): 0.0}, duration=2.0)[0].deliberate True
- Return type:
- an.verify.constraints.gravity_of(ctx)[source]#
The style pack’s gravity (
Nonewhen it declares none or saysnone): what thegravitycheck holds a flight to, and what makes theskatecheck judge an inferred stance (an.verify.support).
- an.verify.constraints.move_jerk(values, dt)[source]#
The log dimensionless jerk
ln(T^5 / A^2 * integral |jerk|^2 dt)of a move sampled everydts: lower is smoother. A minimum-jerk move scores aboutln 720(6.6) whatever its size and duration; corners score far higher.Nonefor a move too short or too small to measure.>>> import math >>> s = [10 * u**3 - 15 * u**4 + 6 * u**5 for u in (i / 60 for i in range(61))] >>> 6.0 < move_jerk(s, 1 / 30) < 7.0 True >>> linear = [i / 60 for i in range(61)] >>> move_jerk(linear, 1 / 30) > 9 True
- an.verify.constraints.shape_drifts(entity, samples, *, quantity, tolerance=None)[source]#
The first of
samples(t, scale_x, scale_y)whosequantityhas left its starting value by more thantolerance(a fraction), as one drift carrying the worst ratio seen from then on.>>> squash = [(0.0, 1.0, 1.0), (0.5, 1.2, 0.8), (1.0, 1.0, 1.0)] >>> shape_drifts("ball", squash, quantity="volume") [] >>> [round(d.ratio, 3) for d in shape_drifts("ball", squash, quantity="aspect")] [1.5] >>> shape_drifts("ball", [(0.0, 1.0, 1.0), (1.0, 1.5, 1.0)], quantity="volume")[0].ratio 1.5
- Return type:
- an.verify.constraints.short_holds(timeline, *, fps)[source]#
Step-held values shown for less than a frame: two
set``s of one property closer than ``1/fps, so the first may never land on a frame.>>> from an.timing.channel import Channel, Keyframe >>> from an.timing.clip import Clip >>> from an.timing.timeline import PlacedClip, Timeline, Track >>> sets = Clip("sets", 1.0, [Channel("a", "x", [Keyframe(0.0, 5.0, "step"), Keyframe(0.01, 0.0, "step")])]) >>> tl = Timeline(2.0, [Track("a", [PlacedClip(sets, start_time=0.5)])]) >>> [(h.at, h.value, round(h.held_s, 3)) for h in short_holds(tl, fps=24)] [(0.5, 5.0, 0.01)]
- an.verify.constraints.unanticipated(moves, *, min_move, frames, fps)[source]#
The moves of at least
min_movewith no anticipation: a move of the same channel, the other way, at most half as far, lastingframesframes, that ends at the big move’s start (to within a frame).>>> big = Move(("a", "x"), 1.0, 2.0, 100.0) >>> wind = Move(("a", "x"), 0.8, 1.0, -20.0) >>> unanticipated([wind, big], min_move=50.0, frames=(3, 10), fps=24.0) [] >>> unanticipated([big], min_move=50.0, frames=(3, 10), fps=24.0) == [big] True
- an.verify.constraints.vanishings(presence, time_jumps, entrances=None)[source]#
The entities that vanish and return with nothing to explain it.
presence[i]is the ids drawn in shoti;time_jumps[i]says the transition into shotipasses time;entrances[i]is the ids shotiopens by acting on. A return after absent shots is explained by a time jump into any shot from the first absent one to the returning one, or by an entrance.>>> shots = [frozenset({"a"}), frozenset(), frozenset({"a"})] >>> vanishings(shots, [False] * 3) [Vanishing(entity='a', before=0, after=2)] >>> vanishings(shots, [False, False, True]) [] >>> vanishings(shots, [False] * 3, [frozenset(), frozenset(), frozenset({"a"})]) [] >>> vanishings([frozenset({"a"}), frozenset({"a"})], [False] * 2) []
- an.verify.constraints.weld_drifts(samples, *, index=0, offset=None, tolerance=4.0)[source]#
The first instant of
samples(t, carrier centre, item centre)at which the item is more thantolerancefrom itsoffsetto the carrier (the first sample’s offset whenoffsetisNone), as one drift: the worst distance seen from then on.>>> held = [(0.0, (0, 0), (10, 0)), (1.0, (50, 0), (60, 0))] >>> weld_drifts(held) [] >>> weld_drifts([*held, (2.0, (90, 0), (60, 0))]) [WeldDrift(index=0, at=2.0, distance=40.0)] >>> weld_drifts(held, offset=(0, 0))[0].distance 10.0