Skip to content
This repository was archived by the owner on Oct 31, 2025. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
6b1afb0
starting point - bringing parser files over from Aer
DanPuzzuoli Nov 11, 2021
3689090
adding hamiltonian_model as well as it does some of the parsing
DanPuzzuoli Nov 11, 2021
58679be
added file and sketched signature for desired function
DanPuzzuoli Nov 11, 2021
8ffc260
trying things out - initial success with multiplying string coefficie…
DanPuzzuoli Nov 15, 2021
16a7419
added error raising if more than one channel is specified, or if chan…
DanPuzzuoli Nov 15, 2021
10e7cf6
added operator merging and channel sorting step, and added tests for …
DanPuzzuoli Nov 16, 2021
396b60a
adding some documentation and removing the old hamiltonian_model file…
DanPuzzuoli Nov 16, 2021
dca82ae
saving
DanPuzzuoli Nov 17, 2021
65cd233
initial tests passing with stripped down version of individual string…
DanPuzzuoli Nov 17, 2021
3c1f830
added doc string from operator_from_string giving explicit descriptio…
DanPuzzuoli Nov 17, 2021
0f9a4c5
saving
DanPuzzuoli Nov 19, 2021
dc328cf
Merge branch 'main' into pulse_string_parser
DanPuzzuoli Dec 10, 2021
fd4a577
converting output aggregated channel list to lower case
DanPuzzuoli Dec 10, 2021
a2f4eca
expanded valid channel characters and added test cases
DanPuzzuoli Dec 10, 2021
7182fd3
added more complicated test case and discovered issue with logic for …
DanPuzzuoli Dec 11, 2021
b960d16
restructured validation checks to allow _SUM strings
DanPuzzuoli Dec 13, 2021
c1f31d6
deleting unused old files
DanPuzzuoli Dec 13, 2021
a59be2f
fully deleting all old files
DanPuzzuoli Dec 13, 2021
c934da4
intermediate linting
DanPuzzuoli Dec 13, 2021
9da584b
further updating validation, and adding documentation note for _SUM[x…
DanPuzzuoli Dec 14, 2021
7e5ed5d
about to try noise parsing
DanPuzzuoli Dec 14, 2021
d17f77b
adding noise parsing function and deleting old noise parser object
DanPuzzuoli Dec 14, 2021
d61e507
small changes
DanPuzzuoli Dec 14, 2021
3394501
moving files around
DanPuzzuoli Jan 4, 2022
6d5cdc7
attempting to simplify and linting
DanPuzzuoli Jan 4, 2022
1291532
adding examples to documentation
DanPuzzuoli Jan 4, 2022
7ff2d17
adding parse_hamiltonian_dict to pulse module documentation
DanPuzzuoli Jan 4, 2022
89ed4db
Merge branch 'main' into pulse_string_parser
DanPuzzuoli Jan 5, 2022
4e30d01
updating parse_hamiltonian_dict to also output subsystem labels/dimen…
DanPuzzuoli Jan 14, 2022
32bb596
Merge branch 'main' into pulse_string_parser
DanPuzzuoli Jan 19, 2022
dc8ea0f
Merge branch 'main' into pulse_string_parser
DanPuzzuoli Feb 8, 2022
327d05d
Adding acquire channels to string parser
DanPuzzuoli Feb 8, 2022
eb6d23f
fixing typos and adding tests addressing PR comments
DanPuzzuoli Feb 8, 2022
cee451a
formatting
DanPuzzuoli Feb 8, 2022
c26ffcf
correcting test comment
DanPuzzuoli Feb 8, 2022
6b647b2
Merge branch 'main' into pulse_string_parser
DanPuzzuoli Feb 11, 2022
ad74ed2
updating formatting after merging main
DanPuzzuoli Feb 11, 2022
7e1dea3
addressing most review comments
DanPuzzuoli Feb 11, 2022
524c7ce
Merge branch 'main' into pulse_string_parser
DanPuzzuoli Feb 11, 2022
679ba7e
updating operator_from_String to utilize quantum_info
DanPuzzuoli Feb 16, 2022
ba4a35b
Merge branch 'pulse_string_parser' of github.com:DanPuzzuoli/qiskit-d…
DanPuzzuoli Feb 16, 2022
8ce25bd
renaming various folders, files, and functions
DanPuzzuoli Feb 16, 2022
9591fd9
Merge branch 'main' into pulse_string_parser
DanPuzzuoli Feb 16, 2022
9fb2c31
Merge branch 'main' into pulse_string_parser
DanPuzzuoli Aug 10, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions qiskit_dynamics/pulse/backend_parser/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# -*- coding: utf-8 -*-

# This code is part of Qiskit.
#
# (C) Copyright IBM 2022.
#
# This code is licensed under the Apache License, Version 2.0. You may
# obtain a copy of this license in the LICENSE.txt file in the root directory
# of this source tree or at http://www.apache.org/licenses/LICENSE-2.0.
#
# Any modifications or derivative works of this code must retain this
# copyright notice, and modified files need to carry a notice indicating
# that they have been altered from the originals.

"""
String model parser functionality.

This module is meant for internal use and may be changed at any point.
"""
142 changes: 142 additions & 0 deletions qiskit_dynamics/pulse/backend_parser/operator_from_string.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
# -*- coding: utf-8 -*-

# This code is part of Qiskit.
#
# (C) Copyright IBM 2022.
#
# This code is licensed under the Apache License, Version 2.0. You may
# obtain a copy of this license in the LICENSE.txt file in the root directory
# of this source tree or at http://www.apache.org/licenses/LICENSE-2.0.
#
# Any modifications or derivative works of this code must retain this
# copyright notice, and modified files need to carry a notice indicating
# that they have been altered from the originals.
# pylint: disable=invalid-name

"""Generate operators from string.

This file is meant for internal use and may be changed at any point.
"""

from typing import Dict
import numpy as np

from qiskit import QiskitError
import qiskit.quantum_info as qi


def operator_from_string(
op_label: str, subsystem_label: int, subsystem_dims: Dict[int, int]
) -> np.ndarray:
r"""Generates a dense operator acting on a single subsystem, tensoring
identities for remaining subsystems.

The single system operator is specified via a string in ``op_label``,
the list of subsystems and their corresponding dimensions are specified in the
dictionary ``subsystem_dims``, with system label being the keys specified as ``int``s,
and system dimensions the values also specified as ``int``s, and ``subsystem_label``
indicates which subsystem the operator specified by ``op_label`` acts on.

Accepted ``op_labels`` are:
- `'X'`: If the target subsystem is two dimensional, the
Pauli :math:`X` operator, and if greater than two dimensional, returns
:math:`a + a^\dagger`, where :math:`a` and :math:`a^\dagger` are the
annihiliation and creation operators, respectively.
- `'Y'`: If the target subsystem is two dimensional, the
Pauli :math:`Y` operator, and if greater than two dimensional, returns
:math:`-i(a - a^\dagger)`, where :math:`a` and :math:`a^\dagger` are the
annihiliation and creation operators, respectively.
- `'Z'`: If the target subsystem is two dimensional, the
Pauli :math:`Z` operator, and if greater than two dimensional, returns
:math:`I - 2 * N`, where :math:`N` is the number operator.
- `'a'`, `'A'`, or `'Sm'`: If two dimensional, the sigma minus operator, and if greater,
generalizes to the operator.
- `'C'`, or `'Sp'`: If two dimensional, sigma plus operator, and if greater,
generalizes to the creation operator.
- `'N'`, or `'O'`: The number operator.
- `'I'`: The identity operator.

Note that the ordering of tensor factors is reversed.

Args:
op_label: The string labelling the single system operator.
subsystem_label: Index of the subsystem to apply the operator.
subsystem_dims: Dictionary of subsystem labels and dimensions.

Returns:
np.ndarray corresponding to the specified operator.

Raises:
QiskitError: If op_label is invalid.
"""

# construct single system operator
op_func = __operdict.get(op_label, None)
if op_func is None:
raise QiskitError(f"String {op_label} does not correspond to a known operator.")

dim = subsystem_dims[subsystem_label]
out = qi.Operator(op_func(dim), input_dims=[dim], output_dims=[dim])

# sort subsystem labels and dimensions according to subsystem label
sorted_subsystem_keys, sorted_subsystem_dims = zip(
*sorted(zip(subsystem_dims.keys(), subsystem_dims.values()))
)

# get subsystem location in ordered list
subsystem_location = sorted_subsystem_keys.index(subsystem_label)

# construct full operator
return qi.ScalarOp(sorted_subsystem_dims).compose(out, [subsystem_location]).data


# functions for generating individual operators
def a(dim: int) -> np.ndarray:
"""Annihilation operator."""
return np.diag(np.sqrt(np.arange(1, dim, dtype=complex)), 1)


def adag(dim: int) -> np.ndarray:
"""Creation operator."""
return a(dim).conj().transpose()


def N(dim: int) -> np.ndarray:
"""Number operator."""
return np.diag(np.arange(dim, dtype=complex))


def X(dim: int) -> np.ndarray:
"""Generalized X operator, written in terms of raising and lowering operators."""
return a(dim) + adag(dim)


def Y(dim: int) -> np.ndarray:
"""Generalized Y operator, written in terms of raising and lowering operators."""
return -1j * (a(dim) - adag(dim))


def Z(dim: int) -> np.ndarray:
"""Generalized Z operator, written as id - 2 * N."""
return ident(dim) - 2 * N(dim)


def ident(dim: int) -> np.ndarray:
"""Identity operator."""
return np.eye(dim, dtype=complex)


# operator names
__operdict = {
"X": X,
"Y": Y,
"Z": Z,
"a": a,
"A": a,
"Sm": a,
"Sp": adag,
"C": adag,
"N": N,
"O": N,
"I": ident,
}
Loading