Skip to content

Commit

Permalink
Merge pull request #133 from Phuire-Research/UI
Browse files Browse the repository at this point in the history
UI
  • Loading branch information
REllEK-IO committed Oct 30, 2023
2 parents 144d695 + 80e8f41 commit 5bc7b4e
Show file tree
Hide file tree
Showing 27 changed files with 629 additions and 445 deletions.
3 changes: 2 additions & 1 deletion Axium.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ Please avoid using these qualities, but are providing explanations to understand
* conclude - This is a pure action that has no reducer or method. And will only be issued upon the conclusion of an ActionStrategy. If ownership is part of the concept load. This allows for the conclude to clear the final action's locks via its OwnershipLedger Entries.
* initializePrinciples - Is a delayed action to allow for the internal set up of the axium at run time.
* open - Similar to conclude, notifies principles when the axium is open to their emissions. Part of the initialization, addConcept, and removeConcept strategies.
* close - This will will cancel all internal subscriptions that the axium has access to. As well as all Steams will be completed. The external close() function that the createAxium supplies, dispatches this action. Or can be ran specially via an internal principle towards its governing axium or that of another axium that it is subscribed to.
* removeConceptsViaQue - This will run via the internal axium principle. Whenever there is an addition to this remove que.

## Use With Care
Expand All @@ -89,7 +90,7 @@ Please avoid using these qualities, but are providing explanations to understand
## Useful Axium Qualities
* open - Sets axium open property by default to True if no payload is supplied. Must be used after setBlockingMode in a strategy to reenable functionality of principles and external subscribers.
* log - Merely Logs the action, is useful for debugging ActionStrategies as it logs attached Strategy, its current ActionList, and any addition action qualities.
* close - This will will cancel all internal subscriptions that the axium has access to. As well as all Steams will be completed. The external close() function that the createAxium supplies, dispatches this action. Or can be ran specially via an internal principle towards its governing axium or that of another axium that it is subscribed to.
* preClose - Will prompt the axium to close and disengage all active subscriptions, while notifying subscribers that their concept has been removed.
* setMode - If your concept requires a specific modification to the functionality of the stream. This will set the mode index to that stream. Specifically this shouldn't have to be used. But is left to the developer if they run into such a case.
* setDefaultModeIndex - Should be used if your mode is to be considered the default mode of your application. For utilization within a strategy after setMode. Be sure to a run time search for your concept name and mode, after your concept is added via the addConcept strategy found below. Be mindful that modeName is just your Concept Name and the creation of new Modes should be the last go To for your applications functionality.
* clearDialog - Clears the currently stored Stratimux dialog, may be used within a strategy.
Expand Down
134 changes: 73 additions & 61 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
**Features:**
* Universal Transformer
* Autonomous Baseline Intelligence (ABI)
* Halting Complete
* Concept Libraries
* Action Oriented
* Single Lock Graph Framework
* Composable Strategies
Expand Down Expand Up @@ -67,87 +69,97 @@ const plan = axium.stage(
const axiumState = cpts[0].state as AxiumState;
if (axiumState.lastStrategy === setOwnerShipModeTopic) {
const ownership = selectState<OwnershipState>(cpts, ownershipName);
console.log('Stage 1', ownership.ownershipLedger, ownership.pendingActions);
const counter = selectState<Counter>(cpts, counterName);
console.log('Count: ', counter.count);
// This will place a counting strategy in the experiment actionQue to be later dispatched.
// Via its principle, to simulate an action moving off premise.
dispatch(strategyBegin(puntCountingStrategy()), {
iterateStage: true
});
if (ownership) {
console.log('Stage 1', ownership.ownershipLedger, ownership.pendingActions);
const counter = selectState<Counter>(cpts, counterName);
console.log('Count: ', counter?.count);
// This will place a counting strategy in the experiment actionQue to be later dispatched.
// Via its principle, to simulate an action moving off premise.
dispatch(strategyBegin(puntCountingStrategy()), {
iterateStage: true
});
}
}
},
// Comment out if testing log and the halting quality of the Unified Turing Machine.
(cpts, dispatch) => {
// Will be ran after both counting strategies conclude.
const ownership = selectState<OwnershipState>(cpts, ownershipName);
console.log('Stage 2', ownership.ownershipLedger, ownership.pendingActions);
dispatch(counterSetCount({newCount: 1000}, undefined, 7000), { iterateStage: true});
if (ownership) {
console.log('Stage 2', ownership.ownershipLedger, ownership.pendingActions);
dispatch(counterSetCount({newCount: 1000}, undefined, undefined, 7000), { iterateStage: true});
}
},
(cpts, dispatch) => {
const ownership = selectState<OwnershipState>(cpts, ownershipName);
console.log('Stage 3', ownership.ownershipLedger, ownership.pendingActions);
const counter = selectState<Counter>(cpts, counterName);
console.log('Count: ', counter.count);
dispatch(strategyBegin(experimentPrimedCountingStrategy(cpts)), {
iterateStage: true
});
if (ownership) {
console.log('Stage 3', ownership.ownershipLedger, ownership.pendingActions);
const counter = selectState<Counter>(cpts, counterName);
console.log('Count: ', counter?.count);
dispatch(strategyBegin(experimentPrimedCountingStrategy(cpts)), {
iterateStage: true
});
}
},
(cpts, dispatch) => {
const axiumState = cpts[0].state as AxiumState;
const counter = selectState<Counter>(cpts, counterName);
console.log('Stage 4', axiumState.lastStrategy, orderOfTopics);
if (orderOfTopics.length === 2 && finalRun) {
finalRun = false;
// This will be the final test to be triggered by a log action.
console.log('Stage 3, If #3 | Count: ', counter.count, orderOfTopics);
expect(orderOfTopics[0]).toBe(experimentCountingTopic);
expect(counter.count).toBe(3);
// Comment in if testing the halting ability of log and setCount stage is commented out.
// setTimeout(() => {done();}, 1000);
plan.conclude();
} else if (
(axiumState.lastStrategy === experimentCountingTopic ||
axiumState.lastStrategy === experimentPrimedCountingTopic) &&
orderOfTopics.length === 0) {
console.log('Stage 3, If #1 | Count: ', counter.count);
orderOfTopics.push(axiumState.lastStrategy);
} else if (
(axiumState.lastStrategy === experimentCountingTopic ||
axiumState.lastStrategy === experimentPrimedCountingTopic) &&
orderOfTopics.length === 1) {
if (orderOfTopics[0] !== axiumState.lastStrategy) {
console.log('Stage 3, If #2 | Count: ', counter.count);
if (counter) {
console.log('Stage 4', axiumState.lastStrategy, orderOfTopics);
if (orderOfTopics.length === 2 && finalRun) {
finalRun = false;
// This will be the final test to be triggered by a log action.
console.log('Stage 3, If #3 | Count: ', counter.count, orderOfTopics);
expect(orderOfTopics[0]).toBe(experimentCountingTopic);
expect(counter.count).toBe(3);
// Comment in if testing the halting ability of log and setCount stage is commented out.
// setTimeout(() => {done();}, 1000);
plan.conclude();
} else if (
(axiumState.lastStrategy === experimentCountingTopic ||
axiumState.lastStrategy === experimentPrimedCountingTopic) &&
orderOfTopics.length === 0) {
console.log('Stage 3, If #1 | Count: ', counter.count);
orderOfTopics.push(axiumState.lastStrategy);
// Due to the halting behavior of a Unified Turing Machine, this will trigger before set Count at step 2.
// If commented out, set Count will trigger the the "If #3" check.
// If commenting out setCount stage, disable the test in the subscription
// Then be sure to enabled the final done check in "If #3".
// Then enabling the axiumLog dispatch will allow the test to conclude.
// But disabling the axiumLog will never trigger the "If #3" check and disallow the test to conclude.
// This proves Stratimux as a Unified Turing Machine and this configuration Halting Complete.
dispatch(axiumLog(), {
runOnce: true
});
} else if (
(axiumState.lastStrategy === experimentCountingTopic ||
axiumState.lastStrategy === experimentPrimedCountingTopic) &&
orderOfTopics.length === 1) {
if (orderOfTopics[0] !== axiumState.lastStrategy) {
console.log('Stage 3, If #2 | Count: ', counter.count);
orderOfTopics.push(axiumState.lastStrategy);
// Due to the halting behavior of a Unified Turing Machine, this will trigger before set Count at step 2.
// If commented out, set Count will trigger the the "If #3" check.
// If commenting out setCount stage, disable the test in the subscription
// Then be sure to enabled the final done check in "If #3".
// Then enabling the axiumLog dispatch will allow the test to conclude.
// But disabling the axiumLog will never trigger the "If #3" check and disallow the test to conclude.
// This proves Stratimux as a Unified Turing Machine and this configuration Halting Complete.
dispatch(axiumLog(), {
runOnce: true
});
}
}
}
}
]);
const sub = axium.subscribe((concepts: Concepts) => {
const state = selectState<OwnershipState>(concepts, ownershipName);
const _axiumState = concepts[0].state as AxiumState;
if (state.initialized && _axiumState.lastStrategy === setOwnerShipModeTopic) {
expect(state.initialized).toBe(true);
}
const counter = selectState<Counter>(concepts, counterName);
// This will run last, despite setCount being the second staged dispatch.
if (counter.count >= 1000) {
console.log('Subscription, Final Count: ', counter.count, orderOfTopics);
expect(counter.count).toBe(1000);
// Comment out if setCount stage is disabled and instead testing axiumLogs of "If #2" halting interaction.
setTimeout(() => {done();}, 1000);
sub.unsubscribe();
axium.close();
if (state) {
const _axiumState = concepts[0].state as AxiumState;
if (state.initialized && _axiumState.lastStrategy === setOwnerShipModeTopic) {
expect(state.initialized).toBe(true);
}
const counter = selectState<Counter>(concepts, counterName);
// This will run last, despite setCount being the second staged dispatch.
if (counter && counter.count >= 1000) {
console.log('Subscription, Final Count: ', counter.count, orderOfTopics);
expect(counter.count).toBe(1000);
// Comment out if setCount stage is disabled and instead testing axiumLogs of "If #2" halting interaction.
setTimeout(() => {done();}, 1000);
sub.unsubscribe();
axium.close();
}
}
});
```
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@phuire/stratimux",
"version": "0.0.57",
"version": "0.0.58",
"description": "Unified Turing Machine",
"main": "dist/index.js",
"module": "dist/index.mjs",
Expand Down
10 changes: 8 additions & 2 deletions src/concepts/axium/axium.concept.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Subject, Subscription } from 'rxjs';
import { Concept } from '../../model/concept';
import { Action } from '../../model/action';
import { axiumPrinciple } from './axium.principle';
import { axiumClosePrinciple, axiumPrinciple } from './axium.principle';
import { blockingMode, permissiveMode } from './axium.mode';
import { openQuality } from './qualities/open.quality';
import { badActionQuality } from './qualities/badAction.quality';
Expand All @@ -27,6 +27,7 @@ import { clearBadStrategyTopicFromBadActionListQuality } from './qualities/clear
import { clearBadPlanFromBadPlanListQuality } from './qualities/clearBadPlanFromBadPlanList.quality';
import { registerStagePlannerQuality } from './qualities/registerStagePlanner.quality';
import { kickQuality } from './qualities/kick.quality';
import { preCloseQuality } from './qualities/preClose.quality';

export type NamedSubscription = {
name: string;
Expand All @@ -37,6 +38,8 @@ export type AxiumState = {
// Would be unique identifier on a network
name: string;
open: boolean;
prepareClose: boolean;
exit: boolean;
conceptCounter: number;
logging: boolean;
dialog: string;
Expand Down Expand Up @@ -68,6 +71,8 @@ const createAxiumState = (name: string, storeDialog?: boolean, logging?: boolean
return {
name,
open: false,
prepareClose: false,
exit: false,
conceptCounter: 0,
logging: logging ? logging : false,
dialog: '',
Expand Down Expand Up @@ -103,6 +108,7 @@ export const createAxiumConcept = (name: string, storeDialog?: boolean, logging?
openQuality,
badActionQuality,
closeQuality,
preCloseQuality,
appendActionListToDialogQuality,
clearDialogQuality,
logQuality,
Expand All @@ -121,7 +127,7 @@ export const createAxiumConcept = (name: string, storeDialog?: boolean, logging?
clearBadStrategyTopicFromBadActionListQuality,
clearBadPlanFromBadPlanListQuality
],
[axiumPrinciple],
[axiumPrinciple, axiumClosePrinciple],
[blockingMode, permissiveMode]
);
};
29 changes: 29 additions & 0 deletions src/concepts/axium/axium.principle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ import { removeConceptsViaQueThenUnblockStrategy } from './strategies/removeConc
import { blockingMode, permissiveMode } from './axium.mode';
import { UnifiedSubject } from '../../model/stagePlanner';
import { blockingMethodSubscription } from '../../model/axium';
import { axiumRegisterStagePlanner } from './qualities/registerStagePlanner.quality';
import { axiumSelectOpen } from './axium.selector';
import { selectUnifiedState } from '../../model/selector';
import { axiumClose } from './qualities/close.quality';

export const axiumPrinciple: PrincipleFunction = (
observer: Subscriber<Action>,
Expand Down Expand Up @@ -140,3 +144,28 @@ export const axiumPrinciple: PrincipleFunction = (
});
registerPrincipleSubscription(observer, concepts, axiumName, subscription);
};

export const axiumClosePrinciple: PrincipleFunction = (
_: Subscriber<Action>,
__: Concepts,
concepts$: UnifiedSubject,
semaphore: number
) => {
let init = false;
const plan = concepts$.stage('Plan Axium Close', [
(concepts, dispatch) => {
const state = selectUnifiedState<AxiumState>(concepts, semaphore);
if (!init && state?.prepareClose) {
init = true;
concepts$.next({0: concepts[0]});
dispatch(axiumClose({exit: state.exit}), {
iterateStage: true
});
plan.conclude();
}
},
() => {
//
}
]);
};
26 changes: 26 additions & 0 deletions src/concepts/axium/qualities/preClose.quality.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { createQuality } from '../../../model/concept';
import { Action, ActionType, prepareActionWithPayloadCreator } from '../../../model/action';
import { AxiumState } from '../axium.concept';
import { selectPayload } from '../../../model/selector';

/**
* @parm exit - If set to true, will exit the current process.
*/
export type PreClosePayload = {
exit: boolean
};
export const axiumPreCloseType: ActionType = 'Prepare Close Axium';
export const axiumPreClose = prepareActionWithPayloadCreator<PreClosePayload>(axiumPreCloseType);

export function closeReducer(state: AxiumState, _action: Action): AxiumState {
return {
...state,
prepareClose: true,
exit: selectPayload<PreClosePayload>(_action).exit
};
}

export const preCloseQuality = createQuality(
axiumPreCloseType,
closeReducer
);
6 changes: 3 additions & 3 deletions src/concepts/chain/chain.principle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Concepts } from '../../model/concept';
import { Action } from '../../model/action';
import { PrincipleFunction, registerPrincipleSubscription } from '../../model/principle';
import { Chain, chainName } from './chain.concept';
import { selectState } from '../../model/selector';
import { selectState, selectUnifiedState } from '../../model/selector';
import { AxiumState } from '../axium/axium.concept';
import { UnifiedSubject } from '../../model/stagePlanner';

Expand All @@ -14,8 +14,8 @@ export const chainPrinciple: PrincipleFunction = (
semaphore: number
) => {
const subscription = concepts$.subscribe((concepts: Concepts) => {
const chainState = selectState<Chain>(concepts, chainName);
if (chainState.actionQue.length > 0) {
const chainState = selectUnifiedState<Chain>(concepts, semaphore);
if (chainState && chainState.actionQue.length > 0) {
// pass = false;
const newActionQue = [...chainState.actionQue];
const nextAction = newActionQue.pop() as Action;
Expand Down
6 changes: 3 additions & 3 deletions src/concepts/experiment/experiment.principle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Action, primeAction } from '../../model/action';
import { PrincipleFunction } from '../../model/principle';
import { Concept, Concepts } from '../../model/concept';
import { UnifiedSubject } from '../../model/stagePlanner';
import { selectState } from '../../model/selector';
import { selectState, selectUnifiedState } from '../../model/selector';
import { ExperimentState, experimentName } from './experiment.concept';
import { axiumRegisterStagePlanner } from '../axium/qualities/registerStagePlanner.quality';
import { axiumSelectOpen } from '../axium/axium.selector';
Expand All @@ -27,9 +27,9 @@ export const experimentActionQuePrinciple: PrincipleFunction = (
},
(cpts, _) => {
const concepts = cpts;
const experimentState = selectState<ExperimentState>(concepts, experimentName);
const experimentState = selectUnifiedState<ExperimentState>(concepts, semaphore);
// console.log('Check que', experimentState.actionQue);
if (experimentState.actionQue.length > 0) {
if (experimentState && experimentState.actionQue.length > 0) {
if (!readyToGo) {
readyToGo = true;
setTimeout(() => {
Expand Down
Loading

0 comments on commit 5bc7b4e

Please sign in to comment.