MQT Qudits - A Framework For Mixed-Dimensional Qudit Quantum ComputingΒΆ

MQT Qudits is an open-source C++17 and Python framework for mixed-dimensional qudit quantum computing developed as part of the Munich Quantum Toolkit (MQT) by the Chair for Design Automation at the Technical University of Munich.

Note

The tool is in an experimental stage, which is subject to frequent changes, and has limited documentation. We are working on improving that. In the meantime, users can explore how to use the framework via the Tutorial, showcasing its main functionality.

Furthermore, this video briefly illustrates some of the functionalities of MQT Qudits.

We appreciate any feedback and contributions to the project. If you have any questions, feel free to create a discussion or an issue on GitHub.

MQT Qudits Tutorial 🌌¢

Discover a New Dimension in Quantum Computing. Embark on a journey with MQT Qudits, a framework for Mixed-Dimensional Quantum Computing.

Delve into the realm of mixed-dimensional quantum computing with NeQSTβ€”a project funded by the European Union and developed developed as part of the Munich Quantum Toolkit (MQT) by the Chair for Design Automation at the Technical University of Munich. Our team is focused on creating design automation methods and software for quantum computing. The following tutorial will guide you through the initial tools and contributions we have made to advance Quantum Information Processing for Science and Technology.

Installation Steps:ΒΆ

(.venv) $ pip install mqt.qudits

For those seeking hands-on customization, simply clone the corresponding repository and perform a local installation.

$ git clone https://github.com/cda-tum/mqt-qudits.git
$ cd mqt-qudits
$ python3 -m venv .venv
$ source .venv/bin/activate
(.venv) $ pip install -ve .
+++

