QFIE package

QFIE.FuzzyEngines module

This module implements the base class for setting up the quantum fuzzy inference engine proposed in doi: 10.1109/TFUZZ.2022.3202348.

class QFIE.FuzzyEngines.QuantumFuzzyEngine(verbose=True)[source]

Bases: object

Class implementing the Quantum Fuzzy Inference Engine proposed in:

G. Acampora, R. Schiattarella and A. Vitiello, “On the Implementation of Fuzzy Inference Engines on Quantum Computers,” in IEEE Transactions on Fuzzy Systems, 2022, doi: 10.1109/TFUZZ.2022.3202348.

add_input_fuzzysets(var_name, set_names, sets)[source]

Set the partition for the input fuzzy variable ‘var_name’.

Parameters:
  • var_name (str) – name of the fuzzy variable defined with input_variable method previously.

  • set_names (list) – list of fuzzy sets’ name as str.

  • sets (list) – list of scikit-fuzzy membership function objects.

Returns:

None

add_output_fuzzysets(var_name, set_names, sets)[source]

Set the partition for the output fuzzy variable ‘var_name’.

Parameters:
  • var_name (str) – name of the fuzzy variable defined with output_variable method previously.

  • set_names (list) – list of fuzzy sets’ name as str.

  • sets (list) – list of scikit-fuzzy membership function objects.

Returns:

None

build_inference_qc(input_values, distributed=False, draw_qc=False, **kwargs)[source]

This function builds the quantum circuit implementing the QFIE, initializing the input quantum registers according to the ‘input_value’ argument.

Parameters:
  • input_values (dict) – dictionary containing the crisp input values of the system. E.g. {‘var_name_1’ (str): x_1 (float), , ‘var_name_n’ (str): x_n (float)}

  • default (draw_qc (Bool -) – False): True for drawing the quantum circuit built. False otherwise.

  • distributed – True to implement the distributed version of the quantum oracle. False otherwise.

Returns:

None

counts_evaluator(n_qubits, counts)[source]

Function returning the alpha values for alpha-cutting the output fuzzy sets according to the probability of measuring the related basis states on the output quantum register.

Parameters:
  • n_qubits (int) – number of qubits in the output quantum register.

  • counts (dict) – counting dictionary of the output quantum register measurement.

Returns:

alpha values for alpha-cutting the output fuzzy sets as ‘dict’.

execute(n_shots: int, plot_histo=False, GPU=False, **kwargs)[source]

Run the inference engine.

Parameters:
  • n_shots (int) – Number of shots.

  • plot_histo (Bool- default False) – True for plotting the counts histogram.

  • GPU – True for using GPU for simulation. Use False if backend is a real device.

Returns:

Crisp output of the system.

filter_rules(rules, output_term)[source]

Searches the rule list and picks only the rules corresponding to the same output value (y_k at fixed k).

Rules must be formatted as follows: ‘if var_1 is x_i and var_2 is x_k and and var_n is x_l then out_1 is y_k’

Parameters:
  • rules (list) – list of rules as strings.

  • output_term (str) – single output term y_k at fixed k as string.

Returns:

Filtered rules as a new list.

input_variable(name, range)[source]

Define the input variable “name” of the system.

Parameters:
  • name (str) – Name of the variable as string.

  • range (np array) – Universe of the discourse for the input variable.

Returns:

None

output_variable(name, range)[source]

Define the output variable “name” of the system.

Parameters:
  • name (str) – Name of the variable as string.

  • range (np array) – Universe of the discourse for the output variable.

Returns:

None

set_rules(rules)[source]

Set the rule-base of the system.

Rules must be formatted as follows: ‘if var_1 is x_i and var_2 is x_k and and var_n is x_l then out_1 is y_k’

Parameters:

rules (list) – list of rules as strings.

Returns:

None

truncate(n, decimals=0)[source]

QFIE.QFS module

QFIE.QFS.compute_qc(backend, qc, qc_label, n_shots, verbose=True, transpilation_info=False)[source]
QFIE.QFS.convert_rule(qc, fuzzy_rule, partitions, output_partition)[source]

Function which convert a fuzzy rule in the equivalent quantum circuit. You can use multiple times convert_rule to concatenate the quantum circuits related to different rules.

QFIE.QFS.generate_circuit(fuzzy_partitions)[source]

Function generating a quantum circuit with width required by QFS

QFIE.QFS.merge_subcounts(subcounts, output_partition)[source]
QFIE.QFS.negation_0(qc, qr, bit_string)[source]

Function which insert a NOT gate if the bit in the rule is 0

QFIE.QFS.output_register(qc, output_partition)[source]
QFIE.QFS.output_single_qubit_register(qc, name)[source]
QFIE.QFS.select_qreg_by_name(qc, name)[source]

Function returning the quantum register in QC selected by name

QFIE.fuzzy_partitions module

class QFIE.fuzzy_partitions.fuzzy_partition(name, sets)[source]

Bases: object

associate_quantum_states()[source]
len_partition()[source]
class QFIE.fuzzy_partitions.fuzzy_rules[source]

Bases: object

add_rules(rule, partitions)[source]

NB: specify in partitions the list of partitions which appears in the rule, in the order in which they appear

Module contents