qi-utilities 0.2.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- qi_utilities-0.2.1/LICENSE +21 -0
- qi_utilities-0.2.1/PKG-INFO +86 -0
- qi_utilities-0.2.1/README.md +58 -0
- qi_utilities-0.2.1/pyproject.toml +53 -0
- qi_utilities-0.2.1/qi_utilities/__init__.py +0 -0
- qi_utilities-0.2.1/qi_utilities/algorithms/__init__.py +0 -0
- qi_utilities-0.2.1/qi_utilities/algorithms/trotterization.py +153 -0
- qi_utilities-0.2.1/qi_utilities/classical_solvers/__init__.py +0 -0
- qi_utilities-0.2.1/qi_utilities/classical_solvers/time_evolution.py +124 -0
- qi_utilities-0.2.1/qi_utilities/factsheets/__init__.py +0 -0
- qi_utilities-0.2.1/qi_utilities/notebook_guides/__init__.py +0 -0
- qi_utilities-0.2.1/qi_utilities/notebook_guides/figures/__init__.py +0 -0
- qi_utilities-0.2.1/qi_utilities/utility_functions/__init__.py +0 -0
- qi_utilities-0.2.1/qi_utilities/utility_functions/api_legacy_functions.py +187 -0
- qi_utilities-0.2.1/qi_utilities/utility_functions/circuit_modifiers.py +139 -0
- qi_utilities-0.2.1/qi_utilities/utility_functions/data_handling.py +464 -0
- qi_utilities-0.2.1/qi_utilities/utility_functions/quantum_info.py +31 -0
- qi_utilities-0.2.1/qi_utilities/utility_functions/raw_data_processing.py +183 -0
- qi_utilities-0.2.1/qi_utilities/utility_functions/readout_correction.py +232 -0
- qi_utilities-0.2.1/qi_utilities.egg-info/PKG-INFO +86 -0
- qi_utilities-0.2.1/qi_utilities.egg-info/SOURCES.txt +23 -0
- qi_utilities-0.2.1/qi_utilities.egg-info/dependency_links.txt +1 -0
- qi_utilities-0.2.1/qi_utilities.egg-info/requires.txt +6 -0
- qi_utilities-0.2.1/qi_utilities.egg-info/top_level.txt +1 -0
- qi_utilities-0.2.1/setup.cfg +4 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023 DiCarlo Lab
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: qi-utilities
|
|
3
|
+
Version: 0.2.1
|
|
4
|
+
Summary: Package library with utility functions and demonstration notebooks especially suited for the superconducting hardware backends of the cloud quantum computing platform Quantum Inspire.
|
|
5
|
+
Author-email: DiCarlo Lab at QuTech <secr-qutech@tudelft.nl>
|
|
6
|
+
Maintainer-email: Marios Samiotis <m.samiotis@tudelft.nl>
|
|
7
|
+
License-Expression: MIT
|
|
8
|
+
Project-URL: Homepage, https://github.com/DiCarloLab-Delft/QuantumInspireUtilities
|
|
9
|
+
Keywords: quantuminspire,qiskit,quantum computing,superconducting
|
|
10
|
+
Classifier: Development Status :: 3 - Alpha
|
|
11
|
+
Classifier: Intended Audience :: Science/Research
|
|
12
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
17
|
+
Classifier: Topic :: Scientific/Engineering
|
|
18
|
+
Requires-Python: >=3.9
|
|
19
|
+
Description-Content-Type: text/markdown
|
|
20
|
+
License-File: LICENSE
|
|
21
|
+
Requires-Dist: qiskit-quantuminspire
|
|
22
|
+
Requires-Dist: matplotlib
|
|
23
|
+
Requires-Dist: pandas
|
|
24
|
+
Requires-Dist: pylatexenc
|
|
25
|
+
Requires-Dist: qiskit-qasm3-import
|
|
26
|
+
Requires-Dist: h5py
|
|
27
|
+
Dynamic: license-file
|
|
28
|
+
|
|
29
|
+
# QuantumInspireUtilities
|
|
30
|
+
This repository contains utility functions and demonstration notebooks that supplement the [Quantum Inspire 2.0](https://www.quantum-inspire.com/) Python SDK, tailored for the superconducting backends of the platform, hosted in the [DiCarlo lab](https://qutech.nl/lab/dicarlo-lab-welcome/) in QuTech.
|
|
31
|
+
|
|
32
|
+
It is primarily intended for researchers, students, and developers who use Quantum Inspire’s superconducting backends and want reusable utilities and worked examples beyond the core SDK.
|
|
33
|
+
|
|
34
|
+
Useful links relating to our superconducting backends:
|
|
35
|
+
1. [Tuna Backends Operational Specifics](https://www.quantum-inspire.com/kbase/tuna-operational-specifics/)
|
|
36
|
+
2. [Backend Performance Dashboards](https://monitoring.qutech.support/public-dashboards/c494a21fb6b7405f850ab8f340f798ef?orgId=1&refresh=10s) [live updates]
|
|
37
|
+
3. [Join our Slack community!](https://join.slack.com/t/qisuperconducting/shared_invite/zt-35o7zitdh-_9QPmB53hhLy12Eat5gwWA)
|
|
38
|
+
|
|
39
|
+
## 1. Installation instructions
|
|
40
|
+
|
|
41
|
+
### 1.1. Beginner-friendly installation
|
|
42
|
+
Note: this installation method is typically not recommended, but is nevertheless suggested due to its relative simplicity. In principle it avoids installing and using pipx, which some users have experienced difficulties in doing so.
|
|
43
|
+
|
|
44
|
+
1. [Install Anaconda](https://www.anaconda.com/) or Miniconda (lightweight version of Anaconda) in your computer
|
|
45
|
+
2. Open Anaconda Prompt (or Terminal in UNIX)
|
|
46
|
+
3. Run the following commands
|
|
47
|
+
- conda create -n quantuminspire python=3.12 (creates a new conda environment)
|
|
48
|
+
- conda activate quantuminspire (activates the environment)
|
|
49
|
+
- pip install quantuminspire
|
|
50
|
+
- pip install qi-utilities (installs this repository)
|
|
51
|
+
- pip install jupyterlab
|
|
52
|
+
- pip install notebook
|
|
53
|
+
|
|
54
|
+
Installing quantuminspire within the conda environment restricts the command 'qi login' to be recognized and used only within the created environment.
|
|
55
|
+
|
|
56
|
+
### 1.2. Advanced installation (recommended)
|
|
57
|
+
|
|
58
|
+
1. [Install pipx](https://pipx.pypa.io/stable/installation/) (used when installing quantuminspire package)
|
|
59
|
+
2. [Install quantuminspire repository](https://github.com/QuTech-Delft/quantuminspire?tab=readme-ov-file) (used for login)
|
|
60
|
+
3. [Install Anaconda](https://www.anaconda.com/) or Miniconda (lightweight version of Anaconda) in your computer
|
|
61
|
+
4. Open Anaconda Prompt (or Terminal in UNIX)
|
|
62
|
+
5. Run the following commands
|
|
63
|
+
- conda create -n quantuminspire python=3.12 (creates a new conda environment)
|
|
64
|
+
- conda activate quantuminspire (activates the environment)
|
|
65
|
+
- pip install qi-utilities (installs this repository)
|
|
66
|
+
- pip install jupyterlab
|
|
67
|
+
- pip install notebook
|
|
68
|
+
|
|
69
|
+
Note: in order to run the method backend.coupling_map.draw(), you will need to [install Graphviz](https://graphviz.org/download/#executable-packages) in your computer. Make sure during installation to add Graphviz to the system PATH, so that your Python environment can recognize it.
|
|
70
|
+
|
|
71
|
+
## 2. Cloning and installing from source
|
|
72
|
+
In order to install this repository from source, you will need a GitHub account to be able to pull the project.
|
|
73
|
+
For new users, we recommend downloading [GitHub Desktop](https://desktop.github.com/download/), and then cloning the repository by using the link https://github.com/DiCarloLab-Delft/QuantumInspireUtilities.git.
|
|
74
|
+
|
|
75
|
+
After creating a working Python environment (see instructions above), open Anaconda Prompt to activate the environment, navigate to the repository directory, and use the following pip command to [install](https://docs.python.org/3/installing/index.html),
|
|
76
|
+
|
|
77
|
+
python -m pip install -e .
|
|
78
|
+
|
|
79
|
+
The '-e' flag makes the package configurable.
|
|
80
|
+
|
|
81
|
+
In order to create your first quantum circuit using the Quantum Inspire SDK, visit https://qutech-delft.github.io/qiskit-quantuminspire/getting_started/submitting.html.
|
|
82
|
+
|
|
83
|
+
## 3. TODOs
|
|
84
|
+
[2026-01-20] Current list of targeted upcoming new features:
|
|
85
|
+
|
|
86
|
+
* Create utility functions and a demonstration notebook guide on variational quantum algorithms.
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
# QuantumInspireUtilities
|
|
2
|
+
This repository contains utility functions and demonstration notebooks that supplement the [Quantum Inspire 2.0](https://www.quantum-inspire.com/) Python SDK, tailored for the superconducting backends of the platform, hosted in the [DiCarlo lab](https://qutech.nl/lab/dicarlo-lab-welcome/) in QuTech.
|
|
3
|
+
|
|
4
|
+
It is primarily intended for researchers, students, and developers who use Quantum Inspire’s superconducting backends and want reusable utilities and worked examples beyond the core SDK.
|
|
5
|
+
|
|
6
|
+
Useful links relating to our superconducting backends:
|
|
7
|
+
1. [Tuna Backends Operational Specifics](https://www.quantum-inspire.com/kbase/tuna-operational-specifics/)
|
|
8
|
+
2. [Backend Performance Dashboards](https://monitoring.qutech.support/public-dashboards/c494a21fb6b7405f850ab8f340f798ef?orgId=1&refresh=10s) [live updates]
|
|
9
|
+
3. [Join our Slack community!](https://join.slack.com/t/qisuperconducting/shared_invite/zt-35o7zitdh-_9QPmB53hhLy12Eat5gwWA)
|
|
10
|
+
|
|
11
|
+
## 1. Installation instructions
|
|
12
|
+
|
|
13
|
+
### 1.1. Beginner-friendly installation
|
|
14
|
+
Note: this installation method is typically not recommended, but is nevertheless suggested due to its relative simplicity. In principle it avoids installing and using pipx, which some users have experienced difficulties in doing so.
|
|
15
|
+
|
|
16
|
+
1. [Install Anaconda](https://www.anaconda.com/) or Miniconda (lightweight version of Anaconda) in your computer
|
|
17
|
+
2. Open Anaconda Prompt (or Terminal in UNIX)
|
|
18
|
+
3. Run the following commands
|
|
19
|
+
- conda create -n quantuminspire python=3.12 (creates a new conda environment)
|
|
20
|
+
- conda activate quantuminspire (activates the environment)
|
|
21
|
+
- pip install quantuminspire
|
|
22
|
+
- pip install qi-utilities (installs this repository)
|
|
23
|
+
- pip install jupyterlab
|
|
24
|
+
- pip install notebook
|
|
25
|
+
|
|
26
|
+
Installing quantuminspire within the conda environment restricts the command 'qi login' to be recognized and used only within the created environment.
|
|
27
|
+
|
|
28
|
+
### 1.2. Advanced installation (recommended)
|
|
29
|
+
|
|
30
|
+
1. [Install pipx](https://pipx.pypa.io/stable/installation/) (used when installing quantuminspire package)
|
|
31
|
+
2. [Install quantuminspire repository](https://github.com/QuTech-Delft/quantuminspire?tab=readme-ov-file) (used for login)
|
|
32
|
+
3. [Install Anaconda](https://www.anaconda.com/) or Miniconda (lightweight version of Anaconda) in your computer
|
|
33
|
+
4. Open Anaconda Prompt (or Terminal in UNIX)
|
|
34
|
+
5. Run the following commands
|
|
35
|
+
- conda create -n quantuminspire python=3.12 (creates a new conda environment)
|
|
36
|
+
- conda activate quantuminspire (activates the environment)
|
|
37
|
+
- pip install qi-utilities (installs this repository)
|
|
38
|
+
- pip install jupyterlab
|
|
39
|
+
- pip install notebook
|
|
40
|
+
|
|
41
|
+
Note: in order to run the method backend.coupling_map.draw(), you will need to [install Graphviz](https://graphviz.org/download/#executable-packages) in your computer. Make sure during installation to add Graphviz to the system PATH, so that your Python environment can recognize it.
|
|
42
|
+
|
|
43
|
+
## 2. Cloning and installing from source
|
|
44
|
+
In order to install this repository from source, you will need a GitHub account to be able to pull the project.
|
|
45
|
+
For new users, we recommend downloading [GitHub Desktop](https://desktop.github.com/download/), and then cloning the repository by using the link https://github.com/DiCarloLab-Delft/QuantumInspireUtilities.git.
|
|
46
|
+
|
|
47
|
+
After creating a working Python environment (see instructions above), open Anaconda Prompt to activate the environment, navigate to the repository directory, and use the following pip command to [install](https://docs.python.org/3/installing/index.html),
|
|
48
|
+
|
|
49
|
+
python -m pip install -e .
|
|
50
|
+
|
|
51
|
+
The '-e' flag makes the package configurable.
|
|
52
|
+
|
|
53
|
+
In order to create your first quantum circuit using the Quantum Inspire SDK, visit https://qutech-delft.github.io/qiskit-quantuminspire/getting_started/submitting.html.
|
|
54
|
+
|
|
55
|
+
## 3. TODOs
|
|
56
|
+
[2026-01-20] Current list of targeted upcoming new features:
|
|
57
|
+
|
|
58
|
+
* Create utility functions and a demonstration notebook guide on variational quantum algorithms.
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=61.0"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "qi-utilities"
|
|
7
|
+
version = "0.2.1"
|
|
8
|
+
description = "Package library with utility functions and demonstration notebooks especially suited for the superconducting hardware backends of the cloud quantum computing platform Quantum Inspire."
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.9"
|
|
11
|
+
license = "MIT"
|
|
12
|
+
|
|
13
|
+
authors = [
|
|
14
|
+
{ name = "DiCarlo Lab at QuTech", email = "secr-qutech@tudelft.nl" }
|
|
15
|
+
]
|
|
16
|
+
|
|
17
|
+
maintainers = [
|
|
18
|
+
{ name = "Marios Samiotis", email = "m.samiotis@tudelft.nl" }
|
|
19
|
+
]
|
|
20
|
+
|
|
21
|
+
keywords = [
|
|
22
|
+
"quantuminspire",
|
|
23
|
+
"qiskit",
|
|
24
|
+
"quantum computing",
|
|
25
|
+
"superconducting"
|
|
26
|
+
]
|
|
27
|
+
|
|
28
|
+
classifiers = [
|
|
29
|
+
"Development Status :: 3 - Alpha",
|
|
30
|
+
"Intended Audience :: Science/Research",
|
|
31
|
+
"Programming Language :: Python :: 3 :: Only",
|
|
32
|
+
"Programming Language :: Python :: 3.9",
|
|
33
|
+
"Programming Language :: Python :: 3.10",
|
|
34
|
+
"Programming Language :: Python :: 3.11",
|
|
35
|
+
"Programming Language :: Python :: 3.12",
|
|
36
|
+
"Topic :: Scientific/Engineering",
|
|
37
|
+
]
|
|
38
|
+
|
|
39
|
+
dependencies = [
|
|
40
|
+
"qiskit-quantuminspire",
|
|
41
|
+
"matplotlib",
|
|
42
|
+
"pandas",
|
|
43
|
+
"pylatexenc",
|
|
44
|
+
"qiskit-qasm3-import",
|
|
45
|
+
"h5py",
|
|
46
|
+
]
|
|
47
|
+
|
|
48
|
+
[project.urls]
|
|
49
|
+
Homepage = "https://github.com/DiCarloLab-Delft/QuantumInspireUtilities"
|
|
50
|
+
|
|
51
|
+
[tool.setuptools.packages.find]
|
|
52
|
+
where = ["."]
|
|
53
|
+
include = ["qi_utilities*"]
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Utility functions for synthesizing a Trotterization quantum circuit.
|
|
3
|
+
|
|
4
|
+
Authors: Marios Samiotis
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
import numpy as np
|
|
8
|
+
from qiskit import QuantumCircuit
|
|
9
|
+
from qiskit.circuit.library import PauliEvolutionGate
|
|
10
|
+
from qiskit.quantum_info import SparsePauliOp
|
|
11
|
+
from qi_utilities.utility_functions.circuit_modifiers import apply_pre_measurement_rotations
|
|
12
|
+
|
|
13
|
+
def apply_trotter_block(qc: QuantumCircuit,
|
|
14
|
+
hamiltonian: SparsePauliOp,
|
|
15
|
+
trotter_order: int,
|
|
16
|
+
time_step: float):
|
|
17
|
+
"""
|
|
18
|
+
This function applies a Trotter block on a given quantum circuit
|
|
19
|
+
'qc'.
|
|
20
|
+
We follow the common convention hbar=1.
|
|
21
|
+
|
|
22
|
+
Args:
|
|
23
|
+
qc (QuantumCircuit):
|
|
24
|
+
The quantum circuit object.
|
|
25
|
+
|
|
26
|
+
hamiltonian (SparsePauliOp):
|
|
27
|
+
The Hamiltonian operator describing the dynamics of a given
|
|
28
|
+
quantum system, written in the Pauli basis.
|
|
29
|
+
It should be given in units of [Hz].
|
|
30
|
+
|
|
31
|
+
In general, a Hamiltonian operator is written as
|
|
32
|
+
H = sum_{j} a_j * P_j, where a_j are complex coefficients in units of [Hz],
|
|
33
|
+
and P_j are n-qubit Pauli operators (else referred to as 'Pauli strings').
|
|
34
|
+
|
|
35
|
+
For an n-qubit Pauli operator P in the Hamiltonian, with Pauli Pi acting
|
|
36
|
+
on qubit qi, the ordering of the string is 'Pn-1,Pn-2,...,P2,P1,P0'.
|
|
37
|
+
e.g. for the two-qubit Pauli string 'YX', operator X corresponds
|
|
38
|
+
to qubit q0, while operator Y corresponds to qubit q1.
|
|
39
|
+
|
|
40
|
+
trotter_order (int):
|
|
41
|
+
The trotterization order. For more info, visit
|
|
42
|
+
https://en.wikipedia.org/wiki/Hamiltonian_simulation#Product_formulas
|
|
43
|
+
|
|
44
|
+
time_step (float):
|
|
45
|
+
The time step in which we evolve dynamically forward in time
|
|
46
|
+
the quantum state encoded in the quantum circuit 'qc'.
|
|
47
|
+
"""
|
|
48
|
+
hamiltonian = hamiltonian[::-1]
|
|
49
|
+
for entry in range(len(hamiltonian)):
|
|
50
|
+
pauli_string = hamiltonian[entry].paulis.to_labels()[0]
|
|
51
|
+
|
|
52
|
+
string_to_list = list(pauli_string)
|
|
53
|
+
target_qubits = []
|
|
54
|
+
qubit_counter = 0
|
|
55
|
+
for index in reversed(range(len(string_to_list))):
|
|
56
|
+
if string_to_list[index] == 'I':
|
|
57
|
+
pass
|
|
58
|
+
else:
|
|
59
|
+
target_qubits.append(qubit_counter)
|
|
60
|
+
qubit_counter += 1
|
|
61
|
+
|
|
62
|
+
unitary_label = 'Trotter block,' + f' Pauli: {pauli_string}' + \
|
|
63
|
+
f'\nn = {trotter_order},' + f' Time = {time_step*1e9:.2f} ns'
|
|
64
|
+
unitary_gate = PauliEvolutionGate(operator = hamiltonian[entry],
|
|
65
|
+
time = time_step / trotter_order,
|
|
66
|
+
label = unitary_label)
|
|
67
|
+
qc.append(unitary_gate, target_qubits)
|
|
68
|
+
|
|
69
|
+
def construct_trotterization_circuit(initial_state: str,
|
|
70
|
+
measured_observable: str,
|
|
71
|
+
hamiltonian: SparsePauliOp,
|
|
72
|
+
trotter_order: int,
|
|
73
|
+
evolution_times: np.ndarray,
|
|
74
|
+
time_step: float,
|
|
75
|
+
midcircuit_measurement: bool = False):
|
|
76
|
+
"""
|
|
77
|
+
This function uses the 'trotter_block' function contained in this module
|
|
78
|
+
to create the Trotterization quantum circuit from an initial state.
|
|
79
|
+
We follow the common convention hbar=1.
|
|
80
|
+
|
|
81
|
+
Args:
|
|
82
|
+
initial_state (str):
|
|
83
|
+
A bitstring specifying the initial state. The order in the bitstring
|
|
84
|
+
is 'qn-1,qn-2,...,q2,q1,q0'. The string can only contain '0' or '1'.
|
|
85
|
+
e.g. for a quantum circuit with 3 qubits, initial_state = '100' will
|
|
86
|
+
initialize qubits q0 and q1 in the state |0>, and qubit q2 in the state
|
|
87
|
+
|1>.
|
|
88
|
+
|
|
89
|
+
measured_observable (str):
|
|
90
|
+
The observable whose expectation value we estimate at the end of
|
|
91
|
+
the Trotterization algorithm.
|
|
92
|
+
|
|
93
|
+
For an n-qubit Pauli string P, where Pauli Pi acts on qubit qi, the order
|
|
94
|
+
in the string is 'Pn-1,Pn-2,...,P2,P1,P0'.
|
|
95
|
+
e.g. for the two-qubit observable string 'YX', qubit q0 is measured
|
|
96
|
+
in the X basis, while qubit q1 is measured in the Y basis.
|
|
97
|
+
|
|
98
|
+
hamiltonian (SparsePauliOp):
|
|
99
|
+
The Hamiltonian operator describing the dynamics of a given
|
|
100
|
+
quantum system, written in the Pauli basis.
|
|
101
|
+
It should be given in units of [Hz].
|
|
102
|
+
|
|
103
|
+
In general, a Hamiltonian operator is written as
|
|
104
|
+
H = sum_{j} a_j * P_j, where a_j are complex coefficients in units of [Hz],
|
|
105
|
+
and P_j are n-qubit Pauli operators (else referred to as 'Pauli strings').
|
|
106
|
+
|
|
107
|
+
For an n-qubit Pauli operator P in the Hamiltonian, with Pauli Pi acting
|
|
108
|
+
on qubit qi, the ordering of the string is 'Pn-1,Pn-2,...,P2,P1,P0'.
|
|
109
|
+
e.g. for the two-qubit Pauli string 'YX', operator X corresponds
|
|
110
|
+
to qubit q0, while operator Y corresponds to qubit q1.
|
|
111
|
+
|
|
112
|
+
trotter_order (int):
|
|
113
|
+
The trotterization order. For more info, visit
|
|
114
|
+
https://en.wikipedia.org/wiki/Hamiltonian_simulation#Product_formulas
|
|
115
|
+
|
|
116
|
+
evolution_times (np.ndarray):
|
|
117
|
+
A numpy array containing the discrete time steps for which the simulation
|
|
118
|
+
solves the time-dependent Schrödinger equation.
|
|
119
|
+
|
|
120
|
+
time_step (float):
|
|
121
|
+
The time step in which we evolve dynamically forward in time
|
|
122
|
+
the quantum state encoded in the quantum circuit 'qc'.
|
|
123
|
+
|
|
124
|
+
midcircuit_measurement (bool):
|
|
125
|
+
A flag which should be set to 'True' if we are utilizing the mid-circuit
|
|
126
|
+
functionality when constructing the Trotterization algorithm.
|
|
127
|
+
"""
|
|
128
|
+
|
|
129
|
+
nr_qubits = len(initial_state)
|
|
130
|
+
if midcircuit_measurement == True:
|
|
131
|
+
qc = QuantumCircuit(nr_qubits, nr_qubits*len(evolution_times))
|
|
132
|
+
else:
|
|
133
|
+
qc = QuantumCircuit(nr_qubits, nr_qubits)
|
|
134
|
+
for idx in range(nr_qubits):
|
|
135
|
+
qc.reset(idx)
|
|
136
|
+
qc.barrier()
|
|
137
|
+
|
|
138
|
+
for idx in range(len(initial_state)):
|
|
139
|
+
if initial_state[idx] == '1':
|
|
140
|
+
qc.x((nr_qubits-1) - idx)
|
|
141
|
+
qc.barrier()
|
|
142
|
+
|
|
143
|
+
for repetition in range(1, trotter_order+1):
|
|
144
|
+
apply_trotter_block(qc, hamiltonian, trotter_order, evolution_times[time_step])
|
|
145
|
+
qc.barrier()
|
|
146
|
+
|
|
147
|
+
if midcircuit_measurement == True:
|
|
148
|
+
apply_pre_measurement_rotations(qc, measured_observable, [nr_qubits*time_step, nr_qubits*time_step + 1])
|
|
149
|
+
else:
|
|
150
|
+
apply_pre_measurement_rotations(qc, measured_observable)
|
|
151
|
+
qc.barrier()
|
|
152
|
+
|
|
153
|
+
return qc
|
|
File without changes
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Utility functions for solving classically the time-dependent
|
|
3
|
+
Schrödinger equation, given an initial quantum state and a system
|
|
4
|
+
Hamiltonian.
|
|
5
|
+
|
|
6
|
+
Authors: Marios Samiotis
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
import numpy as np
|
|
10
|
+
from qiskit import QuantumCircuit
|
|
11
|
+
from qiskit.circuit.library import PauliEvolutionGate
|
|
12
|
+
from qiskit.quantum_info import SparsePauliOp, DensityMatrix, Operator
|
|
13
|
+
from qi_utilities.utility_functions.quantum_info import calculate_observable_value
|
|
14
|
+
|
|
15
|
+
def evolve_quantum_state(quantum_state: QuantumCircuit,
|
|
16
|
+
hamiltonian: SparsePauliOp,
|
|
17
|
+
time_step: float):
|
|
18
|
+
"""
|
|
19
|
+
This function evolves a (initial) quantum state by applying
|
|
20
|
+
the time evolution unitary operator U(t) = exp(-iHt) on the
|
|
21
|
+
state, for a time_step 't' and a Hamiltonian operator 'H'.
|
|
22
|
+
|
|
23
|
+
The initial state 'quantum_state' must be a quantum circuit.
|
|
24
|
+
We follow the common convention hbar=1.
|
|
25
|
+
|
|
26
|
+
Args:
|
|
27
|
+
quantum_state (QuantumCircuit):
|
|
28
|
+
The quantum state to be evolved, given as a QuantumCircuit object.
|
|
29
|
+
The user is required to create such a circuit outside of this function.
|
|
30
|
+
|
|
31
|
+
hamiltonian (SparsePauliOp):
|
|
32
|
+
The Hamiltonian operator describing the dynamics of a given
|
|
33
|
+
quantum system, written in the Pauli basis.
|
|
34
|
+
It should be given in units of [Hz].
|
|
35
|
+
|
|
36
|
+
In general, a Hamiltonian operator is written as
|
|
37
|
+
H = sum_{j} a_j * P_j, where a_j are complex coefficients in units of [Hz],
|
|
38
|
+
and P_j are n-qubit Pauli operators (else referred to as 'Pauli strings').
|
|
39
|
+
|
|
40
|
+
For an n-qubit Pauli operator P in the Hamiltonian, with Pauli Pi acting
|
|
41
|
+
on qubit qi, the ordering of the string is 'Pn-1,Pn-2,...,P2,P1,P0'.
|
|
42
|
+
e.g. for the two-qubit Pauli string 'YX', operator X corresponds
|
|
43
|
+
to qubit q0, while operator Y corresponds to qubit q1.
|
|
44
|
+
|
|
45
|
+
time_step (float):
|
|
46
|
+
The time step in which we evolve dynamically forward in time
|
|
47
|
+
the quantum_state.
|
|
48
|
+
"""
|
|
49
|
+
|
|
50
|
+
if type(quantum_state) is not QuantumCircuit:
|
|
51
|
+
raise TypeError(f"Object {quantum_state} must be a QuantumCircuit.")
|
|
52
|
+
|
|
53
|
+
density_state = DensityMatrix(quantum_state)
|
|
54
|
+
evolution_matrix = PauliEvolutionGate(operator = hamiltonian,
|
|
55
|
+
time = time_step)
|
|
56
|
+
evolution_operator = Operator(evolution_matrix)
|
|
57
|
+
evolved_state = density_state.evolve(evolution_operator)
|
|
58
|
+
|
|
59
|
+
return evolved_state
|
|
60
|
+
|
|
61
|
+
def simulate_time_evolution(initial_state: QuantumCircuit,
|
|
62
|
+
hamiltonian: SparsePauliOp,
|
|
63
|
+
evolution_times: np.ndarray,
|
|
64
|
+
observables: list):
|
|
65
|
+
"""
|
|
66
|
+
This function takes as inputs an initial quantum state, the system Hamiltonian,
|
|
67
|
+
the evolution times and the list of observables to be extracted, and solves
|
|
68
|
+
the time-dependent Schrödinger equation.
|
|
69
|
+
It returns a dictionary containing the values of each observable in the
|
|
70
|
+
'observables' list, for all time steps in 'evolution_times'.
|
|
71
|
+
|
|
72
|
+
The initial state 'initial_state' must be a quantum circuit.
|
|
73
|
+
We follow the common convention hbar=1.
|
|
74
|
+
|
|
75
|
+
Args:
|
|
76
|
+
initial_state (QuantumCircuit):
|
|
77
|
+
The quantum state to be evolved, given as a QuantumCircuit object.
|
|
78
|
+
The user is required to create such a circuit outside of this function.
|
|
79
|
+
|
|
80
|
+
hamiltonian (SparsePauliOp):
|
|
81
|
+
The Hamiltonian operator describing the dynamics of a given
|
|
82
|
+
quantum system, written in the Pauli basis.
|
|
83
|
+
It should be given in units of [Hz].
|
|
84
|
+
|
|
85
|
+
In general, a Hamiltonian operator is written as
|
|
86
|
+
H = sum_{j} a_j * P_j, where a_j are complex coefficients in units of [Hz],
|
|
87
|
+
and P_j are n-qubit Pauli operators (else referred to as 'Pauli strings').
|
|
88
|
+
|
|
89
|
+
For an n-qubit Pauli operator P in the Hamiltonian, with Pauli Pi acting
|
|
90
|
+
on qubit qi, the ordering of the string is 'Pn-1,Pn-2,...,P2,P1,P0'.
|
|
91
|
+
e.g. for the two-qubit Pauli string 'YX', operator X corresponds
|
|
92
|
+
to qubit q0, while operator Y corresponds to qubit q1.
|
|
93
|
+
|
|
94
|
+
evolution_times (np.ndarray):
|
|
95
|
+
A numpy array containing the discrete time steps for which the simulation
|
|
96
|
+
solves the time-dependent Schrödinger equation.
|
|
97
|
+
|
|
98
|
+
observables (list):
|
|
99
|
+
A list containing the observables for which the simulation calculates
|
|
100
|
+
the expectation values of, for each time step within the 'evolution_times'.
|
|
101
|
+
|
|
102
|
+
For an n-qubit Pauli string P, where Pauli Pi acts on qubit qi, the order
|
|
103
|
+
in the string is 'Pn-1,Pn-2,...,P2,P1,P0'.
|
|
104
|
+
e.g. for the two-qubit observable string 'IZ', operator Z corresponds to
|
|
105
|
+
qubit q0 while operator I corresponds to qubit q1.
|
|
106
|
+
"""
|
|
107
|
+
|
|
108
|
+
if type(initial_state) is not QuantumCircuit:
|
|
109
|
+
raise TypeError(f"Object {initial_state} must be a QuantumCircuit.")
|
|
110
|
+
|
|
111
|
+
dt = evolution_times[1] - evolution_times[0] #use this for the time_interval in noisy evolution
|
|
112
|
+
observables_dict = {}
|
|
113
|
+
for observable in observables:
|
|
114
|
+
observables_dict[observable] = {}
|
|
115
|
+
observables_dict[observable]['list'] = list(observable)
|
|
116
|
+
observables_dict[observable]['values'] = []
|
|
117
|
+
for time_step in evolution_times:
|
|
118
|
+
evolved_state = evolve_quantum_state(initial_state, hamiltonian, time_step)
|
|
119
|
+
# put here the evolution due to a noise channel
|
|
120
|
+
for observable in observables:
|
|
121
|
+
observable_value = calculate_observable_value(evolved_state, observable)
|
|
122
|
+
observables_dict[observable]['values'].append(observable_value)
|
|
123
|
+
|
|
124
|
+
return observables_dict
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|