Module qrbs

class neasqc_qrbs.qrbs.WorkingMemory(facts=None)

Bases: object

Class representing a Working Memory.

A Working Memory is an element of a Rule-Based System that manages its facts, keeping trace of their state.

_facts

List of facts asserted into the system.

Type:

List[Fact], optional

assert_fact(fact) Fact

Asserts a fact into the memory.

Parameters:

fact (Fact) – The fact to be asserted.

Returns:

The asserted fact.

Return type:

Fact

retract_fact(fact) None

Retracts a fact from the memory.

Parameters:

fact (Fact) – The fact to be retracted.

class neasqc_qrbs.qrbs.InferenceEngine(rules=None, islands=None)

Bases: object

Class representing an Inference Engine.

An Inference Engine is an element of a Rule-Based System that manages its rules and knowledge islands, providing the tools to evaluate them in order.

_rules

List of rules established for the system.

Type:

List[Rule], optional

_islands

List of knowledge island established for the system.

Type:

List[KnowledgeIsland], optional

assert_rule(rule) Rule

Asserts a rule into the engine.

Parameters:

rule (Rule) – The rule to be asserted.

Returns:

The asserted rule.

Return type:

Rule

retract_rule(rule) None

Retracts a rule from the engine.

Parameters:

rule (Rule) – The rule to be retracted.

Raises:

AttributeError – In case the rule to be retracted is part of a knowledge island.

assert_island(island) KnowledgeIsland

Asserts a knowledge island into the engine.

Parameters:

island (KnowledgeIsland) – The knowledge island to be asserted.

Returns:

The asserted knowledge island.

Return type:

KnowledgeIsland

Raises:

AttributeError – In case the rules that compose the knowledge island are not asserted in the system’s inference engine or the rules that compose the knowledge island are not chained.

retract_island(island) None

Retracts a knowledge island from the engine.

Parameters:

island (KnowledgeIsland) – The knowledge island to be retracted.

class neasqc_qrbs.qrbs.QRBS

Bases: object

Class representing a Quantum Rule-Based System.

A Quantum Rule-Based System (QRBS) is a Rule-Based System implemented in a quantum computer, taking advatange of some of its capabilities, like quantum superposition, to represent certain aspects such as precision and certainty.

_memory

The Working Memory of the system.

Type:

WorkingMemory

_engine

The Inference Engine of the system.

Type:

InferenceEngine

assert_fact(attribute, value, precision=0.0) Fact

Creates a fact and asserts it into the system.

Parameters:
  • attribute (str) – The attribute of the fact.

  • value (float) – The value of the fact.

  • precision (float, optional) – The precision of the fact.

Returns:

The asserted fact.

Return type:

Fact

retract_fact(fact) None

Retracts a fact from the system.

Parameters:

fact (Fact) – The fact to be retracted.

assert_rule(lefthandside, righthandside, certainty=0.0) Rule

Creates a rule and asserts it into the system.

Parameters:
  • lefthandside (LeftHandSide) – The left hand side of the rule.

  • righthandside (Fact) – The right hand side of the rule.

  • certainty (float, optional) – The certainty of the rule.

Returns:

The asserted rule.

Return type:

Rule

retract_rule(rule) None

Retracts a rule from the system.

Parameters:

rule (Rule) – The rule to be retracted.

assert_island(rules) KnowledgeIsland

Creates a knowledge island and asserts it into the system.

Parameters:

rules (List[Rule]) – The rules of the knowledge island.

Returns:

The asserted knowledge island.

Return type:

KnowledgeIsland

retract_island(island) None

Retracts a knowledge island from the system.

Parameters:

island (KnowledgeIsland) – The knowledge island to be retracted.

class neasqc_qrbs.qrbs.QPU

Bases: ABC

Interface defining the structure to implement Quantum Processing Units (QPU).

abstract static evaluate(qrbs) bool

Evaluates whether a QRBS can be executed on this QPU.

Parameters:

qrbs (QRBS) – The QRBS to be evaluated.

abstract static execute(qrbs) None

Executes the QRBS on this QPU.

Parameters:

qrbs (QRBS) – The QRBS to be executed.

class neasqc_qrbs.qrbs.MyQlmQPU

Bases: QPU

myQLM implementation of a Quantum Processing Unit (QPU).

MAX_ARITY = 20
BUILDERS = {'bayes': <class 'neasqc_qrbs.knowledge_rep.BuilderBayes'>, 'cf': <class 'neasqc_qrbs.knowledge_rep.BuilderImpl'>, 'fuzzy': <class 'neasqc_qrbs.knowledge_rep.BuilderFuzzy'>}
static evaluate(qrbs, eval_islands=None, model='cf') bool

Evaluates whether a QRBS can be executed on this QPU.

Parameters:
  • qrbs (QRBS) – The QRBS to be evaluated.

  • eval_islands (List[KnowledgeIsland], optional) – A list of specific KnowledgeIsland to be evaluated.

  • model (str, optional) – The code of the model indicated.

Raises:

ValueError – In case a specified knowledge island is not part of the QRBS or an evaluated knowledge island requires more qubits than supported.

static execute(qrbs, islands=None, model='cf') None

Executes the QRBS on this QPU.

Parameters:
  • qrbs (QRBS) – The QRBS to be executed.

  • islands (List[KnowledgeIsland], optional) – A list of specific KnowledgeIsland to be executed.

  • model (str, optional) – The code of the model indicated.