Skip to content

Commit

Permalink
Merge pull request #191 from Phuire-Research/unifyStreams
Browse files Browse the repository at this point in the history
v0.1.5
  • Loading branch information
REllEK-IO authored Apr 2, 2024
2 parents 14a50ef + 43c08db commit a957ac7
Show file tree
Hide file tree
Showing 34 changed files with 338 additions and 175 deletions.
17 changes: 9 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,12 @@ When in doubt simplify.
* [Unified Turing Machine](https://github.com/Phuire-Research/Stratimux/blob/main/The-Unified-Turing-Machine.md) - The governing concept for this entire framework.

## Change Log ![Tests](https://github.com/Phuire-Research/Stratimux/actions/workflows/node.js.yml/badge.svg)
### **NOTE: Hold off on updating to v0.1.4 and instead use v0.1.2**
See issue: [https://github.com/Phuire-Research/Stratimux/issues/188](https://github.com/Phuire-Research/Stratimux/issues/188)
### **BREAKING Update v0.1.5** 4/02/24
* Unified the internal concept streams and created a new dedicated stream to inform most recent concepts
* Note if you are assembling plans within a method, be sure to grab the **concepts$** from *getAxiumState*
* It is now a requirement you use the **stageWaitForOpenThenIterate(() => action)** helper function in your plans if you are depending on the last strategyTopic property on the axium concept.
* Added an addition logging property to reveal the internal action stream that can be set when creating your axium. This is separate from the prior logging feature.
* Method now utilize an internal actionConcept$ stream of type Subject<Concepts>. Method creators that utilize the UnifiedSubject will throw a type error and will need to be updated.
### **BREAKING Update v0.1.4** 3/28/24
* Removed the "on.expected" option from dispatch to reduce inner complexity of your stages
* Renamed **axium.stage** to **axium.plan** to be in line with industry terminology
Expand Down Expand Up @@ -133,10 +137,6 @@ export const createUXConcept = (
### uXqOfUx.quality.ts
This isolates all the parts necessary for your actions to have impact within this system. Be mindful of your types, as even though they are not explicitly used within this system. They likewise better inform training data, and likewise act as unique identifiers if you are not setting the semaphore ahead of time.

The semaphore is the method of quality selection within the Axium. This is to reduce the time complexity of each look up. And if you applications are purely static with no planned dynamic changes to the Axium's conceptual load. This values can be hard coded ahead of time. This is one of the planned features for [logixUX](https://github.com/Phuire-Research/logixUX). In addition to other scaffolding improvements, AI assistance, and more.
### uXqOfUx.quality.ts
This isolates all the parts necessary for your actions to have impact within this system. Be mindful of your types, as even though they are not explicitly used within this system. They likewise better inform training data, and likewise act as unique identifiers if you are not setting the semaphore ahead of time.

The semaphore is the method of quality selection within the Axium. This is to reduce the time complexity of each look up. And if you applications are purely static with no planned dynamic changes to the Axium's conceptual load. This values can be hard coded ahead of time. This is one of the planned features for [logixUX](https://github.com/Phuire-Research/logixUX). In addition to other scaffolding improvements, AI assistance, and more.
```typescript
import {
Expand All @@ -162,7 +162,7 @@ function getRandomRange(min: number, max: number) {
return Math.random() * (max - min) + min;
}

const uXqOfUXCreator: MethodCreator = (concepts$?: UnifiedSubject, semaphore?: number) =>
const uXqOfUXCreator: MethodCreator = (concepts$?: Subject<Concepts>, semaphore?: number) =>
// Only if you need to access state, otherwise
createMethodWithState<UXState>((action, state) => {
if (action.strategy) {
Expand Down Expand Up @@ -295,6 +295,7 @@ import { createUXConcept } from './concepts/uX/uX.concept';
// Sets logging to true and store dialog to true
// This will log to the console the dialog of each successive ActionStrategy
// And store the entire application context in the axium's dialog.
createAxium(axiumName, [createUXConcept()], true, true);
// The final boolean will allow the action stream to be logged to console
createAxium(axiumName, [createUXConcept()], true, true, true);
})();
```
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "stratimux",
"license": "GPL-3.0",
"version": "0.1.4",
"version": "0.1.5",
"description": "Unified Turing Machine",
"main": "dist/index.js",
"module": "dist/index.mjs",
Expand Down
2 changes: 1 addition & 1 deletion src/concepts/axium/axium.close.principle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export const axiumClosePrinciple: PrincipleFunction = (
semaphore: number
) => {
let init = false;
const plan = concepts$.plan('Plan Axium Close', [
const plan = concepts$.innerPlan('Plan Axium Close', [
createStage((concepts, dispatch) => {
const state = selectUnifiedState<AxiumState>(concepts, semaphore);
if (!init && state?.prepareClose) {
Expand Down
12 changes: 6 additions & 6 deletions src/concepts/axium/axium.concept.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ within strategies, plans, modes, qualities, and principles.
$>*/
/*<#*/
import { Subject, Subscription } from 'rxjs';
import { Concept } from '../../model/concept';
import { Concept, Concepts } from '../../model/concept';
import { Action } from '../../model/action';
import { axiumPrinciple } from './axium.principle';
import { axiumClosePrinciple } from './axium.close.principle';
Expand Down Expand Up @@ -50,6 +50,7 @@ export type AxiumState = {
exit: boolean;
conceptCounter: number;
logging: boolean;
logActionStream: boolean;
dialog: string;
storeDialog: boolean;
lastStrategy: string;
Expand All @@ -65,9 +66,8 @@ export type AxiumState = {
generalSubscribers: NamedSubscription[];
stagePlanners: NamedStagePlanner[];
action$: Subject<Action>;
actionConcepts$: Subject<Concepts>;
concepts$: UnifiedSubject;
innerConcepts$: UnifiedSubject;
subConcepts$: UnifiedSubject;
addConceptQue: Concept[],
removeConceptQue: Concept[],
badPlans: Plan[];
Expand All @@ -76,14 +76,15 @@ export type AxiumState = {

export const axiumName = 'axium';

const createAxiumState = (name: string, storeDialog?: boolean, logging?: boolean): AxiumState => {
const createAxiumState = (name: string, storeDialog?: boolean, logging?: boolean, logActionStream?: boolean): AxiumState => {
return {
name,
open: false,
prepareClose: false,
exit: false,
conceptCounter: 0,
logging: logging ? logging : false,
logActionStream: logActionStream ? logActionStream : false,
dialog: '',
storeDialog: storeDialog ? storeDialog : false,
lastStrategy: '',
Expand All @@ -99,9 +100,8 @@ const createAxiumState = (name: string, storeDialog?: boolean, logging?: boolean
generalSubscribers: [] as NamedSubscription[],
stagePlanners: [] as NamedStagePlanner[],
action$: new Subject<Action>(),
actionConcepts$: new Subject<Concepts>(),
concepts$: new UnifiedSubject(),
innerConcepts$: new UnifiedSubject(),
subConcepts$: new UnifiedSubject(),
addConceptQue: [] as Concept[],
removeConceptQue: [] as Concept[],
badPlans: [],
Expand Down
12 changes: 5 additions & 7 deletions src/concepts/axium/axium.mode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import { Action, primeAction } from '../../model/action';
import { AxiumState } from './axium.concept';
import { UnifiedSubject } from '../../model/stagePlanner';
import { AxiumBadActionPayload } from './qualities/badAction.quality';
import { counterAdd } from '../counter/qualities/add.quality';

export const isActionable = (axiumState: AxiumState, action: Action): boolean => {
let actionable = true;
Expand Down Expand Up @@ -37,9 +36,6 @@ export const permissiveMode: Mode = (
let subject: Subject<Action>;
if (concepts[action.semaphore[0]].qualities[action.semaphore[1]].method) {
subject = concepts[action.semaphore[0]].qualities[action.semaphore[1]].subject as Subject<Action>;
if (action.strategy?.topic === 'Counting Strategy') {
console.log('Method Subject', action);
}
subject.next(action);
}
const reduce = concepts[action.semaphore[0]].qualities[action.semaphore[1]].reducer;
Expand All @@ -50,9 +46,9 @@ export const permissiveMode: Mode = (
const newConcept = {...newConcepts[action.semaphore[0]]};
newConcepts[action.semaphore[0]] = newConcept;
newConcepts[action.semaphore[0]].state = newState;

// console.log('CHECK NEW STATE', newState);
axiumState.actionConcepts$.next(newConcepts);
concepts$.next(newConcepts);
axiumState.subConcepts$.next(newConcepts);
}
} else {
const nextAction = primeAction(concepts, action);
Expand Down Expand Up @@ -87,14 +83,16 @@ export const blockingMode: Mode = (
const newConcept = {...newConcepts[action.semaphore[0]]};
newConcepts[action.semaphore[0]] = newConcept;
newConcepts[action.semaphore[0]].state = newState;
axiumState.innerConcepts$.next(newConcepts);
axiumState.actionConcepts$.next(newConcepts);
axiumState.concepts$.nextBlocking(newConcepts);
}
let subject: Subject<Action>;
if (concepts[action.semaphore[0]].qualities[action.semaphore[1]].method) {
subject = concepts[action.semaphore[0]].qualities[action.semaphore[1]].subject as Subject<Action>;
// if (action.strategy?.topic === 'Counting Strategy') {
// console.log('Method Subject', action);
// }
console.log('Action HIt');
subject.next(action);
}
} else {
Expand Down
11 changes: 5 additions & 6 deletions src/concepts/axium/axium.principle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,8 @@ export const axiumPrinciple: PrincipleFunction = (
) => {
let allowAdd = true;
let allowRemove = true;
const addConceptsPlan = concepts$.plan('Add Concepts Plan', [
const addConceptsPlan = concepts$.innerPlan('Add Concepts Plan', [
createStage((_concepts, dispatch) => {
console.log('Hitting Sub for Add Concept');
const axiumState = _concepts[0].state as AxiumState;
if (axiumState.addConceptQue.length === 0) {
allowAdd = true;
Expand Down Expand Up @@ -84,7 +83,8 @@ export const axiumPrinciple: PrincipleFunction = (
const newAxiumState = newConcepts[0].state as AxiumState;
newAxiumState.cachedSemaphores = createCacheSemaphores(newConcepts);

axiumState.concepts$?.next(newConcepts);
axiumState.actionConcepts$.next(newConcepts);
axiumState.concepts$.next(newConcepts);

dispatch(strategyBegin(addConceptsFromQueThenUnblockStrategy(newConcepts)), {
throttle: 50
Expand All @@ -93,7 +93,7 @@ export const axiumPrinciple: PrincipleFunction = (
}, { selectors: [axiumSelectAddConceptQue], priority: Infinity - 1}),
]);

const removeConceptsPlan = concepts$.plan('Remove Concepts Plan', [
const removeConceptsPlan = concepts$.innerPlan('Remove Concepts Plan', [
createStage((_concepts, dispatch) => {
const axiumState = _concepts[0].state as AxiumState;
if (axiumState.removeConceptQue.length === 0) {
Expand Down Expand Up @@ -153,7 +153,6 @@ export const axiumPrinciple: PrincipleFunction = (
return caught;
}));
const methodSub = quality.method.subscribe((action: Action) => {
console.log('HIT');
blockingMethodSubscription(axiumState.action$, action);
}) as Subscriber<Action>;
const _axiumState = newConcepts[0].state as AxiumState;
Expand All @@ -164,8 +163,8 @@ export const axiumPrinciple: PrincipleFunction = (
}
});
});
axiumState.actionConcepts$.next(newConcepts);
axiumState.concepts$.next(newConcepts);

dispatch(strategyBegin(
removeConceptsViaQueThenUnblockStrategy(newConcepts)), {
throttle: 50
Expand Down
3 changes: 1 addition & 2 deletions src/concepts/axium/qualities/close.quality.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ export function axiumCloseReducer(state: AxiumState, _action: Action): AxiumStat
state.stagePlanners.forEach(named => named.conclude());
state.action$.complete();
state.concepts$.complete();
state.innerConcepts$.complete();
state.subConcepts$.complete();
state.actionConcepts$.complete();
if (exit) {
process.exit();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export function axiumInitializePrinciplesReducer(state: AxiumState, _action: Act
forEachConcept(concepts ,((concept: Concept, semaphore) => {
if (concept.name === axiumName && concept.principles) {
concept.principles.forEach(principle => {
const observable = createPrinciple$(principle, concepts, state.innerConcepts$, semaphore as number);
const observable = createPrinciple$(principle, concepts, state.concepts$, semaphore as number);
principleSubscribers.push({
name: concept.name,
subscription: observable.subscribe((action: Action) => action$.next(action)) as Subscriber<Action>,
Expand Down
1 change: 1 addition & 0 deletions src/concepts/counter/qualities/add.quality.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export const counterAddType: ActionType = 'Counter Add';

export const counterAdd = prepareActionCreator(counterAddType);
function counterAddReducer(state: CounterState, _: Action) {
console.log('ADD: Incoming', state.count, 'Outgoing', state.count + 1);
return {
...state,
count: state.count + 1
Expand Down
1 change: 1 addition & 0 deletions src/concepts/counter/qualities/subtract.quality.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export const counterSubtractType: ActionType = 'Counter Subtract';
export const counterSubtract = prepareActionCreator(counterSubtractType);

function counterSubtractReducer(state: CounterState) {
console.log('SUBTRACT: Incoming', state.count, 'Outgoing', state.count - 1);
return {
...state,
count: state.count - 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,22 @@ For the graph programming framework Stratimux and Experiment Concept, generate a
Then its method will asynchronously unify the state's id value onto the strategy.
$>*/
/*<#*/
import { MethodCreator } from '../../../model/concept';
import { Concepts, MethodCreator } from '../../../model/concept';
import { Action, prepareActionCreator } from '../../../model/action';
import { createQuality } from '../../../model/concept';
import { ExperimentState } from '../experiment.concept';
import { UnifiedSubject } from '../../../model/stagePlanner';
import { createAsyncMethodWithState } from '../../../model/method';
import { strategySuccess } from '../../../model/actionStrategy';
import { strategyData_unifyData } from '../../../model/actionStrategyData';
import { Subject } from 'rxjs';

export const experimentAsyncIterateIdThenReceiveInMethodType
= 'Experiment asynchronously iterate ID then receive in Method via State';

export const experimentAsyncIterateIdThenReceiveInMethod = prepareActionCreator(experimentAsyncIterateIdThenReceiveInMethodType);

const experimentAsyncIterateIdThenReceiveInMethodCreator: MethodCreator = (concepts$?: UnifiedSubject, semaphore?: number) =>
const experimentAsyncIterateIdThenReceiveInMethodCreator: MethodCreator = (concepts$?: Subject<Concepts>, semaphore?: number) =>
createAsyncMethodWithState<ExperimentState>((controller, action, state) => {
setTimeout(() => {
if (action.strategy) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ For the graph programming framework Stratimux and Experiment Concept, generate a
Then debounce the action via the qualities method that will then unify the state's id into the strategy's data.
$>*/
/*<#*/
import { MethodCreator } from '../../../model/concept';
import { Concepts, MethodCreator } from '../../../model/concept';
import { Action, prepareActionWithPayloadCreator } from '../../../model/action';
import { createQuality } from '../../../model/concept';
import { ExperimentState } from '../experiment.concept';
Expand All @@ -12,6 +12,7 @@ import { createAsyncMethodDebounceWithState } from '../../../model/method';
import { selectPayload } from '../../../model/selector';
import { strategySuccess } from '../../../model/actionStrategy';
import { strategyData_unifyData } from '../../../model/actionStrategyData';
import { Subject } from 'rxjs';

export type ExperimentDebounceAsyncIterateIdThenReceiveInMethodPayload = {
setId: number;
Expand All @@ -23,7 +24,7 @@ export const experimentDebounceAsyncIterateIdThenReceiveInMethod
experimentDebounceAsyncIterateIdThenReceiveInMethodType
);

const experimentDebounceAsyncIterateIdThenReceiveInMethodCreator: MethodCreator = (concepts$?: UnifiedSubject, semaphore?: number) =>
const experimentDebounceAsyncIterateIdThenReceiveInMethodCreator: MethodCreator = (concepts$?: Subject<Concepts>, semaphore?: number) =>
createAsyncMethodDebounceWithState<ExperimentState>((controller, action, state) => {
setTimeout(() => {
const payload = selectPayload<ExperimentDebounceAsyncIterateIdThenReceiveInMethodPayload>(action);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Then debounce the quality of actions within a range. To dispatch the most recent
That will finally unify the state id and setId from the payload into the most recent strategies data field.
$>*/
/*<#*/
import { MethodCreator } from '../../../model/concept';
import { Concepts, MethodCreator } from '../../../model/concept';
import { Action, prepareActionWithPayloadCreator } from '../../../model/action';
import { createQuality } from '../../../model/concept';
import { ExperimentState } from '../experiment.concept';
Expand All @@ -13,6 +13,7 @@ import { createMethodDebounceWithState } from '../../../model/method';
import { selectPayload } from '../../../model/selector';
import { strategySuccess } from '../../../model/actionStrategy';
import { strategyData_unifyData } from '../../../model/actionStrategyData';
import { Subject } from 'rxjs';

export type ExperimentDebounceIterateIdThenReceiveInMethodPayload = {
setId: number;
Expand All @@ -25,7 +26,7 @@ export const experimentDebounceIterateIdThenReceiveInMethod =
experimentDebounceIterateIdThenReceiveInMethodType
);

const experimentDebounceIterateIdThenReceiveInMethodCreator: MethodCreator = (concepts$?: UnifiedSubject, semaphore?: number) =>
const experimentDebounceIterateIdThenReceiveInMethodCreator: MethodCreator = (concepts$?: Subject<Concepts>, semaphore?: number) =>
createMethodDebounceWithState<ExperimentState>((action, state) => {
const payload = selectPayload<ExperimentDebounceIterateIdThenReceiveInMethodPayload>(action);
if (action.strategy) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,21 @@ For the graph programming framework Stratimux and Experiment Concept, generate a
set the id supplied to the method into the strategy's data field.
$>*/
/*<#*/
import { MethodCreator } from '../../../model/concept';
import { Concepts, MethodCreator } from '../../../model/concept';
import { Action, prepareActionCreator } from '../../../model/action';
import { createQuality } from '../../../model/concept';
import { ExperimentState } from '../experiment.concept';
import { UnifiedSubject } from '../../../model/stagePlanner';
import { createMethodWithState } from '../../../model/method';
import { strategySuccess } from '../../../model/actionStrategy';
import { strategyData_unifyData } from '../../../model/actionStrategyData';
import { Subject } from 'rxjs';

export const experimentIterateIdThenReceiveInMethodType = 'Experiment iterate ID then receive in Method via State';

export const experimentIterateIdThenReceiveInMethod = prepareActionCreator(experimentIterateIdThenReceiveInMethodType);

const experimentIterateIdThenReceiveInMethodCreator: MethodCreator = (concepts$?: UnifiedSubject, semaphore?: number) =>
const experimentIterateIdThenReceiveInMethodCreator: MethodCreator = (concepts$?: Subject<Concepts>, semaphore?: number) =>
createMethodWithState<ExperimentState>((action, state) => {
if (action.strategy) {
const data = strategyData_unifyData<ExperimentState>(action.strategy, {id: state.id});
Expand Down
Loading

0 comments on commit a957ac7

Please sign in to comment.