Skip to main content

seqgentools

Python combinatorics library that generates indexible sequences through combinations, permutations, and/or products of another sequences. It creates the sequences without actually allocating memory so that a sequence having a large, possibly infinite, number of elements can be used in many applications such as an optimal solution searching problem.

Motivation

Python itertools package provides users with capability of creating “iterators for efficient loopings”. From the prospective of “optimization problems”, “itertools” could be a convinient tool to succinctly define a, possibly large, search space without actually allocating memory for the instance of the space.

For example, following code snippet generates a 3-dimensional space that has 1,000 data points:

>>> for x,y,z in itertools.product(range(10), repeat=3):
>>>     # DO work on each "point of (x,y,z)"

However, itertools has one critical drawback to be used as a search space generator for search algorithms: Its element should be accessed sequentially. For example, to access to the last point of (9,9,9) in previous code example, you need to go through all 999 elements from (0,0,0) to (9,9,8). It is because Python iterator does not support indexing. Next code example shows that iterator can not be indexed.

>>> space = itertools.product(range(10), repeat=3)
>>> space[999]
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: 'itertools.product' object is not subscriptable

“seqgentools” takes the core capabilities of “itertools” and adds randomly-accessible indexing capability to them.

>>> import seqgentools as seq
>>> space = seq.Product(range(10), repeat=3)
>>> space[999]
(9, 9, 9)

Installation

“seqgentools” can be easily installed using “pip” as shown below.

>>> pip install seqgentools --user

To access the latest features, please download from this repository using git.

>>> git clone https://github.com/NCAR/seqgentools.git

Getting-started

Whenever possible, “seqgentools” follows conventions of using “itertools” so that user can leverage of their knowledge about “itertools”. If you are not familiar with “itertools”, I believe, it is worth of investing a couple of miniutes to see what it can do for you.

Doing is believing: please follow examples shown below to get an idea of how “seqgentools” works.

>>> import seqgentools as seq
>>>
>>> ###### Product #######
>>>
>>> prod = seq.Product(range(2), range(2))
>>> list(prod)
[(0, 0), (0, 1), (1, 0), (1, 1)]
>>> prod[3]
(1, 1)
>>>
>>> ###### Permutations #######
>>>
>>> perm = seq.Permutations("ABC", 2)
>>> list(perm)
[('A', 'B'), ('A', 'C'), ('B', 'A'), ('B', 'C'), ('C', 'A'),
    ('C', 'B')]
>>> perm[3]
('B', 'C')
>>>
>>> ###### Combinations #######
>>>
>>> comb = seq.Combinations("ABC", 2)
>>> list(comb)
[('A', 'B'), ('A', 'C'), ('B', 'C')]
>>> comb[2]
('B', 'C')
>>>
>>> ###### Combinations_with_replacement #######
>>>
>>> combr = seq.Combinations_with_replacement("ABC", 2)
>>> list(combr)
[('A', 'A'), ('A', 'B'), ('A', 'C'), ('B', 'B'), ('B', 'C'), ('C', 'C')]
>>> combr[2]
('A', 'C')
>>>
>>> ###### PermutationRange #######
>>>
>>> permrange = seq.PermutationRange("ABC")
>>> list(permrange)
[(), ('A',), ('B',), ('C',), ('A', 'B'), ('A', 'C'), ('B', 'A'),
    ('B', 'C'), ('C', 'A'), ('C', 'B'), ('A', 'B', 'C'), ('A', 'C', 'B'),
    ('B', 'A', 'C'), ('B', 'C', 'A'), ('C', 'A', 'B'), ('C', 'B', 'A')]
>>> permrange[3]
('C',)
>>>
>>> ###### CombinationRange #######
>>>
>>> combrange = seq.CombinationRange("ABC")
>>> list(combrange)
[(), ('A',), ('B',), ('C',), ('A', 'B'), ('A', 'C'), ('B', 'C'),
    ('A', 'B', 'C')]
>>> combrange[2]
('B',)

Search-space Generator

“seqgentools” contains a hierachical search space generator that can dramatically reduce

the total size of search space compared to naive products of each search dimensions.

API Documentation

Under development.

Until API documentation is ready, please see “itertools” API documentation as “seqgentools”, whenever possible, follows “itertools” API.

As of this version, “seqgentools” implemented follwoing sequence generators.

  • Count: generates a sequence of, possibily infinite, evenly spaced numbers

  • Cycle: generates a cyclic chain of another sequence

  • Repeat: generates a repeating sequece of object

  • Chain: generates a chained sequence of another sequences

  • Product: generates a sequence of mathematical product of another sequences

  • Permutations: generates a permuted sequence of another sequence

  • Combinations: generates a combinated sequence of another sequence

  • Combinations_with_replacement: generates a combinated sequence of another sequence with replacement

  • PermutationRange: generates a chained sequence of series of permuted sequence

    ranging r=0 to r=n of another sequence

  • CombinationRange: generates a chained sequence of series of combinated sequence

    ranging r=0 to r=n of another sequence

  • Wrapper: generates a sequence from Python sequece data types

  • Fibonacci: generates an random-accesible Fibonacci sequence

[NOTES]

  • “seqgentools” supports randomly accessible indexing of infinite sequences.

  • “Product”, “Permutations”, “Combinations”, “Combinations_with_replacement”, “PermutationRange”, and “CombinationRange” do not accept infinite sequence as their input(s).

  • test codes in “tests” subdirectory could be a good place to start further investigation.

  • “Wrapper” sequence generator wraps Python sequence data types such as list, tuple, dictionary, string, set, etc.

  • The name of sequence generators in “seqgentools” starts with a capital letter while “itertools” starts with a lower-case. This is to emphasize that sequence generators are instantiated from class, not from function.

Metadata

Release files for seqgentools 0.0.16

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for seqgentools 0.0.16
File Size Uploaded Provenance Actions
seqgentools-0.0.16.tar.gz 11.0 kB Without provenance Details for seqgentools-0.0.16.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for seqgentools 0.0.16
File Interpreter ABI Platform Actions
seqgentools-0.0.16-py2.py3-none-any.whl Python 3, Python 2 none any Details for seqgentools-0.0.16-py2.py3-none-any.whl

Total release size: 25.8 kB

Release files / seqgentools-0.0.16.tar.gz

Download URL seqgentools-0.0.16.tar.gz
Size 11.0 kB
Tags Source
SHA-256 checksum
How to use checksums
0459e26bb5ad9504d3913e8ac4cdd393f528c7f5e9f8fef54759ca4cace40278
BLAKE2b-256 checksum
How to use checksums
c44181826b72b1138bea2ccf07e05734426bf4d7a9feae4e6f2aa27482ac344a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.12.1 pkginfo/1.4.2 requests/2.18.4 setuptools/40.6.2 requests-toolbelt/0.8.0 tqdm/4.26.0 CPython/2.7.10

Release files / seqgentools-0.0.16-py2.py3-none-any.whl

Download URL seqgentools-0.0.16-py2.py3-none-any.whl
Size 14.8 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
a68f00bb5ebc467bc5f689fdbe23503c9711505383706d2152091132743de847
BLAKE2b-256 checksum
How to use checksums
c2b12e40f094ee1efc516ba5e2b566d0942ce4926471442a850b4b0e2826c65f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.12.1 pkginfo/1.4.2 requests/2.18.4 setuptools/40.6.2 requests-toolbelt/0.8.0 tqdm/4.26.0 CPython/2.7.10

Security for seqgentools 0.0.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page