```{note}
This requires a C++17 compiler, a minimum CMake version of 3.19, and Python 3.8+.

User Inputs πŸ’»ΒΆ

1import numpy as np
2
3from mqt.qudits.quantum_circuit import QuantumCircuit

πŸš€ New QASM Extension:ΒΆ

Dive into a language meticulously designed to express quantum algorithms and circuits. MQT Qudits extends the OpenQASM 2.0 grammar, effortlessly adapting to mixed-dimensional registers. In the following, a DITQASM program is explicitly written, although several methods for importing programs from files are present in the library.

 1qasm = """
 2    DITQASM 2.0;
 3
 4    qreg field [7][5,5,5,5,5,5,5];
 5    qreg matter [2];
 6
 7    creg meas_matter[7];
 8    creg meas_fields[3];
 9
10    h matter[0] ctl field[0] field[1] [0,0];
11    cx field[2], matter[0];
12    cx field[2], matter[1];
13    rxy (0, 1, pi, pi/2) field[3];
14
15    measure q[0] -> meas[0];
16    measure q[1] -> meas[1];
17    measure q[2] -> meas[2];
18    """

A new feature is the control syntax:

_operation_   __ctl__  _quditline_  [list of qudit control levels]

We can import the DITQASM program and construct a quantum circuit.

1circuit = QuantumCircuit()
2circuit.from_qasm(qasm)
3
4print(f"Number of operations: {len(circuit.instructions)}")
5print(f"Number of qudits in the circuit: {circuit.num_qudits}")
6print(f"Dimensions: {circuit.dimensions}")
Number of operations: 4
Number of qudits in the circuit: 9
Dimensions: [5, 5, 5, 5, 5, 5, 5, 2, 2]

🐍 Python Interface¢

Constructing and manipulating quantum programs becomes a breeze with Python. You have the flexibility to:

  1. Initialize Quantum Circuits: Start by creating your quantum circuits effortlessly.

  2. Create Quantum Registers: Build dedicated quantum registers tailored to your needs.

  3. Compose Circuits: Seamlessly bring together your quantum registers, forming a unified and powerful circuit.

  4. Apply Operations: Easily apply a variety of qudit operations, without worrying about the right representation.

Let’s construct a quantum circuit from scratch, with the python interface.

 1from mqt.qudits.quantum_circuit import QuantumRegister
 2
 3circuit = QuantumCircuit()
 4
 5field_reg = QuantumRegister("fields", 1, [7])
 6matter_reg = QuantumRegister("matter", 1, [2])
 7
 8circuit.append(field_reg)
 9circuit.append(matter_reg)
10
11print(f"Number of operations: {len(circuit.instructions)}")
12print(f"Number of qudits in the circuit: {circuit.num_qudits}")
13print(f"Gate set: {circuit.gate_set}")
Number of operations: 0
Number of qudits in the circuit: 2
csum
cu_one
cu_two
cu_multi
cx
gellmann
h
ls
ms
pm
r
rh
randu
rz
virtrz
s
x
z
Gate set: None

No operations were inserted yet, let’s take a look at how operations can be applied!

The size of every line is detected automatically and the right operations are applied to the right qudits

1circuit.h(field_reg[0])
2circuit.csum([field_reg[0], matter_reg[0]])
3
4print(f"Number of operations: {len(circuit.instructions)}")
5print(f"Number of qudits in the circuit: {circuit.num_qudits}")
Number of operations: 2
Number of qudits in the circuit: 2

It is possible to export the code as well and share your program in a QASM file.

1print(circuit.to_qasm())
DITQASM 2.0;
qreg fields [1][7];
qreg matter [1][2];
creg meas[2];
h fields[0];
csum fields[0], matter[0];
measure fields[0] -> meas[0];
measure matter[0] -> meas[1];

Let’s save the circuit to a file

1file = circuit.save_to_file("my_circuit", ".")

and load it back

1circuit.load_from_file(file)
2
3print("Program:", circuit.to_qasm(), sep="\n")
4print("Dimensions: ", circuit.dimensions)
Program:
DITQASM 2.0;
qreg fields [1][7];
qreg matter [1][2];
creg meas[2];
h fields[0];
csum fields[0], matter[0];
measure fields[0] -> meas[0];
measure matter[0] -> meas[1];

Dimensions:  [7, 2]

Custom gates can be added to the circuit as well.

1n = 5
2random_matrix = np.random.randn(n, n) + 1j * np.random.randn(n, n)
3
4Q, R = np.linalg.qr(random_matrix)
5
6unitary_matrix = Q
7cu = circuit.cu_one(field_reg[0], unitary_matrix)

Gates follow the order:

  • target qudit/s : list or single number

  • parameters list with order lower level, upper level, control level, theta, phi

  • control data

A simple qudit gate can be added as follows:

1r = circuit.r(field_reg[0], [0, 1, np.pi / 5, np.pi / 7])

Operations can also be controlled by other qudits, as shown below:

1from mqt.qudits.quantum_circuit.gate import ControlData
2
3r_c1 = circuit.r(field_reg[0], [0, 1, np.pi / 5, np.pi / 7], ControlData([matter_reg[0]], [1]))

or as

1r_c2 = circuit.r(field_reg[0], [0, 1, np.pi / 5, np.pi / 7]).control([matter_reg[0]], [1])

The representation of the matrix corresponding to a gate is dynamic:

  • 0: no identities

  • 1: identities in between long-range gates are introduced

  • 2: full circuit unitary

1print(f"Gate matrix for {r._name}:", r.to_matrix(0), sep="\n")
Gate matrix for R7:
[[ 0.95105652+0.j         -0.13407745-0.27841469j  0.        +0.j
   0.        +0.j          0.        +0.j          0.        +0.j
   0.        +0.j        ]
 [ 0.13407745-0.27841469j  0.95105652+0.j          0.        +0.j
   0.        +0.j          0.        +0.j          0.        +0.j
   0.        +0.j        ]
 [ 0.        +0.j          0.        +0.j          1.        +0.j
   0.        +0.j          0.        +0.j          0.        +0.j
   0.        +0.j        ]
 [ 0.        +0.j          0.        +0.j          0.        +0.j
   1.        +0.j          0.        +0.j          0.        +0.j
   0.        +0.j        ]
 [ 0.        +0.j          0.        +0.j          0.        +0.j
   0.        +0.j          1.        +0.j          0.        +0.j
   0.        +0.j        ]
 [ 0.        +0.j          0.        +0.j          0.        +0.j
   0.        +0.j          0.        +0.j          1.        +0.j
   0.        +0.j        ]
 [ 0.        +0.j          0.        +0.j          0.        +0.j
   0.        +0.j          0.        +0.j          0.        +0.j
   1.        +0.j        ]]

The inverse of any gate can easily be obtained.

1rd = r.dag()
2print(f"Inverse gate matrix for {r._name}:", rd.to_matrix(0), sep="\n")
Inverse gate matrix for R7_dag:
[[ 0.95105652-0.j          0.13407745+0.27841469j  0.        -0.j
   0.        -0.j          0.        -0.j          0.        -0.j
   0.        -0.j        ]
 [-0.13407745+0.27841469j  0.95105652-0.j          0.        -0.j
   0.        -0.j          0.        -0.j          0.        -0.j
   0.        -0.j        ]
 [ 0.        -0.j          0.        -0.j          1.        -0.j
   0.        -0.j          0.        -0.j          0.        -0.j
   0.        -0.j        ]
 [ 0.        -0.j          0.        -0.j          0.        -0.j
   1.        -0.j          0.        -0.j          0.        -0.j
   0.        -0.j        ]
 [ 0.        -0.j          0.        -0.j          0.        -0.j
   0.        -0.j          1.        -0.j          0.        -0.j
   0.        -0.j        ]
 [ 0.        -0.j          0.        -0.j          0.        -0.j
   0.        -0.j          0.        -0.j          1.        -0.j
   0.        -0.j        ]
 [ 0.        -0.j          0.        -0.j          0.        -0.j
   0.        -0.j          0.        -0.j          0.        -0.j
   1.        -0.j        ]]

The control information can be accessed as well.

1r_c1.control_info
{'target': 0,
 'dimensions_slice': 7,
 'params': [0, 1, 0.6283185307179586, 0.4487989505128276],
 'controls': ControlData(indices=[1], ctrl_states=[1])}

Two- and multi-qudit gates follow the rule:

  • two : target_qudits first is control, second is target

  • multi: all are controls, except last one is target

1r_c1.reference_lines
[1, 0]

Simulation πŸš€ΒΆ

After crafting your quantum circuit with precision, take it for a spin using two distinct engines, each flaunting its unique set of data structures.

  • External Tensor-Network Simulator: Delve into the quantum realm with a robust external tensor-network simulator. Can simulate all the gate-set.

  • MiSiM (C++-Powered): Unleash the power of decision-diagram-based simulation with MiSiM, seamlessly interfaced with Python for a fluid and efficient experience. πŸŒπŸ’‘Can only simulate the machine following machine gate set:

    • csum

    • cx

    • h

    • rxy

    • rz

    • rh

    • virtrz

    • s

    • x

    • z

Basic SimulationΒΆ

 1circuit = QuantumCircuit()
 2
 3field_reg = QuantumRegister("fields", 1, [3])
 4matter_reg = QuantumRegister("matter", 1, [3])
 5
 6circuit.append(field_reg)
 7circuit.append(matter_reg)
 8
 9h = circuit.h(field_reg[0])
10csum = circuit.csum([field_reg[0], matter_reg[0]])
11
12print(f"Number of operations: {len(circuit.instructions)}")
13print(f"Number of qudits in the circuit: {circuit.num_qudits}")
Number of operations: 2
Number of qudits in the circuit: 2
1from mqt.qudits.simulation import MQTQuditProvider
2
3provider = MQTQuditProvider()
4provider.backends("sim")
['tnsim', 'misim']
 1from mqt.qudits.visualisation import plot_counts, plot_state
 2
 3backend = provider.get_backend("tnsim")
 4
 5job = backend.run(circuit)
 6result = job.result()
 7
 8state_vector = result.get_state_vector()
 9
10plot_state(state_vector, circuit)
_images/43dd1f44c70964e59239e93527b69f82566229c05a5732d864195d96ebf2c341.svg
1backend = provider.get_backend("misim")
2
3job = backend.run(circuit)
4result = job.result()
5
6state_vector = result.get_state_vector()
7
8plot_state(state_vector, circuit)
_images/2d9ed8cde8d24b9dc319adce20e283c685883e456cf7618408bd96cad2d8fc0f.svg

Extending Engines with Noise Model and Properties for FakeBackendΒΆ

Enhance your quantum simulation experience by extending the engines with a noise model and incorporating various properties. By combining a noise model and carefully tuned properties, you can craft a FakeBackend that closely emulates the performance of the best quantum machines in experimental laboratories. This allows for more realistic and insightful quantum simulations.

Experiment, iterate, and simulate quantum circuits with the sophistication of real-world conditions, all within the controlled environment of your simulation. πŸ› οΈπŸ”¬

 1from mqt.qudits.simulation.noise_tools.noise import Noise, NoiseModel
 2
 3# Depolarizing quantum errors
 4local_error = Noise(probability_depolarizing=0.001, probability_dephasing=0.001)
 5local_error_rz = Noise(probability_depolarizing=0.03, probability_dephasing=0.03)
 6
 7entangling_error = Noise(probability_depolarizing=0.1, probability_dephasing=0.001)
 8entangling_error_extra = Noise(probability_depolarizing=0.1, probability_dephasing=0.1)
 9
10entangling_error_on_target = Noise(probability_depolarizing=0.1, probability_dephasing=0.0)
11entangling_error_on_control = Noise(probability_depolarizing=0.01, probability_dephasing=0.0)
12
13# Add errors to noise_tools model
14
15noise_model = NoiseModel()  # We know that the architecture is only two qudits
16# Very noisy gate
17noise_model.add_all_qudit_quantum_error(local_error, ["csum"])
18noise_model.add_recurrent_quantum_error_locally(local_error, ["csum"], [0])
19# Entangling gates
20noise_model.add_nonlocal_quantum_error(entangling_error, ["cx", "ls", "ms"])
21noise_model.add_nonlocal_quantum_error_on_target(entangling_error_on_target, ["cx", "ls", "ms"])
22noise_model.add_nonlocal_quantum_error_on_control(entangling_error_on_control, ["csum", "cx", "ls", "ms"])
23# Super noisy Entangling gates
24noise_model.add_nonlocal_quantum_error(entangling_error_extra, ["csum"])
25# Local Gates
26noise_model.add_quantum_error_locally(local_error, ["h", "rxy", "s", "x", "z"])
27noise_model.add_quantum_error_locally(local_error_rz, ["rz", "virtrz"])
28
29print(noise_model.quantum_errors)
{'csum': {'all': Noise(probability_depolarizing=0.001, probability_dephasing=0.001), (0,): Noise(probability_depolarizing=0.001, probability_dephasing=0.001), 'control': Noise(probability_depolarizing=0.01, probability_dephasing=0.0), 'nonlocal': Noise(probability_depolarizing=0.1, probability_dephasing=0.1)}, 'cx': {'nonlocal': Noise(probability_depolarizing=0.1, probability_dephasing=0.001), 'target': Noise(probability_depolarizing=0.1, probability_dephasing=0.0), 'control': Noise(probability_depolarizing=0.01, probability_dephasing=0.0)}, 'ls': {'nonlocal': Noise(probability_depolarizing=0.1, probability_dephasing=0.001), 'target': Noise(probability_depolarizing=0.1, probability_dephasing=0.0), 'control': Noise(probability_depolarizing=0.01, probability_dephasing=0.0)}, 'ms': {'nonlocal': Noise(probability_depolarizing=0.1, probability_dephasing=0.001), 'target': Noise(probability_depolarizing=0.1, probability_dephasing=0.0), 'control': Noise(probability_depolarizing=0.01, probability_dephasing=0.0)}, 'h': {'local': Noise(probability_depolarizing=0.001, probability_dephasing=0.001)}, 'rxy': {'local': Noise(probability_depolarizing=0.001, probability_dephasing=0.001)}, 's': {'local': Noise(probability_depolarizing=0.001, probability_dephasing=0.001)}, 'x': {'local': Noise(probability_depolarizing=0.001, probability_dephasing=0.001)}, 'z': {'local': Noise(probability_depolarizing=0.001, probability_dephasing=0.001)}, 'rz': {'local': Noise(probability_depolarizing=0.03, probability_dephasing=0.03)}, 'virtrz': {'local': Noise(probability_depolarizing=0.03, probability_dephasing=0.03)}}

We can set the noise model for the simulation, but also set several other flags:

  • shots: number of shots for the stochastic simulation

  • memory: flag for saving shots (True/False)

  • full_state_memory: save the full noisy states

  • file_path: file path of the h5 database storing the data

  • file_name: name of the file

1backend = provider.get_backend("tnsim")
2
3job = backend.run(circuit, noise_model=noise_model)
4
5result = job.result()
6counts = result.get_counts()
7
8plot_counts(counts, circuit)
_images/1d32a3bfc27eac276a432521f3df0cd97324d7e6f526e49f2543fde058e27d40.svg
{'00': 332,
 '01': 0,
 '02': 3,
 '10': 4,
 '11': 329,
 '12': 0,
 '20': 0,
 '21': 7,
 '22': 325}

You can also invoke a fake backend and retrieve a few relevant properties, that are already embedded in them

1provider = MQTQuditProvider()
2provider.backends("fake")
['faketraps2trits', 'faketraps2six']
1backend_ion = provider.get_backend("faketraps2trits", shots=1000)
1import matplotlib.pyplot as plt
2import networkx as nx
3
4mapping = backend_ion.energy_level_graphs
5
6pos = nx.circular_layout(mapping[0])
7nx.draw(mapping[0], pos, with_labels=True, node_size=2000, node_color="lightblue", font_size=12, font_weight="bold")
8plt.show()
_images/4956c0f7c137fb66fece8a828734bbf3f594e75a26b405ae5a6eba8bf35818d8.svg
1job = backend_ion.run(circuit)
2result = job.result()
3counts = result.get_counts()
4
5plot_counts(counts, circuit)
_images/46f4ddcef987ed1b78be20eeff5926827f61f208b787a5ed24f0b30545617020.svg
{'00': 328,
 '01': 0,
 '02': 1,
 '10': 2,
 '11': 322,
 '12': 0,
 '20': 0,
 '21': 2,
 '22': 345}

Compilation βš™οΈΒΆ

Tailor your quantum compilation process to achieve optimal performance and emulate the intricacies of experimental setups.

Compiler Customization with Modern PassesΒΆ

  1. Optimization Strategies: Implement specific optimization strategies based on your quantum algorithm’s characteristics. Fine-tune compilation for better resource utilization and reduced gate counts.

  2. Gate Decomposition: Customize gate decomposition techniques to match the capabilities of experimental quantum hardware. Aligning with the native gate set enhances the efficiency of your compiled circuits.

Experimental-Inspired CompilationΒΆ

Emulate the features of the best experimental laboratories in your compilation process. Leverage modern compiler passes to customize optimization, gate decomposition, and noise-aware strategies, creating compiled circuits that closely resemble the challenges and advantages of cutting-edge quantum hardware.

Customize, compile, and push the boundaries of quantum algorithms with a tailored approach to quantum compilation. πŸ› οΈπŸ”§πŸš€

1from mqt.qudits.compiler import QuditCompiler
1qudit_compiler = QuditCompiler()
2
3passes = ["PhyLocQRPass"]
1compiled_circuit_qr = qudit_compiler.compile(backend_ion, circuit, passes)
2
3print(f"Number of operations: {len(compiled_circuit_qr.instructions)}")
4print(f"Number of qudits in the circuit: {compiled_circuit_qr.num_qudits}")
Number of operations: 10
Number of qudits in the circuit: 2
1job = backend_ion.run(compiled_circuit_qr)
2
3result = job.result()
4counts = result.get_counts()
5
6plot_counts(counts, compiled_circuit_qr)
_images/8b43ce16001d45d06a77cf78b3b80efe9b00d2ef41c4e371954ce57b81a91ca2.svg
{'00': 326,
 '01': 0,
 '02': 4,
 '10': 0,
 '11': 326,
 '12': 0,
 '20': 0,
 '21': 2,
 '22': 342}
1passes = ["PhyLocAdaPass", "ZPropagationPass", "ZRemovalPass"]
2
3compiled_circuit_ada = qudit_compiler.compile(backend_ion, circuit, passes)
4
5print(f"Number of operations: {len(compiled_circuit_ada.instructions)}")
6print(f"Number of qudits in the circuit: {compiled_circuit_ada.num_qudits}")
Number of operations: 5
Number of qudits in the circuit: 2
1job = backend_ion.run(compiled_circuit_ada)
2
3result = job.result()
4counts = result.get_counts()
5
6plot_counts(counts, compiled_circuit_ada)
_images/86d32944e9dca0474a15e673a85d37642142b8a9e237d54c39ae436bcee9649d.svg
{'00': 321,
 '01': 0,
 '02': 4,
 '10': 2,
 '11': 328,
 '12': 0,
 '20': 0,
 '21': 3,
 '22': 342}
1from mqt.qudits.visualisation import draw_qudit_local
2
3draw_qudit_local(compiled_circuit_ada)
|0>-----[R01(1.57,-2.09)]----[R02(1.23,-2.62)]----[R02(3.14,-2.62)]----[R01(1.57,-0.52)]----MG-----=||
|0>-----MG----MG----MG----MG----MG-----=||

PublicationsΒΆ

MQT Qudits is academic software. Thus, many of its built-in algorithms have been published as scientific papers [1, 2, 3, 4, 5].

If you use MQT Qudits in your work, we would appreciate if you cited the respective paper(s).

[1]

Kevin Mato, Stefan Hillmich, and Robert Wille. Mixed-dimensional qudit state preparation using edge-weighted decision diagrams. In Design Automation Conference (DAC). 2024.

[2]

Kevin Mato, Stefan Hillmich, and Robert Wille. Mixed-dimensional quantum circuit simulation with decision diagrams. In International Conference on Quantum Computing and Engineering (QCE). 2023. doi:10.1109/QCE57702.2023.00112.

[3]

Kevin Mato, Stefan Hillmich, and Robert Wille. Compression of qubit circuits: Mapping to mixed-dimensional quantum systems. In International Conference on Quantum Software (QSW). 2023. doi:10.1109/QSW59989.2023.00027.

[4]

Kevin Mato, Martin Ringbauer, Stefan Hillmich, and Robert Wille. Compilation of entangling gates for high-dimensional quantum systems. In Asia and South Pacific Design Automation Conference (ASP-DAC). 2023. doi:10.1145/3566097.3567930.

[5]

Kevin Mato, Martin Ringbauer, Stefan Hillmich, and Robert Wille. Adaptive compilation of multi-level quantum operations. In International Conference on Quantum Computing and Engineering (QCE). 2022. doi:10.1109/QCE53715.2022.00070.

mqt.quditsΒΆ

MQT Qudits - A framework for mixed-dimensional qudit quantum computing.

SubpackagesΒΆ

mqt.qudits.compilerΒΆ

SubpackagesΒΆ
mqt.qudits.compiler.compilation_minitoolsΒΆ

Common utilities for compilation.

SubmodulesΒΆ
mqt.qudits.compiler.compilation_minitools.local_compilation_minitoolsΒΆ
Module ContentsΒΆ
swap_elements(list_nodes, i, j)[source]ΒΆ
new_mod(a, b=2 * np.pi)[source]ΒΆ
pi_mod(a)[source]ΒΆ
regulate_theta(angle)[source]ΒΆ
phi_cost(theta)[source]ΒΆ
theta_cost(theta)[source]ΒΆ
rotation_cost_calc(gate, placement)[source]ΒΆ
mqt.qudits.compiler.compilation_minitools.naive_unitary_verifierΒΆ
Module ContentsΒΆ
class UnitaryVerifier(sequence, target, dimensions, nodes=None, initial_map=None, final_map=None)[source]ΒΆ

Verifies unitary matrices. sequence is a list of numpy arrays target is a numpy array dimensions is list of ints, equals to the dimensions of the qudits involved in the target operation initial_map is a list representing the mapping of the logic states to the physical ones at the beginning of the computation final_map is a list representing the mapping of the logic states to the physical ones at the end of the computation

get_perm_matrix(nodes, mapping)[source]ΒΆ
verify()[source]ΒΆ
mqt.qudits.compiler.compilation_minitools.numerical_ansatz_utilsΒΆ
Module ContentsΒΆ
on1(gate, other_size)[source]ΒΆ
on0(gate, other_size)[source]ΒΆ
gate_expand_to_circuit(gate, circuits_size, target, dims=None)[source]ΒΆ
apply_gate_to_tlines(gate_matrix, circuits_size=2, targets=None, dims=None)[source]ΒΆ
Package ContentsΒΆ
new_mod(a, b=2 * np.pi)[source]ΒΆ
phi_cost(theta)[source]ΒΆ
pi_mod(a)[source]ΒΆ
regulate_theta(angle)[source]ΒΆ
rotation_cost_calc(gate, placement)[source]ΒΆ
swap_elements(list_nodes, i, j)[source]ΒΆ
theta_cost(theta)[source]ΒΆ
class UnitaryVerifier(sequence, target, dimensions, nodes=None, initial_map=None, final_map=None)[source]ΒΆ

Verifies unitary matrices. sequence is a list of numpy arrays target is a numpy array dimensions is list of ints, equals to the dimensions of the qudits involved in the target operation initial_map is a list representing the mapping of the logic states to the physical ones at the beginning of the computation final_map is a list representing the mapping of the logic states to the physical ones at the end of the computation

get_perm_matrix(nodes, mapping)[source]ΒΆ
verify()[source]ΒΆ
apply_gate_to_tlines(gate_matrix, circuits_size=2, targets=None, dims=None)[source]ΒΆ
gate_expand_to_circuit(gate, circuits_size, target, dims=None)[source]ΒΆ
on0(gate, other_size)[source]ΒΆ
on1(gate, other_size)[source]ΒΆ
mqt.qudits.compiler.oneditΒΆ
SubpackagesΒΆ
mqt.qudits.compiler.onedit.local_operation_swapΒΆ
SubmodulesΒΆ
mqt.qudits.compiler.onedit.local_operation_swap.swap_routineΒΆ
Module ContentsΒΆ
find_logic_from_phys(lev_a, lev_b, graph)[source]ΒΆ
graph_rule_update(gate, graph) None[source]ΒΆ
graph_rule_ongate(gate, graph) R[source]ΒΆ
gate_chain_condition(previous_gates, current)[source]ΒΆ
route_states2rotate_basic(gate, orig_placement)[source]ΒΆ
cost_calculator(gate, placement, non_zeros)[source]ΒΆ
Package ContentsΒΆ
cost_calculator(gate, placement, non_zeros)[source]ΒΆ
gate_chain_condition(previous_gates, current)[source]ΒΆ
graph_rule_ongate(gate, graph) R[source]ΒΆ
graph_rule_update(gate, graph) None[source]ΒΆ
route_states2rotate_basic(gate, orig_placement)[source]ΒΆ
mqt.qudits.compiler.onedit.local_phases_transpilationΒΆ
SubmodulesΒΆ
mqt.qudits.compiler.onedit.local_phases_transpilation.propagate_virtrzΒΆ
Module ContentsΒΆ
class ZPropagationPass(backend, back=True)[source]ΒΆ

Bases: mqt.qudits.compiler.CompilerPass

Helper class that provides a standard way to create an ABC using inheritance.

transpile(circuit)[source]ΒΆ
propagate_z(circuit, line, back)[source]ΒΆ
find_intervals_with_same_target_qudits(instructions)[source]ΒΆ
remove_z(original_circuit, back=True)[source]ΒΆ
mqt.qudits.compiler.onedit.local_phases_transpilation.remove_phase_rotationsΒΆ
Module ContentsΒΆ
class ZRemovalPass(backend)[source]ΒΆ

Bases: mqt.qudits.compiler.CompilerPass

Helper class that provides a standard way to create an ABC using inheritance.

transpile(circuit)[source]ΒΆ
remove_rz_gates(original_circuit, reverse=False)[source]ΒΆ
remove_initial_rz(original_circuit)[source]ΒΆ
remove_trailing_rz_sequence(original_circuit)[source]ΒΆ
Package ContentsΒΆ
class ZPropagationPass(backend, back=True)[source]ΒΆ

Bases: mqt.qudits.compiler.CompilerPass

Helper class that provides a standard way to create an ABC using inheritance.

transpile(circuit)[source]ΒΆ
propagate_z(circuit, line, back)[source]ΒΆ
find_intervals_with_same_target_qudits(instructions)[source]ΒΆ
remove_z(original_circuit, back=True)[source]ΒΆ
class ZRemovalPass(backend)[source]ΒΆ

Bases: mqt.qudits.compiler.CompilerPass

Helper class that provides a standard way to create an ABC using inheritance.

transpile(circuit)[source]ΒΆ
remove_rz_gates(original_circuit, reverse=False)[source]ΒΆ
remove_initial_rz(original_circuit)[source]ΒΆ
remove_trailing_rz_sequence(original_circuit)[source]ΒΆ
mqt.qudits.compiler.onedit.mapping_aware_transpilationΒΆ
SubmodulesΒΆ
mqt.qudits.compiler.onedit.mapping_aware_transpilation.phy_local_adaptive_decompΒΆ
Module ContentsΒΆ
class PhyLocAdaPass(backend)[source]ΒΆ

Bases: mqt.qudits.compiler.CompilerPass

Helper class that provides a standard way to create an ABC using inheritance.

transpile(circuit)[source]ΒΆ
class PhyAdaptiveDecomposition(gate, graph_orig, cost_limit=(0, 0), dimension=-1, Z_prop=False)[source]ΒΆ
execute()[source]ΒΆ
Z_extraction(decomposition, placement, phase_propagation)[source]ΒΆ
DFS(current_root, level=0) None[source]ΒΆ
mqt.qudits.compiler.onedit.mapping_aware_transpilation.phy_local_qr_decompΒΆ
Module ContentsΒΆ
class PhyLocQRPass(backend)[source]ΒΆ

Bases: mqt.qudits.compiler.CompilerPass

Helper class that provides a standard way to create an ABC using inheritance.

transpile(circuit)[source]ΒΆ
class PhyQrDecomp(gate, graph_orig, Z_prop=False, not_stand_alone=True)[source]ΒΆ
execute()[source]ΒΆ
Package ContentsΒΆ
class PhyAdaptiveDecomposition(gate, graph_orig, cost_limit=(0, 0), dimension=-1, Z_prop=False)[source]ΒΆ
execute()[source]ΒΆ
Z_extraction(decomposition, placement, phase_propagation)[source]ΒΆ
DFS(current_root, level=0) None[source]ΒΆ
class PhyLocAdaPass(backend)[source]ΒΆ

Bases: mqt.qudits.compiler.CompilerPass

Helper class that provides a standard way to create an ABC using inheritance.

transpile(circuit)[source]ΒΆ
class PhyLocQRPass(backend)[source]ΒΆ

Bases: mqt.qudits.compiler.CompilerPass

Helper class that provides a standard way to create an ABC using inheritance.

transpile(circuit)[source]ΒΆ
class PhyQrDecomp(gate, graph_orig, Z_prop=False, not_stand_alone=True)[source]ΒΆ
execute()[source]ΒΆ
mqt.qudits.compiler.onedit.mapping_un_aware_transpilationΒΆ
SubmodulesΒΆ
mqt.qudits.compiler.onedit.mapping_un_aware_transpilation.log_local_adaptive_decompΒΆ
Module ContentsΒΆ
class LogLocAdaPass(backend)[source]ΒΆ

Bases: mqt.qudits.compiler.CompilerPass

Helper class that provides a standard way to create an ABC using inheritance.

transpile(circuit)[source]ΒΆ
class LogAdaptiveDecomposition(gate, graph_orig, cost_limit=(0, 0), dimension=-1, Z_prop=False)[source]ΒΆ
execute()[source]ΒΆ
z_extraction(decomposition, placement, phase_propagation)[source]ΒΆ
DFS(current_root, level=0) None[source]ΒΆ
mqt.qudits.compiler.onedit.mapping_un_aware_transpilation.log_local_qr_decompΒΆ
Module ContentsΒΆ
class LogLocQRPass(backend)[source]ΒΆ

Bases: mqt.qudits.compiler.CompilerPass

Helper class that provides a standard way to create an ABC using inheritance.

transpile(circuit)[source]ΒΆ
class QrDecomp(gate, graph_orig, Z_prop=False, not_stand_alone=True)[source]ΒΆ
execute()[source]ΒΆ
Package ContentsΒΆ
class LogAdaptiveDecomposition(gate, graph_orig, cost_limit=(0, 0), dimension=-1, Z_prop=False)[source]ΒΆ
execute()[source]ΒΆ
z_extraction(decomposition, placement, phase_propagation)[source]ΒΆ
DFS(current_root, level=0) None[source]ΒΆ
class LogLocAdaPass(backend)[source]ΒΆ

Bases: mqt.qudits.compiler.CompilerPass

Helper class that provides a standard way to create an ABC using inheritance.

transpile(circuit)[source]ΒΆ
class LogLocQRPass(backend)[source]ΒΆ

Bases: mqt.qudits.compiler.CompilerPass

Helper class that provides a standard way to create an ABC using inheritance.

transpile(circuit)[source]ΒΆ
Package ContentsΒΆ
class ZPropagationPass(backend, back=True)[source]ΒΆ

Bases: mqt.qudits.compiler.CompilerPass

Helper class that provides a standard way to create an ABC using inheritance.

transpile(circuit)[source]ΒΆ
propagate_z(circuit, line, back)[source]ΒΆ
find_intervals_with_same_target_qudits(instructions)[source]ΒΆ
remove_z(original_circuit, back=True)[source]ΒΆ
class ZRemovalPass(backend)[source]ΒΆ

Bases: mqt.qudits.compiler.CompilerPass

Helper class that provides a standard way to create an ABC using inheritance.

transpile(circuit)[source]ΒΆ
remove_rz_gates(original_circuit, reverse=False)[source]ΒΆ
remove_initial_rz(original_circuit)[source]ΒΆ
remove_trailing_rz_sequence(original_circuit)[source]ΒΆ
class PhyLocAdaPass(backend)[source]ΒΆ

Bases: mqt.qudits.compiler.CompilerPass

Helper class that provides a standard way to create an ABC using inheritance.

transpile(circuit)[source]ΒΆ
class PhyLocQRPass(backend)[source]ΒΆ

Bases: mqt.qudits.compiler.CompilerPass

Helper class that provides a standard way to create an ABC using inheritance.

transpile(circuit)[source]ΒΆ
class LogLocAdaPass(backend)[source]ΒΆ

Bases: mqt.qudits.compiler.CompilerPass

Helper class that provides a standard way to create an ABC using inheritance.

transpile(circuit)[source]ΒΆ
class LogLocQRPass(backend)[source]ΒΆ

Bases: mqt.qudits.compiler.CompilerPass

Helper class that provides a standard way to create an ABC using inheritance.

transpile(circuit)[source]ΒΆ
mqt.qudits.compiler.twoditΒΆ
SubpackagesΒΆ
mqt.qudits.compiler.twodit.entanglement_qrΒΆ
SubmodulesΒΆ
mqt.qudits.compiler.twodit.entanglement_qr.crotΒΆ
Module ContentsΒΆ
CEX_SEQUENCEΒΆ
class CRotGen(circuit, indices)[source]ΒΆ
crot_101_as_list(theta, phi)[source]ΒΆ
permute_crot_101_as_list(i, theta, phase)[source]ΒΆ
permute_doubled_crot_101_as_list(i, theta, phase)[source]ΒΆ
z_from_crot_101_list(i, phase)[source]ΒΆ
mqt.qudits.compiler.twodit.entanglement_qr.log_ent_qr_cex_decompΒΆ
Module ContentsΒΆ
class LogEntQRCEXPass(backend)[source]ΒΆ

Bases: mqt.qudits.compiler.compiler_pass.CompilerPass

Helper class that provides a standard way to create an ABC using inheritance.

transpile(circuit)[source]ΒΆ
class EntangledQRCEX(gate, graph_orig_c, graph_orig_t)[source]ΒΆ
execute()[source]ΒΆ
mqt.qudits.compiler.twodit.entanglement_qr.pswapΒΆ
Module ContentsΒΆ
class PSwapGen(circuit, indices)[source]ΒΆ
pswap_101_as_list(teta, phi)[source]ΒΆ
permute_pswap_101_as_list(pos, theta, phase)[source]ΒΆ
permute_quad_pswap_101_as_list(pos, theta, phase)[source]ΒΆ
z_pswap_101_as_list(i, phase, dimension_single)[source]ΒΆ
Package ContentsΒΆ
class CRotGen(circuit, indices)[source]ΒΆ
crot_101_as_list(theta, phi)[source]ΒΆ
permute_crot_101_as_list(i, theta, phase)[source]ΒΆ
permute_doubled_crot_101_as_list(i, theta, phase)[source]ΒΆ
z_from_crot_101_list(i, phase)[source]ΒΆ
class EntangledQRCEX(gate, graph_orig_c, graph_orig_t)[source]ΒΆ
execute()[source]ΒΆ
class LogEntQRCEXPass(backend)[source]ΒΆ

Bases: mqt.qudits.compiler.compiler_pass.CompilerPass

Helper class that provides a standard way to create an ABC using inheritance.

transpile(circuit)[source]ΒΆ
class PSwapGen(circuit, indices)[source]ΒΆ
pswap_101_as_list(teta, phi)[source]ΒΆ
permute_pswap_101_as_list(pos, theta, phase)[source]ΒΆ
permute_quad_pswap_101_as_list(pos, theta, phase)[source]ΒΆ
z_pswap_101_as_list(i, phase, dimension_single)[source]ΒΆ
mqt.qudits.compiler.twodit.variational_twodit_compilationΒΆ
SubpackagesΒΆ
mqt.qudits.compiler.twodit.variational_twodit_compilation.ansatzΒΆ
SubmodulesΒΆ
mqt.qudits.compiler.twodit.variational_twodit_compilation.ansatz.ansatz_genΒΆ
Module ContentsΒΆ
prepare_ansatz(u, params, dims)[source]ΒΆ
cu_ansatz(P, dims)[source]ΒΆ
ms_ansatz(P, dims)[source]ΒΆ
ls_ansatz(P, dims)[source]ΒΆ
mqt.qudits.compiler.twodit.variational_twodit_compilation.ansatz.instantiateΒΆ
Module ContentsΒΆ
ansatz_decompose(u, params, dims)[source]ΒΆ
create_cu_instance(P, dims)[source]ΒΆ
create_ms_instance(P, dims)[source]ΒΆ
create_ls_instance(P, dims)[source]ΒΆ
mqt.qudits.compiler.twodit.variational_twodit_compilation.ansatz.parametrizeΒΆ
Module ContentsΒΆ
CUSTOM_PRIMITIVEΒΆ
params_splitter(params, dims)[source]ΒΆ
reindex(ir, jc, num_col)[source]ΒΆ
bound_1ΒΆ
bound_2ΒΆ
bound_3ΒΆ
generic_sud(params, dimension) ndarray[source]ΒΆ
Package ContentsΒΆ
cu_ansatz(P, dims)[source]ΒΆ
ls_ansatz(P, dims)[source]ΒΆ
ms_ansatz(P, dims)[source]ΒΆ
create_cu_instance(P, dims)[source]ΒΆ
create_ls_instance(P, dims)[source]ΒΆ
create_ms_instance(P, dims)[source]ΒΆ
reindex(ir, jc, num_col)[source]ΒΆ
mqt.qudits.compiler.twodit.variational_twodit_compilation.optΒΆ
SubmodulesΒΆ
mqt.qudits.compiler.twodit.variational_twodit_compilation.opt.distance_measuresΒΆ

FROM An alternative quantum fidelity for mixed states of qudits Xiaoguang Wang, 1, 2, * Chang-Shui Yu, 3 and x. x. Yi 3

Module ContentsΒΆ
size_check(a: ndarray, b: ndarray) bool[source]ΒΆ
fidelity_on_operator(a: ndarray, b: ndarray) float[source]ΒΆ
fidelity_on_unitares(a: ndarray, b: ndarray) float[source]ΒΆ
fidelity_on_density_operator(a: ndarray, b: ndarray) float[source]ΒΆ
density_operator(state_vector) ndarray[source]ΒΆ
frobenius_dist(x, y)[source]ΒΆ
mqt.qudits.compiler.twodit.variational_twodit_compilation.opt.optimizerΒΆ
Module ContentsΒΆ
class Optimizer[source]ΒΆ
OBJ_FIDELITY = 0.0001ΒΆ
SINGLE_DIM_0ΒΆ
SINGLE_DIM_1ΒΆ
TARGET_GATEΒΆ
MAX_NUM_LAYERSΒΆ
X_SOLUTION = []ΒΆ
FUN_SOLUTION = []ΒΆ
timer_var = FalseΒΆ
static bounds_assigner(b1, b2, b3, num_params_single, d)[source]ΒΆ
classmethod obj_fun_core(ansatz, lambdas)[source]ΒΆ
classmethod objective_fnc_ms(lambdas)[source]ΒΆ
classmethod objective_fnc_ls(lambdas)[source]ΒΆ
classmethod objective_fnc_cu(lambdas)[source]ΒΆ
classmethod solve_anneal(bounds, ansatz_type, result_queue) None[source]ΒΆ
Package ContentsΒΆ
density_operator(state_vector) ndarray[source]ΒΆ
fidelity_on_density_operator(a: ndarray, b: ndarray) float[source]ΒΆ
fidelity_on_operator(a: ndarray, b: ndarray) float[source]ΒΆ
fidelity_on_unitares(a: ndarray, b: ndarray) float[source]ΒΆ
frobenius_dist(x, y)[source]ΒΆ
size_check(a: ndarray, b: ndarray) bool[source]ΒΆ
class Optimizer[source]ΒΆ
OBJ_FIDELITY = 0.0001ΒΆ
SINGLE_DIM_0ΒΆ
SINGLE_DIM_1ΒΆ
TARGET_GATEΒΆ
MAX_NUM_LAYERSΒΆ
X_SOLUTION = []ΒΆ
FUN_SOLUTION = []ΒΆ
timer_var = FalseΒΆ
static bounds_assigner(b1, b2, b3, num_params_single, d)[source]ΒΆ
classmethod obj_fun_core(ansatz, lambdas)[source]ΒΆ
classmethod objective_fnc_ms(lambdas)[source]ΒΆ
classmethod objective_fnc_ls(lambdas)[source]ΒΆ
classmethod objective_fnc_cu(lambdas)[source]ΒΆ
classmethod solve_anneal(bounds, ansatz_type, result_queue) None[source]ΒΆ
SubmodulesΒΆ
Package ContentsΒΆ
class LogEntQRCEXPass(backend)[source]ΒΆ

Bases: mqt.qudits.compiler.compiler_pass.CompilerPass

Helper class that provides a standard way to create an ABC using inheritance.

transpile(circuit)[source]ΒΆ
SubmodulesΒΆ
mqt.qudits.compiler.compiler_passΒΆ
Module ContentsΒΆ
class CompilerPass(backend, **kwargs)[source]ΒΆ

Bases: abc.ABC

Helper class that provides a standard way to create an ABC using inheritance.

abstract transpile(circuit)[source]ΒΆ
mqt.qudits.compiler.dit_managerΒΆ
Module ContentsΒΆ
class QuditCompiler[source]ΒΆ
passes_enabledΒΆ
compile(backend, circuit, passes_names)[source]ΒΆ
Package ContentsΒΆ
class CompilerPass(backend, **kwargs)[source]ΒΆ

Bases: abc.ABC

Helper class that provides a standard way to create an ABC using inheritance.

abstract transpile(circuit)[source]ΒΆ

mqt.qudits.coreΒΆ

Core structure used in the package.

SubmodulesΒΆ
mqt.qudits.core.dfs_treeΒΆ
Module ContentsΒΆ
class Node(key, rotation, U_of_level, graph_current, current_cost, current_decomp_cost, max_cost, pi_pulses, parent_key, children=None)[source]ΒΆ
add(new_key, rotation, U_of_level, graph_current, current_cost, current_decomp_cost, max_cost, pi_pulses) None[source]ΒΆ
__str__() str[source]ΒΆ

Return str(self).

class NAryTree[source]ΒΆ
property total_sizeΒΆ
add(new_key, rotation, U_of_level, graph_current, current_cost, current_decomp_cost, max_cost, pi_pulses, parent_key=None) None[source]ΒΆ
find_node(node, key)[source]ΒΆ
depth(key)[source]ΒΆ
max_depth(node)[source]ΒΆ
size_refresh(node)[source]ΒΆ
found_checker(node)[source]ΒΆ
min_cost_decomp(node)[source]ΒΆ
retrieve_decomposition(node)[source]ΒΆ
is_empty()[source]ΒΆ
print_tree(node, str_aux)[source]ΒΆ
__str__() str[source]ΒΆ

Return str(self).

mqt.qudits.core.level_graphΒΆ
Module ContentsΒΆ
class LevelGraph(edges, nodes, nodes_physical_mapping=None, initialization_nodes=None, qudit_index=None, og_circuit=None)[source]ΒΆ

Bases: networkx.Graph

Base class for undirected graphs.

A Graph stores nodes and edges with optional data, or attributes.

Graphs hold undirected edges. Self loops are allowed but multiple (parallel) edges are not.

Nodes can be arbitrary (hashable) Python objects with optional key/value attributes, except that None is not allowed as a node.

Edges are represented as links between nodes with optional key/value attributes.

ParametersΒΆ
incoming_graph_datainput graph (optional, default: None)

Data to initialize graph. If None (default) an empty graph is created. The data can be any format that is supported by the to_networkx_graph() function, currently including edge list, dict of dicts, dict of lists, NetworkX graph, 2D NumPy array, SciPy sparse matrix, or PyGraphviz graph.

attrkeyword arguments, optional (default= no attributes)

Attributes to add to graph as key=value pairs.

See AlsoΒΆ

DiGraph MultiGraph MultiDiGraph

ExamplesΒΆ

Create an empty graph structure (a β€œnull graph”) with no nodes and no edges.

>>> G = nx.Graph()

G can be grown in several ways.

Nodes:

Add one node at a time:

>>> G.add_node(1)

Add the nodes from any container (a list, dict, set or even the lines from a file or the nodes from another graph).

>>> G.add_nodes_from([2, 3])
>>> G.add_nodes_from(range(100, 110))
>>> H = nx.path_graph(10)
>>> G.add_nodes_from(H)

In addition to strings and integers any hashable Python object (except None) can represent a node, e.g. a customized node object, or even another Graph.

>>> G.add_node(H)

Edges:

G can also be grown by adding edges.

Add one edge,

>>> G.add_edge(1, 2)

a list of edges,

>>> G.add_edges_from([(1, 2), (1, 3)])

or a collection of edges,

>>> G.add_edges_from(H.edges)

If some edges connect nodes not yet in the graph, the nodes are added automatically. There are no errors when adding nodes or edges that already exist.

Attributes:

Each graph, node, and edge can hold key/value attribute pairs in an associated attribute dictionary (the keys must be hashable). By default these are empty, but can be added or changed using add_edge, add_node or direct manipulation of the attribute dictionaries named graph, node and edge respectively.

>>> G = nx.Graph(day="Friday")
>>> G.graph
{'day': 'Friday'}

Add node attributes using add_node(), add_nodes_from() or G.nodes

>>> G.add_node(1, time="5pm")
>>> G.add_nodes_from([3], time="2pm")
>>> G.nodes[1]
{'time': '5pm'}
>>> G.nodes[1]["room"] = 714  # node must exist already to use G.nodes
>>> del G.nodes[1]["room"]  # remove attribute
>>> list(G.nodes(data=True))
[(1, {'time': '5pm'}), (3, {'time': '2pm'})]

Add edge attributes using add_edge(), add_edges_from(), subscript notation, or G.edges.

>>> G.add_edge(1, 2, weight=4.7)
>>> G.add_edges_from([(3, 4), (4, 5)], color="red")
>>> G.add_edges_from([(1, 2, {"color": "blue"}), (2, 3, {"weight": 8})])
>>> G[1][2]["weight"] = 4.7
>>> G.edges[1, 2]["weight"] = 4

Warning: we protect the graph data structure by making G.edges a read-only dict-like structure. However, you can assign to attributes in e.g. G.edges[1, 2]. Thus, use 2 sets of brackets to add/change data attributes: G.edges[1, 2][β€˜weight’] = 4 (For multigraphs: MG.edges[u, v, key][name] = value).

Shortcuts:

Many common graph features allow python syntax to speed reporting.

>>> 1 in G  # check if node in graph
True
>>> [n for n in G if n < 3]  # iterate through nodes
[1, 2]
>>> len(G)  # number of nodes in graph
5

Often the best way to traverse all edges of a graph is via the neighbors. The neighbors are reported as an adjacency-dict G.adj or G.adjacency()

>>> for n, nbrsdict in G.adjacency():
...     for nbr, eattr in nbrsdict.items():
...         if "weight" in eattr:
...             # Do something useful with the edges
...             pass

But the edges() method is often more convenient:

>>> for u, v, weight in G.edges.data("weight"):
...     if weight is not None:
...         # Do something useful with the edges
...         pass

Reporting:

Simple graph information is obtained using object-attributes and methods. Reporting typically provides views instead of containers to reduce memory usage. The views update as the graph is updated similarly to dict-views. The objects nodes, edges and adj provide access to data attributes via lookup (e.g. nodes[n], edges[u, v], adj[u][v]) and iteration (e.g. nodes.items(), nodes.data(β€˜color’), nodes.data(β€˜color’, default=’blue’) and similarly for edges) Views exist for nodes, edges, neighbors()/adj and degree.

For details on these and other miscellaneous methods, see below.

Subclasses (Advanced):

The Graph class uses a dict-of-dict-of-dict data structure. The outer dict (node_dict) holds adjacency information keyed by node. The next dict (adjlist_dict) represents the adjacency information and holds edge data keyed by neighbor. The inner dict (edge_attr_dict) represents the edge data and holds edge attribute values keyed by attribute names.

Each of these three dicts can be replaced in a subclass by a user defined dict-like object. In general, the dict-like features should be maintained but extra features can be added. To replace one of the dicts create a new graph class by changing the class(!) variable holding the factory for that dict-like structure.

node_dict_factoryfunction, (default: dict)

Factory function to be used to create the dict containing node attributes, keyed by node id. It should require no arguments and return a dict-like object

node_attr_dict_factory: function, (default: dict)

Factory function to be used to create the node attribute dict which holds attribute values keyed by attribute name. It should require no arguments and return a dict-like object

adjlist_outer_dict_factoryfunction, (default: dict)

Factory function to be used to create the outer-most dict in the data structure that holds adjacency info keyed by node. It should require no arguments and return a dict-like object.

adjlist_inner_dict_factoryfunction, (default: dict)

Factory function to be used to create the adjacency list dict which holds edge data keyed by neighbor. It should require no arguments and return a dict-like object

edge_attr_dict_factoryfunction, (default: dict)

Factory function to be used to create the edge attribute dict which holds attribute values keyed by attribute name. It should require no arguments and return a dict-like object.

graph_attr_dict_factoryfunction, (default: dict)

Factory function to be used to create the graph attribute dict which holds attribute values keyed by attribute name. It should require no arguments and return a dict-like object.

Typically, if your extension doesn’t impact the data structure all methods will inherit without issue except: to_directed/to_undirected. By default these methods create a DiGraph/Graph class and you probably want them to create your extension of a DiGraph/Graph. To facilitate this we define two class variables that you can set in your subclass.

to_directed_classcallable, (default: DiGraph or MultiDiGraph)

Class to create a new graph structure in the to_directed method. If None, a NetworkX class (DiGraph or MultiDiGraph) is used.

to_undirected_classcallable, (default: Graph or MultiGraph)

Class to create a new graph structure in the to_undirected method. If None, a NetworkX class (Graph or MultiGraph) is used.

Subclassing Example

Create a low memory graph class that effectively disallows edge attributes by using a single attribute dict for all edges. This reduces the memory used, but you lose edge attributes.

>>> class ThinGraph(nx.Graph):
...     all_edge_dict = {"weight": 1}
...
...     def single_edge_dict(self):
...         return self.all_edge_dict
...
...     edge_attr_dict_factory = single_edge_dict
>>> G = ThinGraph()
>>> G.add_edge(2, 1)
>>> G[2][1]
{'weight': 1}
>>> G.add_edge(2, 2)
>>> G[2][1] is G[2][2]
True
property log_phy_mapΒΆ
phase_storing_setup() None[source]ΒΆ
distance_nodes(source, target)[source]ΒΆ
distance_nodes_pi_pulses_fixed_ancilla(source, target)[source]ΒΆ
logic_physical_map(physical_nodes) None[source]ΒΆ
define__states(initialization_nodes, inreach_nodes) None[source]ΒΆ
update_list(lst_, num_a, num_b)[source]ΒΆ
deep_copy_func(l_n)[source]ΒΆ
index(lev_graph, node)[source]ΒΆ
swap_node_attributes(node_a, node_b)[source]ΒΆ
swap_node_attr_simple(node_a, node_b) None[source]ΒΆ
swap_nodes(node_a, node_b)[source]ΒΆ
get_VRz_gates()[source]ΒΆ
get_node_sensitivity_cost(node)[source]ΒΆ
get_edge_sensitivity(node_a, node_b)[source]ΒΆ
is_irnode(node)[source]ΒΆ
is_Inode(node)[source]ΒΆ
__str__() str[source]ΒΆ

Returns a short summary of the graph.

ReturnsΒΆ
infostring

Graph information including the graph name (if any), graph type, and the number of nodes and edges.

ExamplesΒΆ
>>> G = nx.Graph(name="foo")
>>> str(G)
"Graph named 'foo' with 0 nodes and 0 edges"
>>> G = nx.path_graph(3)
>>> str(G)
'Graph with 3 nodes and 2 edges'
set_circuit(circuit: mqt.qudits.circuit.QuantumCircuit) None[source]ΒΆ
set_qudits_index(index: int) None[source]ΒΆ
Package ContentsΒΆ
class NAryTree[source]ΒΆ
property total_sizeΒΆ
add(new_key, rotation, U_of_level, graph_current, current_cost, current_decomp_cost, max_cost, pi_pulses, parent_key=None) None[source]ΒΆ
find_node(node, key)[source]ΒΆ
depth(key)[source]ΒΆ
max_depth(node)[source]ΒΆ
size_refresh(node)[source]ΒΆ
found_checker(node)[source]ΒΆ
min_cost_decomp(node)[source]ΒΆ
retrieve_decomposition(node)[source]ΒΆ
is_empty()[source]ΒΆ
print_tree(node, str_aux)[source]ΒΆ
__str__() str[source]ΒΆ

Return str(self).

class Node(key, rotation, U_of_level, graph_current, current_cost, current_decomp_cost, max_cost, pi_pulses, parent_key, children=None)[source]ΒΆ
add(new_key, rotation, U_of_level, graph_current, current_cost, current_decomp_cost, max_cost, pi_pulses) None[source]ΒΆ
__str__() str[source]ΒΆ

Return str(self).

class LevelGraph(edges, nodes, nodes_physical_mapping=None, initialization_nodes=None, qudit_index=None, og_circuit=None)[source]ΒΆ

Bases: networkx.Graph

Base class for undirected graphs.

A Graph stores nodes and edges with optional data, or attributes.

Graphs hold undirected edges. Self loops are allowed but multiple (parallel) edges are not.

Nodes can be arbitrary (hashable) Python objects with optional key/value attributes, except that None is not allowed as a node.

Edges are represented as links between nodes with optional key/value attributes.

ParametersΒΆ
incoming_graph_datainput graph (optional, default: None)

Data to initialize graph. If None (default) an empty graph is created. The data can be any format that is supported by the to_networkx_graph() function, currently including edge list, dict of dicts, dict of lists, NetworkX graph, 2D NumPy array, SciPy sparse matrix, or PyGraphviz graph.

attrkeyword arguments, optional (default= no attributes)

Attributes to add to graph as key=value pairs.

See AlsoΒΆ

DiGraph MultiGraph MultiDiGraph

ExamplesΒΆ

Create an empty graph structure (a β€œnull graph”) with no nodes and no edges.

>>> G = nx.Graph()

G can be grown in several ways.

Nodes:

Add one node at a time:

>>> G.add_node(1)

Add the nodes from any container (a list, dict, set or even the lines from a file or the nodes from another graph).

>>> G.add_nodes_from([2, 3])
>>> G.add_nodes_from(range(100, 110))
>>> H = nx.path_graph(10)
>>> G.add_nodes_from(H)

In addition to strings and integers any hashable Python object (except None) can represent a node, e.g. a customized node object, or even another Graph.

>>> G.add_node(H)

Edges:

G can also be grown by adding edges.

Add one edge,

>>> G.add_edge(1, 2)

a list of edges,

>>> G.add_edges_from([(1, 2), (1, 3)])

or a collection of edges,

>>> G.add_edges_from(H.edges)

If some edges connect nodes not yet in the graph, the nodes are added automatically. There are no errors when adding nodes or edges that already exist.

Attributes:

Each graph, node, and edge can hold key/value attribute pairs in an associated attribute dictionary (the keys must be hashable). By default these are empty, but can be added or changed using add_edge, add_node or direct manipulation of the attribute dictionaries named graph, node and edge respectively.

>>> G = nx.Graph(day="Friday")
>>> G.graph
{'day': 'Friday'}

Add node attributes using add_node(), add_nodes_from() or G.nodes

>>> G.add_node(1, time="5pm")
>>> G.add_nodes_from([3], time="2pm")
>>> G.nodes[1]
{'time': '5pm'}
>>> G.nodes[1]["room"] = 714  # node must exist already to use G.nodes
>>> del G.nodes[1]["room"]  # remove attribute
>>> list(G.nodes(data=True))
[(1, {'time': '5pm'}), (3, {'time': '2pm'})]

Add edge attributes using add_edge(), add_edges_from(), subscript notation, or G.edges.

>>> G.add_edge(1, 2, weight=4.7)
>>> G.add_edges_from([(3, 4), (4, 5)], color="red")
>>> G.add_edges_from([(1, 2, {"color": "blue"}), (2, 3, {"weight": 8})])
>>> G[1][2]["weight"] = 4.7
>>> G.edges[1, 2]["weight"] = 4

Warning: we protect the graph data structure by making G.edges a read-only dict-like structure. However, you can assign to attributes in e.g. G.edges[1, 2]. Thus, use 2 sets of brackets to add/change data attributes: G.edges[1, 2][β€˜weight’] = 4 (For multigraphs: MG.edges[u, v, key][name] = value).

Shortcuts:

Many common graph features allow python syntax to speed reporting.

>>> 1 in G  # check if node in graph
True
>>> [n for n in G if n < 3]  # iterate through nodes
[1, 2]
>>> len(G)  # number of nodes in graph
5

Often the best way to traverse all edges of a graph is via the neighbors. The neighbors are reported as an adjacency-dict G.adj or G.adjacency()

>>> for n, nbrsdict in G.adjacency():
...     for nbr, eattr in nbrsdict.items():
...         if "weight" in eattr:
...             # Do something useful with the edges
...             pass

But the edges() method is often more convenient:

>>> for u, v, weight in G.edges.data("weight"):
...     if weight is not None:
...         # Do something useful with the edges
...         pass

Reporting:

Simple graph information is obtained using object-attributes and methods. Reporting typically provides views instead of containers to reduce memory usage. The views update as the graph is updated similarly to dict-views. The objects nodes, edges and adj provide access to data attributes via lookup (e.g. nodes[n], edges[u, v], adj[u][v]) and iteration (e.g. nodes.items(), nodes.data(β€˜color’), nodes.data(β€˜color’, default=’blue’) and similarly for edges) Views exist for nodes, edges, neighbors()/adj and degree.

For details on these and other miscellaneous methods, see below.

Subclasses (Advanced):

The Graph class uses a dict-of-dict-of-dict data structure. The outer dict (node_dict) holds adjacency information keyed by node. The next dict (adjlist_dict) represents the adjacency information and holds edge data keyed by neighbor. The inner dict (edge_attr_dict) represents the edge data and holds edge attribute values keyed by attribute names.

Each of these three dicts can be replaced in a subclass by a user defined dict-like object. In general, the dict-like features should be maintained but extra features can be added. To replace one of the dicts create a new graph class by changing the class(!) variable holding the factory for that dict-like structure.

node_dict_factoryfunction, (default: dict)

Factory function to be used to create the dict containing node attributes, keyed by node id. It should require no arguments and return a dict-like object

node_attr_dict_factory: function, (default: dict)

Factory function to be used to create the node attribute dict which holds attribute values keyed by attribute name. It should require no arguments and return a dict-like object

adjlist_outer_dict_factoryfunction, (default: dict)

Factory function to be used to create the outer-most dict in the data structure that holds adjacency info keyed by node. It should require no arguments and return a dict-like object.

adjlist_inner_dict_factoryfunction, (default: dict)

Factory function to be used to create the adjacency list dict which holds edge data keyed by neighbor. It should require no arguments and return a dict-like object

edge_attr_dict_factoryfunction, (default: dict)

Factory function to be used to create the edge attribute dict which holds attribute values keyed by attribute name. It should require no arguments and return a dict-like object.

graph_attr_dict_factoryfunction, (default: dict)

Factory function to be used to create the graph attribute dict which holds attribute values keyed by attribute name. It should require no arguments and return a dict-like object.

Typically, if your extension doesn’t impact the data structure all methods will inherit without issue except: to_directed/to_undirected. By default these methods create a DiGraph/Graph class and you probably want them to create your extension of a DiGraph/Graph. To facilitate this we define two class variables that you can set in your subclass.

to_directed_classcallable, (default: DiGraph or MultiDiGraph)

Class to create a new graph structure in the to_directed method. If None, a NetworkX class (DiGraph or MultiDiGraph) is used.

to_undirected_classcallable, (default: Graph or MultiGraph)

Class to create a new graph structure in the to_undirected method. If None, a NetworkX class (Graph or MultiGraph) is used.

Subclassing Example

Create a low memory graph class that effectively disallows edge attributes by using a single attribute dict for all edges. This reduces the memory used, but you lose edge attributes.

>>> class ThinGraph(nx.Graph):
...     all_edge_dict = {"weight": 1}
...
...     def single_edge_dict(self):
...         return self.all_edge_dict
...
...     edge_attr_dict_factory = single_edge_dict
>>> G = ThinGraph()
>>> G.add_edge(2, 1)
>>> G[2][1]
{'weight': 1}
>>> G.add_edge(2, 2)
>>> G[2][1] is G[2][2]
True
property log_phy_mapΒΆ
phase_storing_setup() None[source]ΒΆ
distance_nodes(source, target)[source]ΒΆ
distance_nodes_pi_pulses_fixed_ancilla(source, target)[source]ΒΆ
logic_physical_map(physical_nodes) None[source]ΒΆ
define__states(initialization_nodes, inreach_nodes) None[source]ΒΆ
update_list(lst_, num_a, num_b)[source]ΒΆ
deep_copy_func(l_n)[source]ΒΆ
index(lev_graph, node)[source]ΒΆ
swap_node_attributes(node_a, node_b)[source]ΒΆ
swap_node_attr_simple(node_a, node_b) None[source]ΒΆ
swap_nodes(node_a, node_b)[source]ΒΆ
get_VRz_gates()[source]ΒΆ
get_node_sensitivity_cost(node)[source]ΒΆ
get_edge_sensitivity(node_a, node_b)[source]ΒΆ
is_irnode(node)[source]ΒΆ
is_Inode(node)[source]ΒΆ
__str__() str[source]ΒΆ

Returns a short summary of the graph.

ReturnsΒΆ
infostring

Graph information including the graph name (if any), graph type, and the number of nodes and edges.

ExamplesΒΆ
>>> G = nx.Graph(name="foo")
>>> str(G)
"Graph named 'foo' with 0 nodes and 0 edges"
>>> G = nx.path_graph(3)
>>> str(G)
'Graph with 3 nodes and 2 edges'
set_circuit(circuit: mqt.qudits.circuit.QuantumCircuit) None[source]ΒΆ
set_qudits_index(index: int) None[source]ΒΆ

mqt.qudits.exceptionsΒΆ

Exceptions module.

SubmodulesΒΆ
mqt.qudits.exceptions.backenderrorΒΆ
Module ContentsΒΆ
exception BackendNotFoundError(message: str)[source]ΒΆ

Bases: Exception

Common base class for all non-exit exceptions.

mqt.qudits.exceptions.circuiterrorΒΆ
Module ContentsΒΆ
exception CircuitError(message: str)[source]ΒΆ

Bases: Exception

Common base class for all non-exit exceptions.

mqt.qudits.exceptions.compilerexceptionΒΆ
Module ContentsΒΆ
exception NodeNotFoundException(value)[source]ΒΆ

Bases: Exception

Common base class for all non-exit exceptions.

__str__() str[source]ΒΆ

Return str(self).

exception SequenceFoundException(node_key: int = -1)[source]ΒΆ

Bases: Exception

Common base class for all non-exit exceptions.

__str__() str[source]ΒΆ

Return str(self).

exception RoutingException[source]ΒΆ

Bases: Exception

Common base class for all non-exit exceptions.

__str__() str[source]ΒΆ

Return str(self).

exception FidelityReachException(message: str = '')[source]ΒΆ

Bases: Exception

Common base class for all non-exit exceptions.

mqt.qudits.exceptions.joberrorΒΆ
Module ContentsΒΆ
exception JobError(message: str)[source]ΒΆ

Bases: Exception

Common base class for all non-exit exceptions.

class JobTimeoutError(message: str)[source]ΒΆ
Package ContentsΒΆ
exception BackendNotFoundError(message: str)[source]ΒΆ

Bases: Exception

Common base class for all non-exit exceptions.

exception CircuitError(message: str)[source]ΒΆ

Bases: Exception

Common base class for all non-exit exceptions.

exception FidelityReachException(message: str = '')[source]ΒΆ

Bases: Exception

Common base class for all non-exit exceptions.

exception NodeNotFoundException(value)[source]ΒΆ

Bases: Exception

Common base class for all non-exit exceptions.

__str__() str[source]ΒΆ

Return str(self).

exception RoutingException[source]ΒΆ

Bases: Exception

Common base class for all non-exit exceptions.

__str__() str[source]ΒΆ

Return str(self).

exception SequenceFoundException(node_key: int = -1)[source]ΒΆ

Bases: Exception

Common base class for all non-exit exceptions.

__str__() str[source]ΒΆ

Return str(self).

exception JobError(message: str)[source]ΒΆ

Bases: Exception

Common base class for all non-exit exceptions.

class JobTimeoutError(message: str)[source]ΒΆ

mqt.qudits.quantum_circuitΒΆ

Qudit Quantum Circuit Module.

SubpackagesΒΆ
mqt.qudits.quantum_circuit.componentsΒΆ
SubpackagesΒΆ
mqt.qudits.quantum_circuit.components.extensionsΒΆ
SubmodulesΒΆ
mqt.qudits.quantum_circuit.components.extensions.controlsΒΆ
Module ContentsΒΆ
class ControlData[source]ΒΆ
indices: list[int] | intΒΆ
ctrl_states: list[int] | intΒΆ
mqt.qudits.quantum_circuit.components.extensions.gate_typesΒΆ
Module ContentsΒΆ
class GateTypes(*args, **kwds)[source]ΒΆ

Bases: enum.Enum

Enumeration for job status.

SINGLE = 'Single Qudit Gate'ΒΆ
TWO = 'Two Qudit Gate'ΒΆ
MULTI = 'Multi Qudit Gate'ΒΆ
CORE_GATE_TYPES = ()ΒΆ
mqt.qudits.quantum_circuit.components.extensions.matrix_factoryΒΆ
Module ContentsΒΆ
class MatrixFactory(gate, identities_flag)[source]ΒΆ
generate_matrix()[source]ΒΆ
classmethod apply_identites_and_controls(matrix, qudits_applied, dimensions, ref_lines, controls=None, controls_levels=None)[source]ΒΆ
classmethod wrap_in_identities(matrix, indices, sizes)[source]ΒΆ
from_dirac_to_basis(vec, d)[source]ΒΆ
calculate_q0_q1(lev, dim)[source]ΒΆ
insert_at(big_arr, pos, to_insert_arr)[source]ΒΆ

Quite a forceful way of embedding a parameters into big_arr.

SubmodulesΒΆ
mqt.qudits.quantum_circuit.components.classic_registerΒΆ
Module ContentsΒΆ
class ClassicRegister(name, size)[source]ΒΆ
classmethod from_map(sitemap: dict) list[ClassicRegister][source]ΒΆ
__qasm__()[source]ΒΆ
__getitem__(key)[source]ΒΆ
mqt.qudits.quantum_circuit.components.quantum_registerΒΆ
Module ContentsΒΆ
class QuantumRegister(name, size, dims=None)[source]ΒΆ
classmethod from_map(sitemap: dict) list[QuantumRegister][source]ΒΆ
__qasm__()[source]ΒΆ
__getitem__(key)[source]ΒΆ
Package ContentsΒΆ
class ClassicRegister(name, size)[source]ΒΆ
classmethod from_map(sitemap: dict) list[ClassicRegister][source]ΒΆ
__qasm__()[source]ΒΆ
__getitem__(key)[source]ΒΆ
class QuantumRegister(name, size, dims=None)[source]ΒΆ
classmethod from_map(sitemap: dict) list[QuantumRegister][source]ΒΆ
__qasm__()[source]ΒΆ
__getitem__(key)[source]ΒΆ
mqt.qudits.quantum_circuit.gatesΒΆ

Instructions module.

SubmodulesΒΆ
mqt.qudits.quantum_circuit.gates.csumΒΆ
Module ContentsΒΆ
class CSum(circuit: QuantumCircuit, name: str, target_qudits: list[int] | int, dimensions: list[int] | int, controls: ControlData | None = None)[source]ΒΆ

Bases: mqt.qudits.quantum_circuit.gate.Gate

Unitary gate_matrix.

__array__() ndarray[source]ΒΆ
validate_parameter(parameter=None) bool[source]ΒΆ
__str__() str[source]ΒΆ

Return str(self).

mqt.qudits.quantum_circuit.gates.custom_multiΒΆ
Module ContentsΒΆ
class CustomMulti(circuit: QuantumCircuit, name: str, target_qudits: list[int] | int, parameters: ndarray, dimensions: list[int] | int, controls: ControlData | None = None)[source]ΒΆ

Bases: mqt.qudits.quantum_circuit.gate.Gate

Multi body custom gate

__array__() ndarray[source]ΒΆ
validate_parameter(parameter=None) bool[source]ΒΆ
__str__() str[source]ΒΆ

Return str(self).

mqt.qudits.quantum_circuit.gates.custom_oneΒΆ
Module ContentsΒΆ
class CustomOne(circuit: QuantumCircuit, name: str, target_qudits: list[int] | int, parameters: ndarray, dimensions: list[int] | int, controls: ControlData | None = None)[source]ΒΆ

Bases: mqt.qudits.quantum_circuit.gate.Gate

One body custom gate

__array__() ndarray[source]ΒΆ
validate_parameter(parameter=None) bool[source]ΒΆ
__str__() str[source]ΒΆ

Return str(self).

mqt.qudits.quantum_circuit.gates.custom_twoΒΆ
Module ContentsΒΆ
class CustomTwo(circuit: QuantumCircuit, name: str, target_qudits: list[int] | int, parameters: ndarray, dimensions: list[int] | int, controls: ControlData | None = None)[source]ΒΆ

Bases: mqt.qudits.quantum_circuit.gate.Gate

Two body custom gate

__array__() ndarray[source]ΒΆ
validate_parameter(parameter=None) bool[source]ΒΆ
__str__() str[source]ΒΆ

Return str(self).

mqt.qudits.quantum_circuit.gates.cxΒΆ
Module ContentsΒΆ
class CEx(circuit: QuantumCircuit, name: str, target_qudits: list[int] | int, parameters: list | None, dimensions: list[int] | int, controls: ControlData | None = None)[source]ΒΆ

Bases: mqt.qudits.quantum_circuit.gate.Gate

Unitary gate_matrix.

__array__() ndarray[source]ΒΆ
validate_parameter(parameter) bool[source]ΒΆ
__str__() str[source]ΒΆ

Return str(self).

mqt.qudits.quantum_circuit.gates.gellmannΒΆ
Module ContentsΒΆ
class GellMann(circuit: QuantumCircuit, name: str, target_qudits: list[int] | int, parameters: list, dimensions: list[int] | int, controls: ControlData | None = None)[source]ΒΆ

Bases: mqt.qudits.quantum_circuit.gate.Gate

Gate used as generator for Givens rotations.

__array__() ndarray[source]ΒΆ
validate_parameter(parameter) bool[source]ΒΆ
__str__() str[source]ΒΆ

Return str(self).

mqt.qudits.quantum_circuit.gates.hΒΆ
Module ContentsΒΆ
class H(circuit: QuantumCircuit, name: str, target_qudits: list[int] | int, dimensions: list[int] | int, controls: ControlData | None = None)[source]ΒΆ

Bases: mqt.qudits.quantum_circuit.gate.Gate

Unitary gate_matrix.

__array__() ndarray[source]ΒΆ
validate_parameter(parameter=None) bool[source]ΒΆ
__str__() str[source]ΒΆ

Return str(self).

mqt.qudits.quantum_circuit.gates.lsΒΆ
Module ContentsΒΆ
class LS(circuit: QuantumCircuit, name: str, target_qudits: list[int] | int, parameters: list | None, dimensions: list[int] | int, controls: ControlData | None = None)[source]ΒΆ

Bases: mqt.qudits.quantum_circuit.gate.Gate

Unitary gate_matrix.

__array__() ndarray[source]ΒΆ
validate_parameter(parameter) bool[source]ΒΆ
__str__() str[source]ΒΆ

Return str(self).

mqt.qudits.quantum_circuit.gates.msΒΆ
Module ContentsΒΆ
class MS(circuit: QuantumCircuit, name: str, target_qudits: list[int] | int, parameters: list | None, dimensions: list[int] | int, controls: ControlData | None = None)[source]ΒΆ

Bases: mqt.qudits.quantum_circuit.gate.Gate

Unitary gate_matrix.

__array__() ndarray[source]ΒΆ
validate_parameter(parameter) bool[source]ΒΆ
__str__() str[source]ΒΆ

Return str(self).

mqt.qudits.quantum_circuit.gates.permΒΆ
Module ContentsΒΆ
class Perm(circuit: QuantumCircuit, name: str, target_qudits: list[int] | int, parameters: list, dimensions: list[int] | int, controls: ControlData | None = None)[source]ΒΆ

Bases: mqt.qudits.quantum_circuit.gate.Gate

Unitary gate_matrix.

__array__() ndarray[source]ΒΆ
validate_parameter(parameter) bool[source]ΒΆ

Verify that the input is a list of indices

__str__() str[source]ΒΆ

Return str(self).

mqt.qudits.quantum_circuit.gates.rΒΆ
Module ContentsΒΆ
class R(circuit: QuantumCircuit, name: str, target_qudits: list[int] | int, parameters: list | None, dimensions: list[int] | int, controls: ControlData | None = None)[source]ΒΆ

Bases: mqt.qudits.quantum_circuit.gate.Gate

Unitary gate_matrix.

property costΒΆ
__array__() ndarray[source]ΒΆ
levels_setter(la, lb)[source]ΒΆ
validate_parameter(parameter) bool[source]ΒΆ
__str__() str[source]ΒΆ

Return str(self).

mqt.qudits.quantum_circuit.gates.randuΒΆ
Module ContentsΒΆ
class RandU(circuit: QuantumCircuit, name: str, target_qudits: list[int] | int, dimensions: list[int] | int, controls: ControlData | None = None)[source]ΒΆ

Bases: mqt.qudits.quantum_circuit.gate.Gate

Unitary gate_matrix.

__array__() ndarray[source]ΒΆ
validate_parameter() bool[source]ΒΆ
__str__() str[source]ΒΆ

Return str(self).

mqt.qudits.quantum_circuit.gates.rhΒΆ
Module ContentsΒΆ
class Rh(circuit: QuantumCircuit, name: str, target_qudits: list[int] | int, parameters: list | None, dimensions: list[int] | int, controls: ControlData | None = None)[source]ΒΆ

Bases: mqt.qudits.quantum_circuit.gate.Gate

SU2 Hadamard

__array__() ndarray[source]ΒΆ
levels_setter(la, lb)[source]ΒΆ
validate_parameter(parameter) bool[source]ΒΆ
__str__() str[source]ΒΆ

Return str(self).

mqt.qudits.quantum_circuit.gates.rzΒΆ
Module ContentsΒΆ
class Rz(circuit: QuantumCircuit, name: str, target_qudits: list[int] | int, parameters: list | None, dimensions: list[int] | int, controls: ControlData | None = None)[source]ΒΆ

Bases: mqt.qudits.quantum_circuit.gate.Gate

Unitary gate_matrix.

property costΒΆ
__array__() ndarray[source]ΒΆ
levels_setter(la, lb)[source]ΒΆ
validate_parameter(parameter) bool[source]ΒΆ
__str__() str[source]ΒΆ

Return str(self).

mqt.qudits.quantum_circuit.gates.sΒΆ
Module ContentsΒΆ
class S(circuit: QuantumCircuit, name: str, target_qudits: list[int] | int, dimensions: list[int] | int, controls: ControlData | None = None)[source]ΒΆ

Bases: mqt.qudits.quantum_circuit.gate.Gate

Unitary gate_matrix.

__array__() ndarray[source]ΒΆ
validate_parameter(parameter=None) bool[source]ΒΆ
__str__() str[source]ΒΆ

Return str(self).

mqt.qudits.quantum_circuit.gates.virt_rzΒΆ
Module ContentsΒΆ
class VirtRz(circuit: QuantumCircuit, name: str, target_qudits: list[int] | int, parameters: list | None, dimensions: list[int] | int, controls: ControlData | None = None)[source]ΒΆ

Bases: mqt.qudits.quantum_circuit.gate.Gate

Unitary gate_matrix.

property costΒΆ
__array__() ndarray[source]ΒΆ
validate_parameter(parameter) bool[source]ΒΆ
__str__() str[source]ΒΆ

Return str(self).

mqt.qudits.quantum_circuit.gates.xΒΆ
Module ContentsΒΆ
class X(circuit: QuantumCircuit, name: str, target_qudits: list[int] | int, dimensions: list[int] | int, controls: ControlData | None = None)[source]ΒΆ

Bases: mqt.qudits.quantum_circuit.gate.Gate

Unitary gate_matrix.

__array__() ndarray[source]ΒΆ
validate_parameter(parameter=None) bool[source]ΒΆ
__str__() str[source]ΒΆ

Return str(self).

mqt.qudits.quantum_circuit.gates.zΒΆ
Module ContentsΒΆ
class Z(circuit: QuantumCircuit, name: str, target_qudits: list[int] | int, dimensions: list[int] | int, controls: ControlData | None = None)[source]ΒΆ

Bases: mqt.qudits.quantum_circuit.gate.Gate

Unitary gate_matrix.

__array__() ndarray[source]ΒΆ
validate_parameter(parameter=None) bool[source]ΒΆ
__str__() str[source]ΒΆ

Return str(self).

Package ContentsΒΆ
class ControlData[source]ΒΆ
indices: list[int] | intΒΆ
ctrl_states: list[int] | intΒΆ
class GateTypes(*args, **kwds)[source]ΒΆ

Bases: enum.Enum

Enumeration for job status.

SINGLE = 'Single Qudit Gate'ΒΆ
TWO = 'Two Qudit Gate'ΒΆ
MULTI = 'Multi Qudit Gate'ΒΆ
class CSum(circuit: QuantumCircuit, name: str, target_qudits: list[int] | int, dimensions: list[int] | int, controls: ControlData | None = None)[source]ΒΆ

Bases: mqt.qudits.quantum_circuit.gate.Gate

Unitary gate_matrix.

__array__() ndarray[source]ΒΆ
validate_parameter(parameter=None) bool[source]ΒΆ
__str__() str[source]ΒΆ

Return str(self).

class CustomMulti(circuit: QuantumCircuit, name: str, target_qudits: list[int] | int, parameters: ndarray, dimensions: list[int] | int, controls: ControlData | None = None)[source]ΒΆ

Bases: mqt.qudits.quantum_circuit.gate.Gate

Multi body custom gate

__array__() ndarray[source]ΒΆ
validate_parameter(parameter=None) bool[source]ΒΆ
__str__() str[source]ΒΆ

Return str(self).

class CustomOne(circuit: QuantumCircuit, name: str, target_qudits: list[int] | int, parameters: ndarray, dimensions: list[int] | int, controls: ControlData | None = None)[source]ΒΆ

Bases: mqt.qudits.quantum_circuit.gate.Gate

One body custom gate

__array__() ndarray[source]ΒΆ
validate_parameter(parameter=None) bool[source]ΒΆ
__str__() str[source]ΒΆ

Return str(self).

class CustomTwo(circuit: QuantumCircuit, name: str, target_qudits: list[int] | int, parameters: ndarray, dimensions: list[int] | int, controls: ControlData | None = None)[source]ΒΆ

Bases: mqt.qudits.quantum_circuit.gate.Gate

Two body custom gate

__array__() ndarray[source]ΒΆ
validate_parameter(parameter=None) bool[source]ΒΆ
__str__() str[source]ΒΆ

Return str(self).

class CEx(circuit: QuantumCircuit, name: str, target_qudits: list[int] | int, parameters: list | None, dimensions: list[int] | int, controls: ControlData | None = None)[source]ΒΆ

Bases: mqt.qudits.quantum_circuit.gate.Gate

Unitary gate_matrix.

__array__() ndarray[source]ΒΆ
validate_parameter(parameter) bool[source]ΒΆ
__str__() str[source]ΒΆ

Return str(self).

class GellMann(circuit: QuantumCircuit, name: str, target_qudits: list[int] | int, parameters: list, dimensions: list[int] | int, controls: ControlData | None = None)[source]ΒΆ

Bases: mqt.qudits.quantum_circuit.gate.Gate

Gate used as generator for Givens rotations.

__array__() ndarray[source]ΒΆ
validate_parameter(parameter) bool[source]ΒΆ
__str__() str[source]ΒΆ

Return str(self).

class H(circuit: QuantumCircuit, name: str, target_qudits: list[int] | int, dimensions: list[int] | int, controls: ControlData | None = None)[source]ΒΆ

Bases: mqt.qudits.quantum_circuit.gate.Gate

Unitary gate_matrix.

__array__() ndarray[source]ΒΆ
validate_parameter(parameter=None) bool[source]ΒΆ
__str__() str[source]ΒΆ

Return str(self).

class LS(circuit: QuantumCircuit, name: str, target_qudits: list[int] | int, parameters: list | None, dimensions: list[int] | int, controls: ControlData | None = None)[source]ΒΆ

Bases: mqt.qudits.quantum_circuit.gate.Gate

Unitary gate_matrix.

__array__() ndarray[source]ΒΆ
validate_parameter(parameter) bool[source]ΒΆ
__str__() str[source]ΒΆ

Return str(self).

class MS(circuit: QuantumCircuit, name: str, target_qudits: list[int] | int, parameters: list | None, dimensions: list[int] | int, controls: ControlData | None = None)[source]ΒΆ

Bases: mqt.qudits.quantum_circuit.gate.Gate

Unitary gate_matrix.

__array__() ndarray[source]ΒΆ
validate_parameter(parameter) bool[source]ΒΆ
__str__() str[source]ΒΆ

Return str(self).

class Perm(circuit: QuantumCircuit, name: str, target_qudits: list[int] | int, parameters: list, dimensions: list[int] | int, controls: ControlData | None = None)[source]ΒΆ

Bases: mqt.qudits.quantum_circuit.gate.Gate

Unitary gate_matrix.

__array__() ndarray[source]ΒΆ
validate_parameter(parameter) bool[source]ΒΆ

Verify that the input is a list of indices

__str__() str[source]ΒΆ

Return str(self).

class R(circuit: QuantumCircuit, name: str, target_qudits: list[int] | int, parameters: list | None, dimensions: list[int] | int, controls: ControlData | None = None)[source]ΒΆ

Bases: mqt.qudits.quantum_circuit.gate.Gate

Unitary gate_matrix.

property costΒΆ
__array__() ndarray[source]ΒΆ
levels_setter(la, lb)[source]ΒΆ
validate_parameter(parameter) bool[source]ΒΆ
__str__() str[source]ΒΆ

Return str(self).

class RandU(circuit: QuantumCircuit, name: str, target_qudits: list[int] | int, dimensions: list[int] | int, controls: ControlData | None = None)[source]ΒΆ

Bases: mqt.qudits.quantum_circuit.gate.Gate

Unitary gate_matrix.

__array__() ndarray[source]ΒΆ
validate_parameter() bool[source]ΒΆ
__str__() str[source]ΒΆ

Return str(self).

class Rh(circuit: QuantumCircuit, name: str, target_qudits: list[int] | int, parameters: list | None, dimensions: list[int] | int, controls: ControlData | None = None)[source]ΒΆ

Bases: mqt.qudits.quantum_circuit.gate.Gate

SU2 Hadamard

__array__() ndarray[source]ΒΆ
levels_setter(la, lb)[source]ΒΆ
validate_parameter(parameter) bool[source]ΒΆ
__str__() str[source]ΒΆ

Return str(self).

class Rz(circuit: QuantumCircuit, name: str, target_qudits: list[int] | int, parameters: list | None, dimensions: list[int] | int, controls: ControlData | None = None)[source]ΒΆ

Bases: mqt.qudits.quantum_circuit.gate.Gate

Unitary gate_matrix.

property costΒΆ
__array__() ndarray[source]ΒΆ
levels_setter(la, lb)[source]ΒΆ
validate_parameter(parameter) bool[source]ΒΆ
__str__() str[source]ΒΆ

Return str(self).

class S(circuit: QuantumCircuit, name: str, target_qudits: list[int] | int, dimensions: list[int] | int, controls: ControlData | None = None)[source]ΒΆ

Bases: mqt.qudits.quantum_circuit.gate.Gate

Unitary gate_matrix.

__array__() ndarray[source]ΒΆ
validate_parameter(parameter=None) bool[source]ΒΆ
__str__() str[source]ΒΆ

Return str(self).

class VirtRz(circuit: QuantumCircuit, name: str, target_qudits: list[int] | int, parameters: list | None, dimensions: list[int] | int, controls: ControlData | None = None)[source]ΒΆ

Bases: mqt.qudits.quantum_circuit.gate.Gate

Unitary gate_matrix.

property costΒΆ
__array__() ndarray[source]ΒΆ
validate_parameter(parameter) bool[source]ΒΆ
__str__() str[source]ΒΆ

Return str(self).

class X(circuit: QuantumCircuit, name: str, target_qudits: list[int] | int, dimensions: list[int] | int, controls: ControlData | None = None)[source]ΒΆ

Bases: mqt.qudits.quantum_circuit.gate.Gate

Unitary gate_matrix.

__array__() ndarray[source]ΒΆ
validate_parameter(parameter=None) bool[source]ΒΆ
__str__() str[source]ΒΆ

Return str(self).

class Z(circuit: QuantumCircuit, name: str, target_qudits: list[int] | int, dimensions: list[int] | int, controls: ControlData | None = None)[source]ΒΆ

Bases: mqt.qudits.quantum_circuit.gate.Gate

Unitary gate_matrix.

__array__() ndarray[source]ΒΆ
validate_parameter(parameter=None) bool[source]ΒΆ
__str__() str[source]ΒΆ

Return str(self).

SubmodulesΒΆ
mqt.qudits.quantum_circuit.circuitΒΆ
Module ContentsΒΆ
is_not_none_or_empty(variable)[source]ΒΆ
add_gate_decorator(func)[source]ΒΆ
class QuantumCircuit(*args)[source]ΒΆ
property num_quditsΒΆ
property dimensionsΒΆ
property gate_set: NoneΒΆ
qasm_to_gate_set_dictΒΆ
classmethod get_qasm_set()[source]ΒΆ
reset() None[source]ΒΆ
copy()[source]ΒΆ
append(qreg: QuantumRegister) None[source]ΒΆ
append_classic(creg: ClassicRegister) None[source]ΒΆ
csum(qudits: list[int])[source]ΒΆ
cu_one(qudits: int, parameters: ndarray, controls: ControlData | None = None)[source]ΒΆ
cu_two(qudits: list[int], parameters: ndarray, controls: ControlData | None = None)[source]ΒΆ
cu_multi(qudits: list[int], parameters: ndarray, controls: ControlData | None = None)[source]ΒΆ
cx(qudits: list[int], parameters: list | None = None)[source]ΒΆ
gellmann(qudit: int, parameters: list | None = None, controls: ControlData | None = None)[source]ΒΆ
h(qudit: int, controls: ControlData | None = None)[source]ΒΆ
rh(qudit: int, parameters: list, controls: ControlData | None = None)[source]ΒΆ
ls(qudits: list[int], parameters: list | None = None)[source]ΒΆ
ms(qudits: list[int], parameters: list | None = None)[source]ΒΆ
pm(qudits: list[int], parameters: list)[source]ΒΆ
r(qudit: int, parameters: list, controls: ControlData | None = None)[source]ΒΆ
randu(qudits: list[int])[source]ΒΆ
rz(qudit: int, parameters: list, controls: ControlData | None = None)[source]ΒΆ
virtrz(qudit: int, parameters: list, controls: ControlData | None = None)[source]ΒΆ
s(qudit: int, controls: ControlData | None = None)[source]ΒΆ
x(qudit: int, controls: ControlData | None = None)[source]ΒΆ
z(qudit: int, controls: ControlData | None = None)[source]ΒΆ
replace_gate(gate_index: int, sequence: list[Gate]) None[source]ΒΆ
set_instructions(sequence: list[Gate])[source]ΒΆ
from_qasm(qasm_prog) None[source]ΒΆ

Create a circuit from qasm text

to_qasm()[source]ΒΆ
save_to_file(file_name: str, file_path: str = '.') str[source]ΒΆ

Save qasm into a file with the specified name and path.

Parameters:
  • text (str) – The text to be saved into the file.

  • file_name (str) – The name of the file.

  • file_path (str, optional) – The path where the file will be saved. Defaults to β€œ.” (current directory).

Returns:

The full path of the saved file.

Return type:

str

load_from_file(file_path: str) None[source]ΒΆ

Load text from a file.

Parameters:

file_path (str) – The path of the file to load.

Returns:

The text loaded from the file.

Return type:

str

draw() None[source]ΒΆ
mqt.qudits.quantum_circuit.gateΒΆ
Module ContentsΒΆ
class Instruction(name: str)[source]ΒΆ

Bases: abc.ABC

Helper class that provides a standard way to create an ABC using inheritance.

class Gate(circuit: QuantumCircuit, name: str, gate_type: enum, target_qudits: list[int] | int, dimensions: list[int] | int, params: list | ndarray | None = None, control_set=None, label: str | None = None, duration=None, unit='dt')[source]ΒΆ

Bases: Instruction

Unitary gate_matrix.

property reference_linesΒΆ
property get_control_linesΒΆ
property control_infoΒΆ
abstract __array__() ndarray[source]ΒΆ
dag()[source]ΒΆ
to_matrix(identities=0) ndarray[source]ΒΆ

Return a np.ndarray for the gate_matrix unitary parameters.

Returns:

if the Gate subclass has a parameters definition.

Return type:

np.ndarray

Raises:

CircuitError – If a Gate subclass does not implement this method an exception will be raised when this base class method is called.

control(indices: list[int] | int, ctrl_states: list[int] | int)[source]ΒΆ
abstract validate_parameter(parameter)[source]ΒΆ
__qasm__() str[source]ΒΆ

Generate QASM for Gate export

abstract __str__() str[source]ΒΆ

Return str(self).

check_long_range()[source]ΒΆ
set_gate_type_single() None[source]ΒΆ
set_gate_type_two() None[source]ΒΆ
set_gate_type_multi() None[source]ΒΆ
return_custom_data() str[source]ΒΆ
mqt.qudits.quantum_circuit.qasmΒΆ
Module ContentsΒΆ
class QASM[source]ΒΆ

Class that manages the parsing of QASM programs

parse_nonspecial_lines(line, rgxs, in_comment_flag)[source]ΒΆ
parse_qreg(line, rgxs, sitemap) bool[source]ΒΆ
parse_creg(line, rgxs, sitemap_classic) bool[source]ΒΆ
safe_eval_math_expression(expression)[source]ΒΆ
parse_gate(line, rgxs, sitemap, gates) bool[source]ΒΆ
parse_ignore(line, rgxs, warned) bool[source]ΒΆ
parse_ditqasm2_str(contents)[source]ΒΆ

Parse the string contents of an OpenQASM 2.0 file. This parser only supports basic gate_matrix definitions, and is not guaranteed to check the full openqasm grammar.

parse_ditqasm2_file(fname)[source]ΒΆ

Parse an OpenQASM 2.0 file.

Package ContentsΒΆ
class QuantumCircuit(*args)[source]ΒΆ
property num_quditsΒΆ
property dimensionsΒΆ
property gate_set: NoneΒΆ
qasm_to_gate_set_dictΒΆ
classmethod get_qasm_set()[source]ΒΆ
reset() None[source]ΒΆ
copy()[source]ΒΆ
append(qreg: QuantumRegister) None[source]ΒΆ
append_classic(creg: ClassicRegister) None[source]ΒΆ
csum(qudits: list[int])[source]ΒΆ
cu_one(qudits: int, parameters: ndarray, controls: ControlData | None = None)[source]ΒΆ
cu_two(qudits: list[int], parameters: ndarray, controls: ControlData | None = None)[source]ΒΆ
cu_multi(qudits: list[int], parameters: ndarray, controls: ControlData | None = None)[source]ΒΆ
cx(qudits: list[int], parameters: list | None = None)[source]ΒΆ
gellmann(qudit: int, parameters: list | None = None, controls: ControlData | None = None)[source]ΒΆ
h(qudit: int, controls: ControlData | None = None)[source]ΒΆ
rh(qudit: int, parameters: list, controls: ControlData | None = None)[source]ΒΆ
ls(qudits: list[int], parameters: list | None = None)[source]ΒΆ
ms(qudits: list[int], parameters: list | None = None)[source]ΒΆ
pm(qudits: list[int], parameters: list)[source]ΒΆ
r(qudit: int, parameters: list, controls: ControlData | None = None)[source]ΒΆ
randu(qudits: list[int])[source]ΒΆ
rz(qudit: int, parameters: list, controls: ControlData | None = None)[source]ΒΆ
virtrz(qudit: int, parameters: list, controls: ControlData | None = None)[source]ΒΆ
s(qudit: int, controls: ControlData | None = None)[source]ΒΆ
x(qudit: int, controls: ControlData | None = None)[source]ΒΆ
z(qudit: int, controls: ControlData | None = None)[source]ΒΆ
replace_gate(gate_index: int, sequence: list[Gate]) None[source]ΒΆ
set_instructions(sequence: list[Gate])[source]ΒΆ
from_qasm(qasm_prog) None[source]ΒΆ

Create a circuit from qasm text

to_qasm()[source]ΒΆ
save_to_file(file_name: str, file_path: str = '.') str[source]ΒΆ

Save qasm into a file with the specified name and path.

Parameters:
  • text (str) – The text to be saved into the file.

  • file_name (str) – The name of the file.

  • file_path (str, optional) – The path where the file will be saved. Defaults to β€œ.” (current directory).

Returns:

The full path of the saved file.

Return type:

str

load_from_file(file_path: str) None[source]ΒΆ

Load text from a file.

Parameters:

file_path (str) – The path of the file to load.

Returns:

The text loaded from the file.

Return type:

str

draw() None[source]ΒΆ
class QuantumRegister(name, size, dims=None)[source]ΒΆ
classmethod from_map(sitemap: dict) list[QuantumRegister][source]ΒΆ
__qasm__()[source]ΒΆ
__getitem__(key)[source]ΒΆ
class QASM[source]ΒΆ

Class that manages the parsing of QASM programs

parse_nonspecial_lines(line, rgxs, in_comment_flag)[source]ΒΆ
parse_qreg(line, rgxs, sitemap) bool[source]ΒΆ
parse_creg(line, rgxs, sitemap_classic) bool[source]ΒΆ
safe_eval_math_expression(expression)[source]ΒΆ
parse_gate(line, rgxs, sitemap, gates) bool[source]ΒΆ
parse_ignore(line, rgxs, warned) bool[source]ΒΆ
parse_ditqasm2_str(contents)[source]ΒΆ

Parse the string contents of an OpenQASM 2.0 file. This parser only supports basic gate_matrix definitions, and is not guaranteed to check the full openqasm grammar.

parse_ditqasm2_file(fname)[source]ΒΆ

Parse an OpenQASM 2.0 file.

mqt.qudits.simulationΒΆ

SubpackagesΒΆ
mqt.qudits.simulation.backendsΒΆ
SubpackagesΒΆ
mqt.qudits.simulation.backends.fake_backendsΒΆ
SubmodulesΒΆ
mqt.qudits.simulation.backends.fake_backends.fake_traps2sixΒΆ
Module ContentsΒΆ
class FakeIonTraps2Six(provider: mqt.qudits.simulation.qudit_provider.QuditProvider | None = None, name: str | None = None, description: str | None = None, online_date: datetime | None = None, backend_version: str | None = None, **fields)[source]ΒΆ

Bases: mqt.qudits.simulation.backends.tnsim.TNSim

Helper class that provides a standard way to create an ABC using inheritance.

property version: intΒΆ
property energy_level_graphs: list[LevelGraph, LevelGraph]ΒΆ
mqt.qudits.simulation.backends.fake_backends.fake_traps2threeΒΆ
Module ContentsΒΆ
class FakeIonTraps2Trits(provider: mqt.qudits.simulation.qudit_provider.QuditProvider | None = None, name: str | None = None, description: str | None = None, online_date: datetime | None = None, backend_version: str | None = None, **fields)[source]ΒΆ

Bases: mqt.qudits.simulation.backends.tnsim.TNSim

Helper class that provides a standard way to create an ABC using inheritance.

property version: intΒΆ
property energy_level_graphs: list[LevelGraph, LevelGraph]ΒΆ
Package ContentsΒΆ
class FakeIonTraps2Six(provider: mqt.qudits.simulation.qudit_provider.QuditProvider | None = None, name: str | None = None, description: str | None = None, online_date: datetime | None = None, backend_version: str | None = None, **fields)[source]ΒΆ

Bases: mqt.qudits.simulation.backends.tnsim.TNSim

Helper class that provides a standard way to create an ABC using inheritance.

property version: intΒΆ
property energy_level_graphs: list[LevelGraph, LevelGraph]ΒΆ
class FakeIonTraps2Trits(provider: mqt.qudits.simulation.qudit_provider.QuditProvider | None = None, name: str | None = None, description: str | None = None, online_date: datetime | None = None, backend_version: str | None = None, **fields)[source]ΒΆ

Bases: mqt.qudits.simulation.backends.tnsim.TNSim

Helper class that provides a standard way to create an ABC using inheritance.

property version: intΒΆ
property energy_level_graphs: list[LevelGraph, LevelGraph]ΒΆ
SubmodulesΒΆ
mqt.qudits.simulation.backends.backendv2ΒΆ
Module ContentsΒΆ
class Backend(provider: mqt.qudits.simulation.qudit_provider.QuditProvider | None = None, name: str | None = None, description: str | None = None, online_date: datetime | None = None, backend_version: str | None = None, **fields: Any)[source]ΒΆ

Bases: abc.ABC

Helper class that provides a standard way to create an ABC using inheritance.

property version: intΒΆ
property instructions: list[tuple[Gate, tuple[int]]]ΒΆ
property operations: list[Gate]ΒΆ
property operation_names: list[str]ΒΆ
property num_qudits: intΒΆ
abstract property energy_level_graphs: list[LevelGraph, LevelGraph]ΒΆ
property optionsΒΆ
property providerΒΆ
targetΒΆ
set_options(**fields) None[source]ΒΆ
abstract run(run_input, **options) Job[source]ΒΆ
mqt.qudits.simulation.backends.misimΒΆ
Module ContentsΒΆ
class MISim(**fields)[source]ΒΆ

Bases: mqt.qudits.simulation.backends.backendv2.Backend

Helper class that provides a standard way to create an ABC using inheritance.

run(circuit: QuantumCircuit, **options) Job[source]ΒΆ
execute(circuit: QuantumCircuit, noise_model: NoiseModel | None = None) ndarray[source]ΒΆ
mqt.qudits.simulation.backends.stochastic_simΒΆ
Module ContentsΒΆ
stochastic_simulation(backend: Backend, circuit: QuantumCircuit)[source]ΒΆ
stochastic_execution(args)[source]ΒΆ
stochastic_simulation_misim(backend: Backend, circuit: QuantumCircuit)[source]ΒΆ
stochastic_execution_misim(args)[source]ΒΆ
mqt.qudits.simulation.backends.tnsimΒΆ
Module ContentsΒΆ
class TNSim(**fields)[source]ΒΆ

Bases: mqt.qudits.simulation.backends.backendv2.Backend

Helper class that provides a standard way to create an ABC using inheritance.

run(circuit: QuantumCircuit, **options)[source]ΒΆ
execute(circuit: QuantumCircuit)[source]ΒΆ
Package ContentsΒΆ
class MISim(**fields)[source]ΒΆ

Bases: mqt.qudits.simulation.backends.backendv2.Backend

Helper class that provides a standard way to create an ABC using inheritance.

run(circuit: QuantumCircuit, **options) Job[source]ΒΆ
execute(circuit: QuantumCircuit, noise_model: NoiseModel | None = None) ndarray[source]ΒΆ
class TNSim(**fields)[source]ΒΆ

Bases: mqt.qudits.simulation.backends.backendv2.Backend

Helper class that provides a standard way to create an ABC using inheritance.

run(circuit: QuantumCircuit, **options)[source]ΒΆ
execute(circuit: QuantumCircuit)[source]ΒΆ
mqt.qudits.simulation.jobsΒΆ
SubmodulesΒΆ
mqt.qudits.simulation.jobs.jobΒΆ
Module ContentsΒΆ
class Job(backend: Backend | None, job_id: str = 'auto', **kwargs)[source]ΒΆ

Class to handle jobs

This first version of the Backend abstract class is written to be mostly backwards compatible with the legacy providers interface. This was done to ease the transition for users and provider maintainers to the new versioned providers. Expect future versions of this abstract class to change the data model and interface.

version = 1ΒΆ
job_id() str[source]ΒΆ

Return a unique id identifying the job.

backend() Backend[source]ΒΆ

Return the backend where this job was executed.

done() bool[source]ΒΆ

Return whether the job has successfully run.

running() bool[source]ΒΆ

Return whether the job is actively running.

cancelled() bool[source]ΒΆ

Return whether the job has been cancelled.

in_final_state() bool[source]ΒΆ

Return whether the job is in a final job state such as DONE or ERROR.

wait_for_final_state(timeout: float | None = None, wait: float = 5, callback: Callable | None = None) None[source]ΒΆ

Poll the job status until it progresses to a final state such as DONE or ERROR.

Parameters:
  • timeout – Seconds to wait for the job. If None, wait indefinitely.

  • wait – Seconds between queries.

  • callback – Callback function invoked after each query.

Raises:

JobTimeoutError – If the job does not reach a final state before the specified timeout.

abstract submit() NoReturn[source]ΒΆ

Submit the job to the backend for execution.

result()[source]ΒΆ

Return the results of the job.

set_result(result) None[source]ΒΆ
abstract cancel() NoReturn[source]ΒΆ

Attempt to cancel the job.

abstract status() str[source]ΒΆ

Return the status of the job, among the values of BackendStatus.

mqt.qudits.simulation.jobs.job_resultΒΆ
Module ContentsΒΆ
class JobResult(state_vector: list[numpy.complex128], counts: list[int])[source]ΒΆ
get_counts() list[int][source]ΒΆ
get_state_vector() list[numpy.complex128][source]ΒΆ
mqt.qudits.simulation.jobs.jobstatusΒΆ
Module ContentsΒΆ
class JobStatus(*args, **kwds)[source]ΒΆ

Bases: enum.Enum

Enumeration for job status.

INITIALIZING = 'Initializing: Job is being initialized'ΒΆ
QUEUED = 'Queued: Job is waiting in the queue'ΒΆ
VALIDATING = 'Validating: Job is being validated'ΒΆ
RUNNING = 'Running: Job is actively running'ΒΆ
CANCELLED = 'Cancelled: Job has been cancelled'ΒΆ
DONE = 'Done: Job has successfully run'ΒΆ
ERROR = 'Error: Job incurred an error'ΒΆ
JOB_FINAL_STATES = ()ΒΆ
Package ContentsΒΆ
class Job(backend: Backend | None, job_id: str = 'auto', **kwargs)[source]ΒΆ

Class to handle jobs

This first version of the Backend abstract class is written to be mostly backwards compatible with the legacy providers interface. This was done to ease the transition for users and provider maintainers to the new versioned providers. Expect future versions of this abstract class to change the data model and interface.

version = 1ΒΆ
job_id() str[source]ΒΆ

Return a unique id identifying the job.

backend() Backend[source]ΒΆ

Return the backend where this job was executed.

done() bool[source]ΒΆ

Return whether the job has successfully run.

running() bool[source]ΒΆ

Return whether the job is actively running.

cancelled() bool[source]ΒΆ

Return whether the job has been cancelled.

in_final_state() bool[source]ΒΆ

Return whether the job is in a final job state such as DONE or ERROR.

wait_for_final_state(timeout: float | None = None, wait: float = 5, callback: Callable | None = None) None[source]ΒΆ

Poll the job status until it progresses to a final state such as DONE or ERROR.

Parameters:
  • timeout – Seconds to wait for the job. If None, wait indefinitely.

  • wait – Seconds between queries.

  • callback – Callback function invoked after each query.

Raises:

JobTimeoutError – If the job does not reach a final state before the specified timeout.

abstract submit() NoReturn[source]ΒΆ

Submit the job to the backend for execution.

result()[source]ΒΆ

Return the results of the job.

set_result(result) None[source]ΒΆ
abstract cancel() NoReturn[source]ΒΆ

Attempt to cancel the job.

abstract status() str[source]ΒΆ

Return the status of the job, among the values of BackendStatus.

class JobResult(state_vector: list[numpy.complex128], counts: list[int])[source]ΒΆ
get_counts() list[int][source]ΒΆ
get_state_vector() list[numpy.complex128][source]ΒΆ
class JobStatus(*args, **kwds)[source]ΒΆ

Bases: enum.Enum

Enumeration for job status.

INITIALIZING = 'Initializing: Job is being initialized'ΒΆ
QUEUED = 'Queued: Job is waiting in the queue'ΒΆ
VALIDATING = 'Validating: Job is being validated'ΒΆ
RUNNING = 'Running: Job is actively running'ΒΆ
CANCELLED = 'Cancelled: Job has been cancelled'ΒΆ
DONE = 'Done: Job has successfully run'ΒΆ
ERROR = 'Error: Job incurred an error'ΒΆ
mqt.qudits.simulation.noise_toolsΒΆ
SubmodulesΒΆ
mqt.qudits.simulation.noise_tools.noiseΒΆ
Module ContentsΒΆ
class Noise[source]ΒΆ
probability_depolarizing: floatΒΆ
probability_dephasing: floatΒΆ
class NoiseModel[source]ΒΆ
property basis_gatesΒΆ
add_recurrent_quantum_error_locally(noise, gates, qudits) None[source]ΒΆ
add_quantum_error_locally(noise, gates) None[source]ΒΆ
add_all_qudit_quantum_error(noise, gates) None[source]ΒΆ
add_nonlocal_quantum_error(noise, gates) None[source]ΒΆ
add_nonlocal_quantum_error_on_target(noise, gates) None[source]ΒΆ
add_nonlocal_quantum_error_on_control(noise, gates) None[source]ΒΆ
__str__() str[source]ΒΆ

Return str(self).

mqt.qudits.simulation.noise_tools.noisy_circuit_factoryΒΆ
Module ContentsΒΆ
class NoisyCircuitFactory(noise_model: NoiseModel, circuit: QuantumCircuit)[source]ΒΆ
generate_circuit()[source]ΒΆ
Package ContentsΒΆ
class Noise[source]ΒΆ
probability_depolarizing: floatΒΆ
probability_dephasing: floatΒΆ
class NoiseModel[source]ΒΆ
property basis_gatesΒΆ
add_recurrent_quantum_error_locally(noise, gates, qudits) None[source]ΒΆ
add_quantum_error_locally(noise, gates) None[source]ΒΆ
add_all_qudit_quantum_error(noise, gates) None[source]ΒΆ
add_nonlocal_quantum_error(noise, gates) None[source]ΒΆ
add_nonlocal_quantum_error_on_target(noise, gates) None[source]ΒΆ
add_nonlocal_quantum_error_on_control(noise, gates) None[source]ΒΆ
__str__() str[source]ΒΆ

Return str(self).

class NoisyCircuitFactory(noise_model: NoiseModel, circuit: QuantumCircuit)[source]ΒΆ
generate_circuit()[source]ΒΆ
SubmodulesΒΆ
mqt.qudits.simulation.qudit_providerΒΆ
Module ContentsΒΆ
class MQTQuditProvider[source]ΒΆ
property version: intΒΆ
get_backend(name: str | None = None, **kwargs) Backend[source]ΒΆ

Return a single backend matching the specified filtering.

backends(name: str | None = None, **kwargs) list[Backend][source]ΒΆ

Return a list of backends matching the specified filtering.

__eq__(other: object) bool[source]ΒΆ

Return self==value.

__hash__() int[source]ΒΆ

Return hash(self).

mqt.qudits.simulation.save_infoΒΆ
Module ContentsΒΆ
save_full_states(list_of_vectors, file_path=None, file_name=None) None[source]ΒΆ
save_shots(shots, file_path=None, file_name=None) None[source]ΒΆ
Package ContentsΒΆ
class MQTQuditProvider[source]ΒΆ
property version: intΒΆ
get_backend(name: str | None = None, **kwargs) Backend[source]ΒΆ

Return a single backend matching the specified filtering.

backends(name: str | None = None, **kwargs) list[Backend][source]ΒΆ

Return a list of backends matching the specified filtering.

__eq__(other: object) bool[source]ΒΆ

Return self==value.

__hash__() int[source]ΒΆ

Return hash(self).

mqt.qudits.visualisationΒΆ

SubmodulesΒΆ
mqt.qudits.visualisation.drawing_routinesΒΆ
Module ContentsΒΆ
draw_qudit_local(circuit: QuantumCircuit) None[source]ΒΆ
mqt.qudits.visualisation.mini_quantum_informationΒΆ
Module ContentsΒΆ
get_density_matrix_from_counts(results, circuit)[source]ΒΆ
partial_trace(rho, qudits2keep, dims, optimize=False)[source]ΒΆ

Calculate the partial trace

p_a = Tr_b(p)

ParametersΒΆ
p2D array

Matrix to trace

qudits2keeparray

An array of indices of the spaces to keep after being traced. For instance, if the space is A x B x C x D and we want to trace out B and D, keep = [0,2]

dimsarray

An array of the dimensions of each space. For instance, if the space is A x B x C x D, dims = [dim_A, dim_B, dim_C, dim_D]

ReturnsΒΆ
p_a2D array

Traced matrix

mqt.qudits.visualisation.plot_informationΒΆ
Module ContentsΒΆ
class HistogramWithErrors(labels, counts, errors, title='Simulation')[source]ΒΆ
generate_histogram() None[source]ΒΆ
save_to_png(filename) None[source]ΒΆ
state_labels(circuit)[source]ΒΆ
plot_state(result: ndarray, circuit: QuantumCircuit, errors=None) None[source]ΒΆ
plot_counts(result, circuit: QuantumCircuit) None[source]ΒΆ
Package ContentsΒΆ
draw_qudit_local(circuit: QuantumCircuit) None[source]ΒΆ
get_density_matrix_from_counts(results, circuit)[source]ΒΆ
partial_trace(rho, qudits2keep, dims, optimize=False)[source]ΒΆ

Calculate the partial trace

p_a = Tr_b(p)

ParametersΒΆ
p2D array

Matrix to trace

qudits2keeparray

An array of indices of the spaces to keep after being traced. For instance, if the space is A x B x C x D and we want to trace out B and D, keep = [0,2]

dimsarray

An array of the dimensions of each space. For instance, if the space is A x B x C x D, dims = [dim_A, dim_B, dim_C, dim_D]

ReturnsΒΆ
p_a2D array

Traced matrix

plot_counts(result, circuit: QuantumCircuit) None[source]ΒΆ
plot_state(result: ndarray, circuit: QuantumCircuit, errors=None) None[source]ΒΆ

Package ContentsΒΆ

__version__: strΒΆ
version_info: tuple[int, int, int, str, str] | tuple[int, int, int]ΒΆ