A SpinQ quantum state tomography data acquisition toolset
Project description
Quantum State Tomography
Quantum State Tomography is the process of completely characterizing the quantum state of a system by performing a series of measurements on identical copies of the state. It allows us to mathematically reconstruct the density matrix, which fully describes the system.
Quantum State Tomography is generally a two-phase process:
- Data Acquisition: Run quantum circuits on a simulator or real hardware to gather measurement statistics for a complete set of observables. In this toolset, we specifically use the complete set of tensor products of the non-identity Pauli matrices ($X, Y, Z$).
- State Reconstruction: Use the acquired measurement data to mathematically reconstruct the density matrix of the quantum state.
[!NOTE] This toolset is solely focused on Data Acquisition (
qtomos). State reconstruction is not handled by this repository.
Currently, data acquisition supports multiple predefined quantum states (GHZ, Phi+, W, and random circuits) defined in the circuits_catalog. You can dynamically select which circuit to prepare during acquisition.
This is now you basically use this tool:
# acquire data for the complete set of tensor products of the non-identity Pauli matrices (X, Y, Z), on the noiseless simulator, on a three qubit GHZ, using 500 shots for each measurement, saving the results to output.json
qtomos --circuit ghz --mode sim --shots 500 --file output.json
Read on to learn how to install and use this tool.
IMPORTANT: to connect to a real SpinQ QPU you need to provide your connection credentials. Read section "Acquire Data from the QPU" below. Do not put your access credentials in a file that is commited to the repository.
Install
SpinQit currently works only on Python 3.8.
The file .python-version will most likely take care of setting up your environment with the correct Python version (if 3.8 is installed on your machine; if not, use pyenv, Conda or whatever manager you prefer to install it).
We suggest installing everything in a virtual environment.
To set up your environment, run:
python -m venv .venv
source .venv/bin/activate
pip install -e .
On Arm based Macs, you'll have issues with the default location of SPinQit libraries. Use the fix-spinqit-macos-arm.shscript to fix it (changes will only affect that venv)
Data Acquisition
The first time you run qtomos, it may take longer (the SpinQ SDK might be downloading required assets).
Simulate Acquisition
To run a simulation for a specific observable (e.g., XX) on a GHZ state:
qtomos --circuit ghz --mode sim --observable XX --file output.json
Selecting a Circuit
You can select the quantum state to prepare using the -c or --circuit argument. The CLI dynamically exposes all circuits defined in qtomos/circuits_catalog.py. Current available states include ghz (default), phi_plus, w, and random.
# Acquire the ZZZ observable for a W state
qtomos --circuit w --mode sim --observable ZZZ --file output.json
# Acquire the full set for a random circuit
qtomos --circuit random --mode sim --file output.json
By default, the measurement bitstrings use Big-Endian format (qubit 0 is the leftmost bit). If you prefer Little-Endian (qubit 0 is the rightmost bit, similar to Qiskit), use the --endian little flag:
qtomos --circuit ghz --mode sim --observable XX --endian little --file output.json
Acquire Data from the QPU
Before running on the real hardware (QPU), you need to configure your environment variables.
Copy the .env.example file to .env and fill in your connection details:
cp .env.example .env
Edit .env to match your credentials:
IP=192.168.172.233
PORT=50177
USERNAME=your_username
PASSWORD=your_password
Then, to acquire data for the same specific observable on the real hardware:
qtomos --circuit ghz --mode qpu --observable XX --file output.json
Drawing Circuits
To generate a visual representation of the quantum circuit instead of simulating it or running it on the QPU, use the draw mode. This will save a .png image of the circuit in your current directory (e.g., XX_of_a_Ghz.png):
qtomos --circuit ghz --mode draw --observable XX --file output.json
Full Tomographic Acquisition
To perform a full tomographic acquisition (all observables), omit the --observable argument. This defaults to 3 qubits.
# 3-qubit full tomographic acquisition on simulator
qtomos --circuit ghz --mode sim --file output.json
# 3-qubit full tomographic acquisition on QPU
qtomos --circuit ghz --mode qpu --file output.json
Parametrizing Shots
By default, execution uses 1024 shots. You can customize the number of shots using the --shots flag:
qtomos --circuit ghz --mode sim --file output.json --shots 500
Saving Output and Format
The output JSON file has the following structure:
{
"metadata": {
"circuit_name": "ghz",
"qubits": 2,
"mode": "sim",
"shots": 500,
"endian": "big",
"timestamps": {
"start": "2026-06-25T20:51:33.528965-03:00",
"end": "2026-06-25T20:51:33.530752-03:00"
}
},
"measurements": {
"XX": {
"timestamps": {
"start": "2026-06-25T20:51:33.529028-03:00",
"end": "2026-06-25T20:51:33.530740-03:00"
},
"counts": {
"00": 250,
"11": 250
},
"qasm": "...",
"native": "..."
},
...
}
}
Help (qtomos)
For a complete list of options, use the --help flag:
$ qtomos --help
usage: qtomos [-h] [-m {sim,qpu,draw}] [-c {ghz,phi_plus,random,w}]
[-q QUBITS] [-e {big,little}] [--shots SHOTS] -f FILE
[-o OBSERVABLE]
Acquire SpinQ Tomographic Data
optional arguments:
-h, --help show this help message and exit
-m {sim,qpu,draw}, --mode {sim,qpu,draw}
Execution mode: sim (simulator), qpu (real computer),
or draw (print circuit)
-c {ghz,phi_plus,random,w}, --circuit {ghz,phi_plus,random,w}
Circuit to prepare
-q QUBITS, --qubits QUBITS
Number of qubits (inferred from observable if omitted,
defaults to 3)
-e {big,little}, --endian {big,little}
Endianness for output bitstrings: big (q[0] is
leftmost) or little (q[0] is rightmost)
--shots SHOTS Number of shots for execution
-f FILE, --file FILE Output JSON file path
-o OBSERVABLE, --observable OBSERVABLE
Measure a single observable (e.g., XX, XYZ)
Project Structure
The codebase is structured as follows:
pyproject.toml: The package configuration file defining dependencies and the CLI entry point.qtomos/: Directory containing the project's internal modules and CLI:qtomos/__init__.py: Initializer that exposesqtomosas a Python package.qtomos/cli.py: CLI entry-point script for data acquisition. It handles argument parsing (simulator, real QPU, or circuit drawing, shots, endianness) and prints the structured JSON output with metadata.qtomos/acquisition.py: Contains the core logic and programmatic API (measure_observableandmeasure_all_observables) for executing the quantum circuits and gathering measurement statistics.qtomos/circuits_catalog.py: A catalog of pre-defined quantum circuits. The CLI dynamically discovers states defined here (e.g.,ghz,phi_plus,w,random).qtomos/utils.py: Contains all shared mathematical utilities, including Pauli basis generation, match filtering, and average expectation calculation for marginal operators.
tests/: Directory for automated tests:tests/test_tomography.py: Unit test suite to validate supporting mathematical operations.
Running Unit Tests
To run the automated unit tests and verify the consistency of the project, execute the following command from the repository root:
python tests/test_tomography.py
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file qtomos-0.1.0.tar.gz.
File metadata
- Download URL: qtomos-0.1.0.tar.gz
- Upload date:
- Size: 11.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8e2c550bfecd5cd0c718a3ca00d8cc5f07f2ab3f53bac810a6be3b010ffb3043
|
|
| MD5 |
98ee19512591b9f9c044c6da7ae90721
|
|
| BLAKE2b-256 |
53087273de604fad72c935d21b8315b33691a3a4cd0e67e47d8b28af2530244d
|
Provenance
The following attestation bundles were made for qtomos-0.1.0.tar.gz:
Publisher:
publish.yml on lifia-unlp/qtomos
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
qtomos-0.1.0.tar.gz -
Subject digest:
8e2c550bfecd5cd0c718a3ca00d8cc5f07f2ab3f53bac810a6be3b010ffb3043 - Sigstore transparency entry: 1960788993
- Sigstore integration time:
-
Permalink:
lifia-unlp/qtomos@976a457f99b9fc0225e7d0bde67ceee532033336 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/lifia-unlp
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@976a457f99b9fc0225e7d0bde67ceee532033336 -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file qtomos-0.1.0-py3-none-any.whl.
File metadata
- Download URL: qtomos-0.1.0-py3-none-any.whl
- Upload date:
- Size: 9.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a260e4ec52247cea1ad607d43ab4edb1accd941d07c888c54370f0061b3eb148
|
|
| MD5 |
9e815fbcad77af337e170ceeb02741ff
|
|
| BLAKE2b-256 |
b6c8b842021fdd2bc82b78c8b8989e182ee895763eb08505da43ffe26221a1e9
|
Provenance
The following attestation bundles were made for qtomos-0.1.0-py3-none-any.whl:
Publisher:
publish.yml on lifia-unlp/qtomos
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
qtomos-0.1.0-py3-none-any.whl -
Subject digest:
a260e4ec52247cea1ad607d43ab4edb1accd941d07c888c54370f0061b3eb148 - Sigstore transparency entry: 1960789191
- Sigstore integration time:
-
Permalink:
lifia-unlp/qtomos@976a457f99b9fc0225e7d0bde67ceee532033336 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/lifia-unlp
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@976a457f99b9fc0225e7d0bde67ceee532033336 -
Trigger Event:
workflow_dispatch
-
Statement type: