Skip to content

Commit fb48d99

Browse files
committed
Release 3.1
1 parent 42f707b commit fb48d99

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

110 files changed

+3206
-707
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -249,3 +249,5 @@ multiColSplay/**
249249
singleColSplay/**
250250
sym
251251
symsEnumsSplay/**
252+
253+
src/pykx/pykx_init.q_

LICENSE.txt

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
This work is dual licensed under "Apache 2.0" and the "Software License for q.so", users are required to abide by the terms of both licenses in their entirety. The terms of these licenses are included below
1+
All files contained within this repository are not covered by a single license. The following outlines the differences.
2+
3+
1. All files and folders contained within the source code directory 'src/pykx/q.so/' are licensed under the terms of the 'Software License for q.so' which are included below
4+
2. All other files within this repository are licensed under the "Apache 2.0" license include below
25

36
***********************************************************************************
47
Apache 2.0

README.md

+6-4
Original file line numberDiff line numberDiff line change
@@ -95,24 +95,26 @@ PyKX depends on the following third-party Python packages:
9595

9696
- `pandas>=1.2, <2.0; python_version=='3.8'`
9797
- `pandas>=1.2, <=2.2.3; python_version>'3.8'`
98-
- `numpy~=1.22, <2.0; python_version<'3.11'`
99-
- `numpy~=1.23, <2.0; python_version=='3.11'`
100-
- `numpy~=1.26, <2.0; python_version=='3.12'`
98+
- `numpy~=1.22; python_version<'3.11'`
99+
- `numpy~=1.23; python_version=='3.11'`
100+
- `numpy~=1.26; python_version>'3.11'`
101101
- `pytz>=2022.1`
102102
- `toml~=0.10.2`
103103
- `dill>=0.2.0`
104104
- `requests>=2.25.0`
105105

106106
They are installed automatically by `pip` when PyKX is installed.
107107

108-
PyKX also has an optional Python dependency of `pyarrow>=3.0.0`, which can be included by installing the `pyarrow` extra, e.g. `pip install pykx[pyarrow]`
108+
PyKX also has an optional Python dependency of `pyarrow>=3.0.0, <19.0.0`, which can be included by installing the `pyarrow` extra, e.g. `pip install pykx[pyarrow]`
109109

110110
When using PyKX with KX Dashboards users will be required to install `ast2json~=0.3` this can be installed using the `dashboards` extra, e.g. `pip install pykx[dashboards]`
111111

112112
When using PyKX Streaming users may require the ability to stop processes initialized in a now unavailable process to facilitate this PyKX can make use of `psutil` this can be installed using the `streaming` extra, e.g. `pip install pykx[streaming]`
113113

114114
When using Streamlit users will be required to install `streamlit~=1.28` this can be installed using the `streamlit` extra, e.g. `pip install pykx[streamlit]`
115115

116+
When attempting to convert data to/from PyTorch users will be required to install `torch>2.1` this can be installed using the `torch` extra, e.g. `pip install pykx[torch]`
117+
116118
**Warning:** Trying to use the `pa` conversion methods of `pykx.K` objects or the `pykx.toq.from_arrow` method when PyArrow is not installed (or could not be imported without error) will raise a `pykx.PyArrowUnavailable` exception.
117119

118120
#### Optional Non-Python Dependencies

conda-recipe/conda_build_config.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ python:
44
- 3.10
55
- 3.11
66
- 3.12
7+
- 3.13

conda-recipe/meta.yaml

+11-4
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,25 @@ requirements:
1818
- python
1919
- setuptools>=68.0
2020
- setuptools_scm[toml]>=8.0.0
21-
- cython==3.0.0
22-
- numpy==1.26 # [py==312]
23-
- numpy==1.22.* # [py<312]
21+
- cython==3.0.*
22+
- numpy==2.* # [py==313]
23+
- numpy==2.0.* # [py==312]
24+
- numpy==2.0.* # [py==311]
25+
- numpy==2.0.* # [py==310]
26+
- numpy==2.0.* # [py==39]
27+
- numpy==1.22.* # [py==38]
28+
- numpy==1.20.* # [py==37]
2429
- tomli>=2.0.1
2530
- wheel>=0.36
2631
- sysroot_linux-64 # [linux64]
2732

2833
run:
2934
- python
30-
- numpy>=1.22,<2.0
35+
- numpy>=1.20 # [py==37]
36+
- numpy>=1.22 # [py>37]
3137
- pandas>=1.2, <=2.2.3 # [py>38]
3238
- pandas<2.0 # [py==38]
39+
- pyarrow>=3.0.0, <19.0.0
3340
- pytz>=2022.1
3441
- toml>=0.10.2
3542
- dill>=0.2.0

docs/api/pykx-execution/q.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ pykx.List(pykx.q('
112112

113113
Restricted evaluation of a parse tree.
114114

115-
Behaves similar to [`eval`](#eval) except the evaluation is blocked from modifying values or global state.
115+
Behaves similar to [`eval`](#eval) except the evaluation is blocked from modifying state for any handle context other than 0.
116116

117117
```python
118118
>>> pykx.q.reval(pykx.q.parse(b'til 10'))

docs/beta-features/index.md

+13-8
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
1+
---
2+
title: PyKX Beta Features
3+
description: PyKX features in beta status
4+
date: January 2025
5+
author: KX Systems, Inc.,
6+
tags: PyKX, beta features,
7+
---
18
# Beta Features
29

3-
!!! "Note"
4-
5-
There are currently no active features in beta status, the following page outlines broadly the concept of beta features within PyKX and how it is managed today
10+
_This page provides an overview of PyKX Beta Features, including what they are, how to enable them, and what features are available._
611

712
## What is a Beta Feature?
813

@@ -12,14 +17,14 @@ Feedback on Beta Feature development is incredibly helpful and helps to determin
1217

1318
## How do I enable Beta Features?
1419

15-
Within PyKX beta features are enabled through the use of a configuration/environment variable `PYKX_BETA_FEATURES`, within a Python session users can set this prior to importing PyKX as shown below, note that when enabled you will be able to see what features are in beta through access of `kx.beta_features`:
20+
Enable PyKX beta features using the `#!python PYKX_BETA_FEATURES` configuration/environment variable. Set this before importing PyKX in a Python session, as shown below, to view available beta features through `#!python kx.beta_features`:
1621

1722
```python
1823
>>> import os
1924
>>> os.environ['PYKX_BETA_FEATURES'] = 'True'
2025
>>> import pykx as kx
2126
>>> kx.beta_features
22-
[]
27+
['PyTorch Conversions']
2328
```
2429

2530
Alternatively you can set beta features to be available at all times by adding `PYKX_BETA_FEATURES` to your `.pykx-config` file as outlined [here](../user-guide/configuration.md#configuration-file). An example of a configuration making use of this is as follows:
@@ -34,12 +39,12 @@ PYKX_BETA_FEATURES='true'
3439

3540
## What Beta Features are available?
3641

37-
As mentioned above the list of available features to a user is contained within the `beta_features` property, for users with these features available you can get access to this information as follows within a Python session
42+
As mentioned above, the `beta_features` property contains the list of available features. You can retrieve this information in a Python session as follows:
3843

3944
```python
4045
>>> import pykx as kx
4146
>>> kx.beta_features
42-
[]
47+
['PyTorch Conversions']
4348
```
4449

45-
There are currently no active features in beta status. This page will be updated when new beta features are added at a future point in time.
50+
1. [`PyTorch Conversions`](torch.md): Allow users to convert numeric type PyKX vectors and N-Dimensional lists to PyTorch Tensor objects.

docs/beta-features/torch.md

+110
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
---
2+
title: PyTorch Conversions
3+
description: PyTorch Tensor Conversions beta feature in PyKX
4+
date: January 2025
5+
author: KX Systems, Inc.,
6+
tags: PyKX, PyTorch Tensor
7+
---
8+
# PyTorch Conversions
9+
10+
_This page provides an overview of PyTorch Conversions, a beta feature in PyKX._
11+
12+
!!! Warning
13+
14+
This functionality is provided as a Beta Feature and is subject to change. To enable this functionality for testing please follow the configuration instructions [here](../user-guide/configuration.md) setting `PYKX_BETA_FEATURES='true'`.
15+
16+
## Introduction
17+
18+
Commonly used in the development of complex machine learning algorithms, PyTorch is a machine learning library based on the Torch library and is used in applications such as computer vision and natural language processing. Originally developed by Meta AI it is now widely used in the open-source community for algorithm development.
19+
20+
This beta feature allows PyKX users to convert PyKX Vector/List objects into their PyTorch [Tensor](https://pytorch.org/docs/stable/tensors.html) equivalents.
21+
22+
## Requirements and limitations
23+
24+
25+
Before you run this functionality, first you must install `torch>2.1` in your local Python session, by using the following command:
26+
27+
```bash
28+
pip install pykx[torch]
29+
```
30+
31+
## Functional walkthrough
32+
33+
This walkthrough demonstrates the following steps:
34+
35+
1. Convert a PyKX Vector object to a Tensor object.
36+
1. Convert a PyKX List object to a Tensor object.
37+
1. Convert a Tensor object to a PyKX equivalent object.
38+
39+
### Vector to Tensor
40+
41+
Use the `*.pt()` methods to convert PyKX numeric data representations to Tensor objects. In the example below we convert PyKX numeric types to their PyTorch Tensor equivalents:
42+
43+
```python
44+
>>> import os
45+
>>> os.environ['PYKX_BETA_FEATURES'] = 'True'
46+
>>> import pykx as kx
47+
>>> svec = kx.q('1 2 3h')
48+
>>> lvec = kx.q('1 2 3j')
49+
>>> rvec = kx.q('1 2 3e')
50+
>>> fvec = kx.q('1 2 3f')
51+
>>> svec.pt()
52+
tensor([1, 2, 3], dtype=torch.int16)
53+
>>> lvec.pt()
54+
tensor([1, 2, 3])
55+
>>> rvec.pt()
56+
tensor([1., 2., 3.])
57+
>>> fvec.pt()
58+
tensor([1., 2., 3.], dtype=torch.float64)
59+
```
60+
61+
In particular note in the above that the data types are converted to their Tensor size equivalent.
62+
63+
### List to Tensor
64+
65+
To convert PyKX List objects to Tensors, two criteria must be met:
66+
67+
1. The `#!python pykx.List` contains only data of a single type.
68+
1. The `#!python pykx.List` is an N-Dimensional regularly shaped/rectangular structure.
69+
70+
By default conversions to a `#!python torch.Tensor` object test for these criteria and it throws an error if they are not met as follows:
71+
72+
```python
73+
>>> import os
74+
>>> os.environ['PYKX_BETA_FEATURES'] = 'True'
75+
>>> import pykx as kx
76+
>>> kx.q('(1 2;2 3f)').pt()
77+
TypeError: Data must be a singular type "rectangular" matrix
78+
```
79+
80+
A working example of this is as follows:
81+
82+
```python
83+
>>> kx.q('100 100 100#1000000?1f').pt()
84+
tensor([[[0.3928, 0.5171, 0.5160, ..., 0.3410, 0.8618, 0.5549],
85+
[0.0617, 0.2858, 0.6685, ..., 0.9234, 0.4016, 0.5619],
86+
[0.7249, 0.8112, 0.2087, ..., 0.3187, 0.1873, 0.8416],
87+
...,
88+
dtype=torch.float64)
89+
```
90+
91+
Having to pre-compute the shape of the data can slow down the processing of large matrices. To avoid this, if you already know the final shape of the tensor, you can specify it using the `#!python reshape` keyword in advance.
92+
93+
```python
94+
>>> kx.q('100 100 100#1000000?1f').pt(reshape=[100, 100, 100])
95+
tensor([[[0.3928, 0.5171, 0.5160, ..., 0.3410, 0.8618, 0.5549],
96+
[0.0617, 0.2858, 0.6685, ..., 0.9234, 0.4016, 0.5619],
97+
[0.7249, 0.8112, 0.2087, ..., 0.3187, 0.1873, 0.8416],
98+
...,
99+
dtype=torch.float64)
100+
```
101+
102+
While not clear from the above for particularly complex nested `#!python pykx.List` objects setting the data shape can provide significant performance boosts:
103+
104+
```python
105+
lst = kx.q('100 100 100 100#100000000?1f')
106+
%timeit lst.pt()
107+
# 1.22 s ± 24.4 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)
108+
%timeit lst.pt(reshape=[100, 100, 100, 100])
109+
# 265 ms ± 4.96 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)
110+
```

docs/examples/jupyter-integration.ipynb

+7-93
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@
1919
"1. [Execute against Embedded q](#3-execute-against-embedded-q)\n",
2020
"1. [SQL interface](#4-sql-interface)\n",
2121
"1. [q namespaces](#5-q-namespaces)\n",
22-
"1. [(Advanced) q over IPC](#6-advanced-q-over-ipc)"
22+
"1. [q over IPC](#6-q-over-ipc)\n",
23+
"1. [q first mode](#7-q-first-mode)\n",
24+
"1. [Saving code blocks](#8-saving-code-blocks)"
2325
]
2426
},
2527
{
@@ -157,94 +159,6 @@
157159
"([] a: 1 2 3)"
158160
]
159161
},
160-
{
161-
"cell_type": "markdown",
162-
"id": "cda0d38a",
163-
"metadata": {},
164-
"source": [
165-
"#### Executing against an external q process over IPC\n",
166-
"\n",
167-
"Connection information can also be included after the `%%q` to connect to a remote `q` process over\n",
168-
"IPC.\n",
169-
"\n",
170-
"Here is the list of currently supported connection parameters.\n",
171-
"If they specify a type a second value is expected to follow them to be used as the parameter.\n",
172-
"If no type follows them they can be used as a stand alone flag.\n",
173-
"\n",
174-
"```\n",
175-
"--host: A string object denoting the host to connect to\n",
176-
"--port: An int object denoting the port to connect over\n",
177-
"--user: A str object denoting the username to use when connecting\n",
178-
"--password: A str object denoting the password to use when connecting\n",
179-
"--timeout: A float object denoting the time in seconds before the query\n",
180-
" times out, defaults to no timeout\n",
181-
"--nolarge: Disable messages over 2GB being sent / received\n",
182-
"--tls: Use a tls connection\n",
183-
"--unix: Use a unix connection\n",
184-
"--reconnection_attempts: An int object denoting how many\n",
185-
" reconnection attempts to make\n",
186-
"--noctx: Disable the context interface\n",
187-
"```\n",
188-
"\n",
189-
"Connect to a q server running on `localhost` at port `5001` as `user` using password `password`\n",
190-
"and disable the context interface."
191-
]
192-
},
193-
{
194-
"cell_type": "code",
195-
"execution_count": null,
196-
"id": "1faca1e1",
197-
"metadata": {},
198-
"outputs": [],
199-
"source": [
200-
"%%q --host localhost --port 5000 --user user --pass password --noctx\n",
201-
"til 10"
202-
]
203-
},
204-
{
205-
"cell_type": "markdown",
206-
"id": "f046ebb6",
207-
"metadata": {},
208-
"source": [
209-
"All connection arguments are optional with the exception of the `--port` argument. If `--host` is not provided `localhost` will be used as the default host."
210-
]
211-
},
212-
{
213-
"cell_type": "code",
214-
"execution_count": null,
215-
"id": "615d7d2e",
216-
"metadata": {},
217-
"outputs": [],
218-
"source": [
219-
"%%q --port 5000\n",
220-
"tab:([]a:1000?1000; b:1000?500.0; c:1000?`AAPL`MSFT`GOOG);"
221-
]
222-
},
223-
{
224-
"cell_type": "markdown",
225-
"id": "d756f342",
226-
"metadata": {},
227-
"source": [
228-
"It is possible to execute `q` code spanning multiple lines."
229-
]
230-
},
231-
{
232-
"cell_type": "code",
233-
"execution_count": null,
234-
"id": "c739a80a",
235-
"metadata": {
236-
"scrolled": true
237-
},
238-
"outputs": [],
239-
"source": [
240-
"%%q --port 5000\n",
241-
"afunc: {[x; y]\n",
242-
" x + y \n",
243-
" };\n",
244-
"afunc[0; 1]\n",
245-
"afunc[2; 3]"
246-
]
247-
},
248162
{
249163
"cell_type": "markdown",
250164
"id": "2905895e",
@@ -313,7 +227,7 @@
313227
"id": "52ca850e",
314228
"metadata": {},
315229
"source": [
316-
"## 6. (Advanced) q over IPC\n",
230+
"## 6. q over IPC\n",
317231
"\n",
318232
"After `%%q` you can include connection information, if you wish to connect to a remote `q` process over IPC. \n",
319233
"\n",
@@ -386,7 +300,7 @@
386300
"source": [
387301
"%%q --port 5000\n",
388302
"afunc: {[x; y]\n",
389-
" x + y \n",
303+
" x + y\n",
390304
" };\n",
391305
"afunc[0; 1]\n",
392306
"afunc[2; 3]"
@@ -408,7 +322,7 @@
408322
"id": "607997ac-e7d7-4cc9-a06f-aa1cd3d742ce",
409323
"metadata": {},
410324
"source": [
411-
"#### q first mode\n",
325+
"## 7. q first mode\n",
412326
"q first mode can be enabled by importing PyKX after setting the environment variable `PYKX_JUPYTERQ` to `true`, or at runtime use:"
413327
]
414328
},
@@ -533,7 +447,7 @@
533447
"id": "080dd085-e54f-478c-a305-eac9f23db020",
534448
"metadata": {},
535449
"source": [
536-
"#### Saving code blocks\n",
450+
"## 8. Saving code blocks\n",
537451
"The `--save` feature allows user to save code in a cell as a q file.\n",
538452
"\n",
539453
"To use this feature, include `--save` followed by the `path` of the file.\n",

0 commit comments

Comments
 (0)