From 516829a801bfe23e38ee09975dfb7cf30da3b01a Mon Sep 17 00:00:00 2001 From: jordandsullivan Date: Wed, 25 Sep 2024 14:47:28 -0700 Subject: [PATCH 1/5] removed QuantumTranslator module as it is superannuated by qbraid.transpile and associated functions --- ucc/__init__.py | 5 +- ucc/compile.py | 6 +- ucc/quantum_translator/__init__.py | 1 - ucc/quantum_translator/interfaces/__init__.py | 3 - .../interfaces/cirq_interface.py | 7 - .../interfaces/qiskit_interface.py | 10 -- .../interfaces/tket_interface.py | 8 - ucc/quantum_translator/quantum_translator.py | 148 ------------------ .../tests/test_cirq_interface.py | 29 ---- .../tests/test_qiskit_interface.py | 24 --- .../tests/test_quantum_translator.py | 65 -------- .../tests/test_tket_interface.py | 30 ---- .../tests/utils/__init__.py | 0 .../tests/utils/circuits/__init__.py | 0 .../tests/utils/circuits/cirq_circuits.py | 11 -- .../tests/utils/circuits/qasm2_circuits.py | 8 - .../tests/utils/circuits/qasm3_circuits.py | 7 - .../tests/utils/circuits/qiskit_circuits.py | 11 -- .../tests/utils/circuits/tket_circuits.py | 11 -- ucc/transpilers/ucc_transpiler.py | 2 +- 20 files changed, 7 insertions(+), 379 deletions(-) delete mode 100644 ucc/quantum_translator/__init__.py delete mode 100644 ucc/quantum_translator/interfaces/__init__.py delete mode 100644 ucc/quantum_translator/interfaces/cirq_interface.py delete mode 100644 ucc/quantum_translator/interfaces/qiskit_interface.py delete mode 100644 ucc/quantum_translator/interfaces/tket_interface.py delete mode 100644 ucc/quantum_translator/quantum_translator.py delete mode 100644 ucc/quantum_translator/tests/test_cirq_interface.py delete mode 100644 ucc/quantum_translator/tests/test_qiskit_interface.py delete mode 100644 ucc/quantum_translator/tests/test_quantum_translator.py delete mode 100644 ucc/quantum_translator/tests/test_tket_interface.py delete mode 100644 ucc/quantum_translator/tests/utils/__init__.py delete mode 100644 ucc/quantum_translator/tests/utils/circuits/__init__.py delete mode 100644 ucc/quantum_translator/tests/utils/circuits/cirq_circuits.py delete mode 100644 ucc/quantum_translator/tests/utils/circuits/qasm2_circuits.py delete mode 100644 ucc/quantum_translator/tests/utils/circuits/qasm3_circuits.py delete mode 100644 ucc/quantum_translator/tests/utils/circuits/qiskit_circuits.py delete mode 100644 ucc/quantum_translator/tests/utils/circuits/tket_circuits.py diff --git a/ucc/__init__.py b/ucc/__init__.py index 424a4ea2..c52a5107 100644 --- a/ucc/__init__.py +++ b/ucc/__init__.py @@ -1,4 +1,3 @@ from .transpilers import UCCTranspiler -from .compile import compile -from .custom_cx import CXCancellation -from .quantum_translator import QuantumTranslator +from .compile import compile, supported_circuit_formats +from .custom_cx import CXCancellation \ No newline at end of file diff --git a/ucc/compile.py b/ucc/compile.py index 65562d3e..72e1f992 100644 --- a/ucc/compile.py +++ b/ucc/compile.py @@ -1,8 +1,9 @@ -from ucc.quantum_translator import QuantumTranslator from ucc.transpilers import UCCTranspiler from qbraid.transpiler import transpile from qbraid.programs.alias_manager import get_program_type_alias +from qbraid.transpiler import ConversionGraph +supported_circuit_formats = ConversionGraph().nodes() def compile(circuit, return_format='original', mode='ucc', get_gate_counts=False): """ @@ -12,7 +13,7 @@ def compile(circuit, return_format='original', mode='ucc', get_gate_counts=False circuit (object): The quantum circuit to be compiled. return_format (str): The format in which your circuit will be returned. e.g. "TKET", "OpenQASM2" - Check `ucc.QuantumTranslator.supported_circuit_formats()` + Check `ucc.supported_circuit_formats()` Defaults to format of input circuit. mode (str): 'ucc' or 'qiskit, specifies transpiler mode to use @@ -22,6 +23,7 @@ def compile(circuit, return_format='original', mode='ucc', get_gate_counts=False if return_format == "original": return_format = get_program_type_alias(circuit) + # Currently all circuits are translated to Qiskit Circuit objects before DAG optimization qiskit_circuit = transpile(circuit, "qiskit") compiled_circuit, gate_counts = UCCTranspiler.transpile(qiskit_circuit, mode=mode, get_gate_counts=get_gate_counts) diff --git a/ucc/quantum_translator/__init__.py b/ucc/quantum_translator/__init__.py deleted file mode 100644 index ad122866..00000000 --- a/ucc/quantum_translator/__init__.py +++ /dev/null @@ -1 +0,0 @@ -from .quantum_translator import QuantumTranslator diff --git a/ucc/quantum_translator/interfaces/__init__.py b/ucc/quantum_translator/interfaces/__init__.py deleted file mode 100644 index 4cce7d33..00000000 --- a/ucc/quantum_translator/interfaces/__init__.py +++ /dev/null @@ -1,3 +0,0 @@ -from .cirq_interface import CirqInterface -from .qiskit_interface import QiskitInterface -from .tket_interface import TKETInterface \ No newline at end of file diff --git a/ucc/quantum_translator/interfaces/cirq_interface.py b/ucc/quantum_translator/interfaces/cirq_interface.py deleted file mode 100644 index 35c42f08..00000000 --- a/ucc/quantum_translator/interfaces/cirq_interface.py +++ /dev/null @@ -1,7 +0,0 @@ -import cirq - -class CirqInterface: - @staticmethod - def to_qasm(circuit: cirq.Circuit) -> str: - """Translates a Cirq circuit to OpenQASM2. OpenQASM3 is not currently supported by Cirq.""" - return cirq.qasm(circuit) diff --git a/ucc/quantum_translator/interfaces/qiskit_interface.py b/ucc/quantum_translator/interfaces/qiskit_interface.py deleted file mode 100644 index 96161739..00000000 --- a/ucc/quantum_translator/interfaces/qiskit_interface.py +++ /dev/null @@ -1,10 +0,0 @@ -from qiskit import QuantumCircuit, qasm3, qasm2 - -class QiskitInterface: - @staticmethod - def to_qasm(circuit: QuantumCircuit, version='2') -> str: - """Translates a Qiskit circuit to OpenQASM string of the version specified.""" - if version == '2': - return qasm2.dumps(circuit) - elif version =='3': - return qasm3.dumps(circuit) diff --git a/ucc/quantum_translator/interfaces/tket_interface.py b/ucc/quantum_translator/interfaces/tket_interface.py deleted file mode 100644 index bf9c0ee4..00000000 --- a/ucc/quantum_translator/interfaces/tket_interface.py +++ /dev/null @@ -1,8 +0,0 @@ -from pytket import Circuit -from pytket.qasm import circuit_to_qasm_str - -class TKETInterface: - @staticmethod - def to_qasm(circuit: Circuit) -> str: - """Translates a TKET circuit to OpenQASM2. OpenQASM3 is not currently supported by PyTKET.""" - return circuit_to_qasm_str(circuit) diff --git a/ucc/quantum_translator/quantum_translator.py b/ucc/quantum_translator/quantum_translator.py deleted file mode 100644 index fe9087e8..00000000 --- a/ucc/quantum_translator/quantum_translator.py +++ /dev/null @@ -1,148 +0,0 @@ -from pytket import Circuit as TketCircuit -from cirq import Circuit as CirqCircuit -from qiskit import QuantumCircuit as QiskitCircuit - -from cirq.contrib.qasm_import import circuit_from_qasm as cirq_from_qasm -from pytket.qasm import circuit_from_qasm_str as tket_from_qasm - -import qiskit.qasm2 -import qiskit.qasm3 - -from .interfaces import QiskitInterface, TKETInterface, CirqInterface - -class QuantumTranslator: - def __init__(self, circuit, return_format='original'): - self._original_circuit = circuit - self._original_format = self.identify_format(circuit) - - if return_format == 'original': - self.return_format = self._original_format - else: - self.return_format = return_format - - @property - def supported_circuit_formats(): - return ["pytket.Circuit", "cirq.Circuit", "qiskit.QuantumCircuit", "OpenQASM2"] - - @classmethod - def identify_format(cls, circuit): - if isinstance(circuit, TketCircuit): - return 'tket' - elif isinstance(circuit, QiskitCircuit): - return 'qiskit' - elif isinstance(circuit, CirqCircuit): - return 'cirq' - elif cls.is_valid_openqasm(circuit, version=2): - return 'openqasm2' - elif cls.is_valid_openqasm(circuit, version=3): - return 'openqasm3' - else: - return 'unknown' - - @classmethod - def to_qasm(cls, circuit, version='2'): - """ - Identify type of the provided circuit, and if supported, translate to - OpenQASM of the version specified. - - Parameters: - circuit (str): A quantum circuit of supported types - (qiskit, cirq, pytket). - version (str): OpenQASM version to translate the given `circuit` to. - Defaults to '2'. - Returns: - str: OpenQASM2 or OpenQASM3 code corresponding to given `circuit`. - """ - circuit_format = cls.identify_format(circuit) - - match circuit_format: - case 'tket': - return TKETInterface.to_qasm(circuit) - case 'qiskit': - return QiskitInterface.to_qasm(circuit, version) - case 'cirq': - return CirqInterface.to_qasm(circuit) - case 'openqasm2': - if version == '2': - return circuit # Circuit is already OpenQasm2 - elif version == '3': - # Translate to Qiskit, then to OpenQASM3 - qis_circuit = cls.to_qiskit(circuit) - return QiskitInterface.to_qasm(qis_circuit, version='2') - case 'openqasm3': - if version == '3': - return circuit # Circuit is already OpenQasm3 - elif version == '2': - # Translate to Qiskit, then to OpenQASM2 - qis_circuit = cls.to_qiskit(circuit) - return QiskitInterface.to_qasm(qis_circuit, version='3') - - raise TypeError(f'Provided circuit is not in {cls.supported_circuit_formats}') - - def to_return_format(self, qasm_circuit): - """Translates given OpenQASM `qasm_circuit` to format of `self.return_format`.""" - match self.return_format: - case 'tket': - return self.to_tket(qasm_circuit) - case 'qiskit': - return self.to_qiskit(qasm_circuit) - case 'cirq': - return self.to_cirq(qasm_circuit) - case 'openqasm2': - return self.to_qasm(qasm_circuit, version='2') - case 'openqasm3': - return self.to_qasm(qasm_circuit, version='3') - - - @classmethod - def to_tket(cls, qasm_circuit: str) -> TketCircuit: - """Validates and translates an OpenQASM2 string to a TKET circuit. - OpenQASM3 is not currently supported by PyTKET.""" - - # assert cls.is_valid_openqasm(qasm_circuit, version='2') - return tket_from_qasm(qasm_circuit) - - @classmethod - def to_cirq(cls, qasm_circuit: str) -> CirqCircuit: - """Validates and translates an OpenQASM2 string to a cirq circuit. - OpenQASM3 is not currently supported by Cirq.""" - - # assert cls.is_valid_openqasm(qasm_circuit, version='2') - return cirq_from_qasm(qasm_circuit) - - @classmethod - def to_qiskit(cls, qasm_circuit: str) -> QiskitCircuit: - """Validates and translates an OpenQASM2 or OpenQASM3 string to a Qiskit circuit.""" - - if cls.is_valid_openqasm(qasm_circuit, version='2'): - return qiskit.qasm2.loads(qasm_circuit) - elif cls.is_valid_openqasm(qasm_circuit, version='3'): - return qiskit.qasm3.loads(qasm_circuit) - - - @staticmethod - def is_valid_openqasm(qasm_output, version): - """ - Check if the provided string is valid OpenQASM code of the version specified. - - Parameters: - qasm_output (str): The OpenQASM code as a string. - - Returns: - bool: True if the string is valid OpenQASM of the version - specified, False otherwise. - """ - if version == '3': - try: - qiskit.qasm3.loads(qasm_output) - return True - except Exception as a: - print(a) - return False - elif version == '2': - try: - qiskit.qasm2.loads(qasm_output) - return True - except Exception as a: - print(a) - return False diff --git a/ucc/quantum_translator/tests/test_cirq_interface.py b/ucc/quantum_translator/tests/test_cirq_interface.py deleted file mode 100644 index 1a28f2e4..00000000 --- a/ucc/quantum_translator/tests/test_cirq_interface.py +++ /dev/null @@ -1,29 +0,0 @@ -# tests/test_.interfaces..interfaces.cirq_interface.py - -from cirq import Circuit, H, CNOT, LineQubit -from ucc.quantum_translator.interfaces import CirqInterface -from ucc.quantum_translator import QuantumTranslator -import pytest - -@pytest.mark.skip(reason="Skipping as cirq lacks OpenQASM3 conversion as of Aug 21, 2024.") -def test_cirq_to_openqasm3(): - # Create a simple Cirq circuit - qubits = LineQubit.range(2) - circuit = Circuit(H(qubits[0]), CNOT(qubits[0], qubits[1])) - - # Translate the circuit to OpenQASM3 - qasm_output = CirqInterface.to_qasm(circuit) - - # Validate the output as OpenQASM3 - assert QuantumTranslator.is_valid_openqasm(qasm_output, version='3'), "The generated code is not valid OpenQASM3." - -def test_cirq_to_openqasm2(): - # Create a simple Cirq circuit - qubits = LineQubit.range(2) - circuit = Circuit(H(qubits[0]), CNOT(qubits[0], qubits[1])) - - # Translate the circuit to OpenQASM3 - qasm_output = CirqInterface.to_qasm(circuit) - - # Validate the output as OpenQASM3 - assert QuantumTranslator.is_valid_openqasm(qasm_output, version='2'), "The generated code is not valid OpenQASM3." diff --git a/ucc/quantum_translator/tests/test_qiskit_interface.py b/ucc/quantum_translator/tests/test_qiskit_interface.py deleted file mode 100644 index 88a77de4..00000000 --- a/ucc/quantum_translator/tests/test_qiskit_interface.py +++ /dev/null @@ -1,24 +0,0 @@ -# tests/test_.interfaces.qiskit_interface.py - -from qiskit import QuantumCircuit -from ucc.quantum_translator.interfaces import QiskitInterface -from ucc.quantum_translator import QuantumTranslator - -# Create a simple quantum circuit -circuit = QuantumCircuit(2) -circuit.h(0) -circuit.cx(0, 1) - -def test_qiskit_to_openqasm3(): - # Translate the circuit to OpenQASM3 - qasm_output = QiskitInterface.to_qasm(circuit, version='3') - print(qasm_output) - # Validate the output as OpenQASM3 - assert QuantumTranslator.is_valid_openqasm(qasm_output, version='3'), "The generated code is not valid OpenQASM3." - -def test_qiskit_to_openqasm2(): - # Translate the circuit to OpenQASM2 - qasm_output = QiskitInterface.to_qasm(circuit, version='2') - - # Validate the output as OpenQASM3 - assert QuantumTranslator.is_valid_openqasm(qasm_output, version='2'), "The generated code is not valid OpenQASM2." diff --git a/ucc/quantum_translator/tests/test_quantum_translator.py b/ucc/quantum_translator/tests/test_quantum_translator.py deleted file mode 100644 index b8e1263c..00000000 --- a/ucc/quantum_translator/tests/test_quantum_translator.py +++ /dev/null @@ -1,65 +0,0 @@ -import pytest -from ucc.quantum_translator import QuantumTranslator -from pytket import Circuit as TketCircuit -from cirq import Circuit as CirqCircuit -from qiskit import QuantumCircuit as QiskitCircuit - - -# Test valid TKET circuit to OpenQASM2 translation -def test_tket_to_qasm2(): - circuit = TketCircuit(2) - qasm_output = QuantumTranslator.to_qasm(circuit, version='2') - assert QuantumTranslator.is_valid_openqasm(qasm_output, version='2') - -# Test valid Qiskit circuit to OpenQASM3 translation -def test_qiskit_to_qasm3(): - circuit = QiskitCircuit(2) - qasm_output = QuantumTranslator.to_qasm(circuit, version='3') - assert QuantumTranslator.is_valid_openqasm(qasm_output, version='3') - -# Test valid OpenQASM2 input -def test_valid_openqasm2_input(): - openqasm_str = """ - OPENQASM 2.0; - include "qelib1.inc"; - qreg q[2]; - h q[0]; - cx q[0], q[1]; - """ - assert QuantumTranslator.is_valid_openqasm(openqasm_str, version='2') - -# Test valid OpenQASM3 input -def test_valid_openqasm3_input(): - openqasm_str = """ - OPENQASM 3.0; - include "stdgates.inc"; - qubit[2] q; - h q[0]; - cx q[0], q[1]; - """ - assert QuantumTranslator.is_valid_openqasm(openqasm_str, version='3') - -# Test invalid circuit type -def test_invalid_circuit_type(): - class CustomCircuit: - pass - - with pytest.raises(TypeError): - QuantumTranslator.to_qasm(CustomCircuit()) - -# Test invalid OpenQASM2 string -def test_invalid_openqasm2_string(): - invalid_qasm = "INVALID OPENQASM CODE" - assert not QuantumTranslator.is_valid_openqasm(invalid_qasm, version='2') - -# Test invalid OpenQASM3 string -def test_invalid_openqasm3_string(): - invalid_qasm = "INVALID OPENQASM CODE" - assert not QuantumTranslator.is_valid_openqasm(invalid_qasm, version='3') - -# Test OpenQASM3 translation from a Qiskit circuit -def test_qiskit_to_qasm3(): - circuit = QiskitCircuit(2) - qasm_output = QuantumTranslator.to_qasm(circuit, version='3') - assert QuantumTranslator.is_valid_openqasm(qasm_output, version='3') - diff --git a/ucc/quantum_translator/tests/test_tket_interface.py b/ucc/quantum_translator/tests/test_tket_interface.py deleted file mode 100644 index c9100350..00000000 --- a/ucc/quantum_translator/tests/test_tket_interface.py +++ /dev/null @@ -1,30 +0,0 @@ -from pytket import Circuit -from ucc.quantum_translator.interfaces import TKETInterface -from ucc.quantum_translator import QuantumTranslator -import pytest - -@pytest.mark.skip( - reason="Skipping as PyTKET lacks OpenQASM3 conversion as of Aug 21, 2024.") -def test_tket_to_openqasm3(): - # Create a simple TKET circuit - circuit = Circuit(2) - circuit.H(0) - circuit.CX(0, 1) - - # Translate the circuit to OpenQASM3 - qasm_output = TKETInterface.to_qasm(circuit) - - # Validate the output as OpenQASM3 - assert QuantumTranslator.is_valid_openqasm(qasm_output, version='3'), "The generated code is not valid OpenQASM3." - -def test_tket_to_openqasm2(): - # Create a simple TKET circuit - circuit = Circuit(2) - circuit.H(0) - circuit.CX(0, 1) - - # Translate the circuit to OpenQASM3 - qasm_output = TKETInterface.to_qasm(circuit) - - # Validate the output as OpenQASM3 - assert QuantumTranslator.is_valid_openqasm(qasm_output, version='2'), "The generated code is not valid OpenQASM3." diff --git a/ucc/quantum_translator/tests/utils/__init__.py b/ucc/quantum_translator/tests/utils/__init__.py deleted file mode 100644 index e69de29b..00000000 diff --git a/ucc/quantum_translator/tests/utils/circuits/__init__.py b/ucc/quantum_translator/tests/utils/circuits/__init__.py deleted file mode 100644 index e69de29b..00000000 diff --git a/ucc/quantum_translator/tests/utils/circuits/cirq_circuits.py b/ucc/quantum_translator/tests/utils/circuits/cirq_circuits.py deleted file mode 100644 index 943ebc19..00000000 --- a/ucc/quantum_translator/tests/utils/circuits/cirq_circuits.py +++ /dev/null @@ -1,11 +0,0 @@ -from cirq import Circuit, H, CNOT, LineQubit - -def ghz_state(n_qubits): - qubits = LineQubit.range(n_qubits) - circuit = Circuit(H(qubits[0])) - - for i in range(n_qubits - 1): - circuit.append(CNOT(qubits[i], qubits[i+1])) - - return circuit - diff --git a/ucc/quantum_translator/tests/utils/circuits/qasm2_circuits.py b/ucc/quantum_translator/tests/utils/circuits/qasm2_circuits.py deleted file mode 100644 index 22e08616..00000000 --- a/ucc/quantum_translator/tests/utils/circuits/qasm2_circuits.py +++ /dev/null @@ -1,8 +0,0 @@ -bell_state = """ -OPENQASM 2.0; -include "qelib1.inc"; -qreg q[2]; -h q[0]; -cx q[0], q[1]; -""" - diff --git a/ucc/quantum_translator/tests/utils/circuits/qasm3_circuits.py b/ucc/quantum_translator/tests/utils/circuits/qasm3_circuits.py deleted file mode 100644 index f7e72864..00000000 --- a/ucc/quantum_translator/tests/utils/circuits/qasm3_circuits.py +++ /dev/null @@ -1,7 +0,0 @@ -bell_state = """ - OPENQASM 3.0; - include "stdgates.inc"; - qubit[2] q; - h q[0]; - cx q[0], q[1]; - """ \ No newline at end of file diff --git a/ucc/quantum_translator/tests/utils/circuits/qiskit_circuits.py b/ucc/quantum_translator/tests/utils/circuits/qiskit_circuits.py deleted file mode 100644 index 3eb0cc3a..00000000 --- a/ucc/quantum_translator/tests/utils/circuits/qiskit_circuits.py +++ /dev/null @@ -1,11 +0,0 @@ -from qiskit import QuantumCircuit - -def ghz_state(n_qubits): - circuit = QuantumCircuit(n_qubits) - circuit.h(0) - - for i in range(n_qubits - 1): - circuit.cx(i, i + 1) - - return circuit - diff --git a/ucc/quantum_translator/tests/utils/circuits/tket_circuits.py b/ucc/quantum_translator/tests/utils/circuits/tket_circuits.py deleted file mode 100644 index a9ed8505..00000000 --- a/ucc/quantum_translator/tests/utils/circuits/tket_circuits.py +++ /dev/null @@ -1,11 +0,0 @@ -from pytket import Circuit - -def ghz_state(n_qubits): - circuit = Circuit(n_qubits) - circuit.H(0) - - for i in range(n_qubits - 1): - circuit.CX(i, i + 1) - - return circuit - diff --git a/ucc/transpilers/ucc_transpiler.py b/ucc/transpilers/ucc_transpiler.py index c8054e49..8c6aef2b 100644 --- a/ucc/transpilers/ucc_transpiler.py +++ b/ucc/transpilers/ucc_transpiler.py @@ -1,5 +1,5 @@ from qiskit import transpile, QuantumCircuit -from ..quantum_translator import QuantumTranslator + from ucc.transpilers.ucc_defaults import UCCDefault1 From 060da34c3bde3f2faa668db3f94ded70d2e9ba95 Mon Sep 17 00:00:00 2001 From: jordandsullivan Date: Wed, 25 Sep 2024 14:48:00 -0700 Subject: [PATCH 2/5] Removing outdated references in jupyter notebooks; --- .../check_parameterized.ipynb | 42 ++- .../custom_compile_heisenberg_ring.ipynb | 154 ++--------- .../custom_compile_qcnn.ipynb | 154 +++-------- .../custom_compile_qft.ipynb | 243 ++++++++++++++++-- 4 files changed, 290 insertions(+), 303 deletions(-) diff --git a/custom_compiler_experiments/check_parameterized.ipynb b/custom_compiler_experiments/check_parameterized.ipynb index e779534e..c8b17c0a 100644 --- a/custom_compiler_experiments/check_parameterized.ipynb +++ b/custom_compiler_experiments/check_parameterized.ipynb @@ -2,7 +2,7 @@ "cells": [ { "cell_type": "code", - "execution_count": 1, + "execution_count": 24, "metadata": {}, "outputs": [], "source": [ @@ -16,7 +16,7 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": 25, "metadata": {}, "outputs": [ { @@ -46,14 +46,14 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 26, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "Time taken: 0.008273601531982422\n", + "Time taken: 0.007478952407836914\n", "OrderedDict({'rz': 1})\n", "Number of 2-qubit gates: 0\n", "Number of 1-qubit gates: 1\n", @@ -84,7 +84,7 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": 27, "metadata": {}, "outputs": [ { @@ -120,14 +120,14 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": 28, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "Time taken: 0.028227567672729492\n", + "Time taken: 0.014104127883911133\n", "OrderedDict({'cx': 2, 'rz': 2})\n", "Number of 2-qubit gates: 2\n", "Number of 1-qubit gates: 2\n", @@ -165,13 +165,14 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": 32, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ + "Time taken: 0.002134084701538086\n", " ┌────────────┐┌────────────┐\n", "q_0: ┤ Rz(angle1) ├┤ Rz(angle2) ├\n", " └────────────┘└────────────┘\n", @@ -189,36 +190,23 @@ "from ucc.transpilers.ucc_defaults import UCCDefault1\n", "\n", "ucc_transpiler = UCCDefault1()\n", + "t1 = time.time()\n", "transpiled_circuit = ucc_transpiler.run(pqc)\n", + "t2 = time.time()\n", + "print(\"Time taken: \", t2-t1)\n", "\n", "print(transpiled_circuit)" ] }, { "cell_type": "code", - "execution_count": 7, + "execution_count": 30, "metadata": {}, - "outputs": [ - { - "ename": "QASM2ExportError", - "evalue": "'Cannot represent circuits with unbound parameters in OpenQASM 2.'", - "output_type": "error", - "traceback": [ - "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", - "\u001b[0;31mQASM2ExportError\u001b[0m Traceback (most recent call last)", - "Cell \u001b[0;32mIn[7], line 3\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01mucc\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m \u001b[38;5;28mcompile\u001b[39m\n\u001b[0;32m----> 3\u001b[0m ucc_qc, gate_counts \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;43mcompile\u001b[39;49m\u001b[43m(\u001b[49m\u001b[43mpqc\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mmode\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mqiskit\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mdraw\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;28;43;01mFalse\u001b[39;49;00m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mget_gate_counts\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43m \u001b[49m\u001b[38;5;28;43;01mTrue\u001b[39;49;00m\u001b[43m)\u001b[49m\n", - "File \u001b[0;32m~/ucc/custom_compiler_experiments/../ucc/compile.py:23\u001b[0m, in \u001b[0;36mcompile\u001b[0;34m(circuit, qasm_version, return_format, mode, draw, get_gate_counts)\u001b[0m\n\u001b[1;32m 5\u001b[0m \u001b[38;5;250m\u001b[39m\u001b[38;5;124;03m\"\"\"\u001b[39;00m\n\u001b[1;32m 6\u001b[0m \u001b[38;5;124;03mProcesses the provided quantum circuit using the QuantumTranslator \u001b[39;00m\n\u001b[1;32m 7\u001b[0m \u001b[38;5;124;03mand compiles it using the Compiler. Why is it called a compiler and not\u001b[39;00m\n\u001b[0;32m (...)\u001b[0m\n\u001b[1;32m 20\u001b[0m \u001b[38;5;124;03m variable type : Compiled circuit result \u001b[39;00m\n\u001b[1;32m 21\u001b[0m \u001b[38;5;124;03m\"\"\"\u001b[39;00m\n\u001b[1;32m 22\u001b[0m translator \u001b[38;5;241m=\u001b[39m QuantumTranslator(circuit, return_format)\n\u001b[0;32m---> 23\u001b[0m qasm_code \u001b[38;5;241m=\u001b[39m \u001b[43mtranslator\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mto_qasm\u001b[49m\u001b[43m(\u001b[49m\u001b[43mcircuit\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mversion\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mqasm_version\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 25\u001b[0m compiled_qasm, gate_counts \u001b[38;5;241m=\u001b[39m UCCTranspiler\u001b[38;5;241m.\u001b[39mtranspile(qasm_code, mode\u001b[38;5;241m=\u001b[39mmode, draw\u001b[38;5;241m=\u001b[39mdraw, get_gate_counts\u001b[38;5;241m=\u001b[39mget_gate_counts)\n\u001b[1;32m 26\u001b[0m \u001b[38;5;66;03m# print(compiled_qasm)\u001b[39;00m\n", - "File \u001b[0;32m~/ucc/custom_compiler_experiments/../ucc/quantum_translator/quantum_translator.py:62\u001b[0m, in \u001b[0;36mQuantumTranslator.to_qasm\u001b[0;34m(cls, circuit, version)\u001b[0m\n\u001b[1;32m 60\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m TKETInterface\u001b[38;5;241m.\u001b[39mto_qasm(circuit)\n\u001b[1;32m 61\u001b[0m \u001b[38;5;28;01mcase\u001b[39;00m \u001b[38;5;124m'\u001b[39m\u001b[38;5;124mqiskit\u001b[39m\u001b[38;5;124m'\u001b[39m:\n\u001b[0;32m---> 62\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[43mQiskitInterface\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mto_qasm\u001b[49m\u001b[43m(\u001b[49m\u001b[43mcircuit\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mversion\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 63\u001b[0m \u001b[38;5;28;01mcase\u001b[39;00m \u001b[38;5;124m'\u001b[39m\u001b[38;5;124mcirq\u001b[39m\u001b[38;5;124m'\u001b[39m:\n\u001b[1;32m 64\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m CirqInterface\u001b[38;5;241m.\u001b[39mto_qasm(circuit)\n", - "File \u001b[0;32m~/ucc/custom_compiler_experiments/../ucc/quantum_translator/interfaces/qiskit_interface.py:8\u001b[0m, in \u001b[0;36mQiskitInterface.to_qasm\u001b[0;34m(circuit, version)\u001b[0m\n\u001b[1;32m 6\u001b[0m \u001b[38;5;250m\u001b[39m\u001b[38;5;124;03m\"\"\"Translates a Qiskit circuit to OpenQASM string of the version specified.\"\"\"\u001b[39;00m\n\u001b[1;32m 7\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m version \u001b[38;5;241m==\u001b[39m \u001b[38;5;124m'\u001b[39m\u001b[38;5;124m2\u001b[39m\u001b[38;5;124m'\u001b[39m:\n\u001b[0;32m----> 8\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[43mqasm2\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mdumps\u001b[49m\u001b[43m(\u001b[49m\u001b[43mcircuit\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 9\u001b[0m \u001b[38;5;28;01melif\u001b[39;00m version \u001b[38;5;241m==\u001b[39m\u001b[38;5;124m'\u001b[39m\u001b[38;5;124m3\u001b[39m\u001b[38;5;124m'\u001b[39m:\n\u001b[1;32m 10\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m qasm3\u001b[38;5;241m.\u001b[39mdumps(circuit)\n", - "File \u001b[0;32m~/qiskit/qiskit/qasm2/export.py:138\u001b[0m, in \u001b[0;36mdumps\u001b[0;34m(circuit)\u001b[0m\n\u001b[1;32m 126\u001b[0m \u001b[38;5;250m\u001b[39m\u001b[38;5;124;03m\"\"\"Export a circuit to an OpenQASM 2 program in a string.\u001b[39;00m\n\u001b[1;32m 127\u001b[0m \n\u001b[1;32m 128\u001b[0m \u001b[38;5;124;03mArgs:\u001b[39;00m\n\u001b[0;32m (...)\u001b[0m\n\u001b[1;32m 135\u001b[0m \u001b[38;5;124;03m QASM2ExportError: if the circuit cannot be represented by OpenQASM 2.\u001b[39;00m\n\u001b[1;32m 136\u001b[0m \u001b[38;5;124;03m\"\"\"\u001b[39;00m\n\u001b[1;32m 137\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m circuit\u001b[38;5;241m.\u001b[39mnum_parameters \u001b[38;5;241m>\u001b[39m \u001b[38;5;241m0\u001b[39m:\n\u001b[0;32m--> 138\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m QASM2ExportError(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mCannot represent circuits with unbound parameters in OpenQASM 2.\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n\u001b[1;32m 140\u001b[0m \u001b[38;5;66;03m# Mapping of instruction name to a pair of the source for a definition, and an OQ2 string\u001b[39;00m\n\u001b[1;32m 141\u001b[0m \u001b[38;5;66;03m# that includes the `gate` or `opaque` statement that defines the gate.\u001b[39;00m\n\u001b[1;32m 142\u001b[0m gates_to_define: collections\u001b[38;5;241m.\u001b[39mOrderedDict[\u001b[38;5;28mstr\u001b[39m, \u001b[38;5;28mtuple\u001b[39m[Instruction, \u001b[38;5;28mstr\u001b[39m]] \u001b[38;5;241m=\u001b[39m (\n\u001b[1;32m 143\u001b[0m collections\u001b[38;5;241m.\u001b[39mOrderedDict()\n\u001b[1;32m 144\u001b[0m )\n", - "\u001b[0;31mQASM2ExportError\u001b[0m: 'Cannot represent circuits with unbound parameters in OpenQASM 2.'" - ] - } - ], + "outputs": [], "source": [ "from ucc import compile\n", "\n", - "ucc_qc, gate_counts = compile(pqc, mode=\"qiskit\", draw=False, get_gate_counts = True)" + "ucc_qc, gate_counts = compile(pqc, mode=\"qiskit\", get_gate_counts = True)" ] } ], diff --git a/custom_compiler_experiments/custom_compile_heisenberg_ring.ipynb b/custom_compiler_experiments/custom_compile_heisenberg_ring.ipynb index b35d3fae..84d05d67 100644 --- a/custom_compiler_experiments/custom_compile_heisenberg_ring.ipynb +++ b/custom_compiler_experiments/custom_compile_heisenberg_ring.ipynb @@ -16,7 +16,7 @@ }, { "cell_type": "code", - "execution_count": 129, + "execution_count": 17, "metadata": {}, "outputs": [], "source": [ @@ -35,7 +35,7 @@ }, { "cell_type": "code", - "execution_count": 130, + "execution_count": 18, "metadata": {}, "outputs": [ { @@ -90,7 +90,7 @@ }, { "cell_type": "code", - "execution_count": 131, + "execution_count": 19, "metadata": {}, "outputs": [], "source": [ @@ -108,7 +108,7 @@ }, { "cell_type": "code", - "execution_count": 132, + "execution_count": 20, "metadata": {}, "outputs": [], "source": [ @@ -124,17 +124,17 @@ }, { "cell_type": "code", - "execution_count": 133, + "execution_count": 21, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "Time taken: 0.39925265312194824\n", - "OrderedDict({'rz': 58, 'rx': 40, 'cx': 24, 'ry': 13})\n", + "Time taken: 0.5280048847198486\n", + "OrderedDict({'rz': 54, 'rx': 40, 'cx': 24, 'ry': 13})\n", "Number of 2-qubit gates: 24\n", - "Number of 1-qubit gates: 111\n" + "Number of 1-qubit gates: 107\n" ] } ], @@ -156,7 +156,7 @@ }, { "cell_type": "code", - "execution_count": 134, + "execution_count": 22, "metadata": {}, "outputs": [], "source": [ @@ -165,139 +165,17 @@ }, { "cell_type": "code", - "execution_count": 135, + "execution_count": 24, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "global phase: π\n", - " ┌─────────────┐ ┌──────────┐ ┌─────────┐ ┌────────────┐»\n", - "q_0: ┤ Rz(-2.7603) ├─┤ Ry(-π/2) ├──■────┤ Rz(π/2) ├──┤ Ry(3.0416) ├»\n", - " ├─────────────┤ ├─────────┬┘┌─┴─┐┌─┴─────────┴─┐├────────────┤»\n", - "q_1: ┤ Rz(-2.8003) ├─┤ Ry(π/2) ├─┤ X ├┤ Rz(-1.7398) ├┤ Ry(1.5798) ├»\n", - " ├─────────────┴┐├─────────┤ └───┘└─────────────┘└────────────┘»\n", - "q_2: ┤ Rz(0.072702) ├┤ Ry(π/2) ├───────────────────────────────────»\n", - " ├─────────────┬┘├─────────┴┐ »\n", - "q_3: ┤ Rz(-1.9201) ├─┤ Ry(-π/2) ├──────────────────────────────────»\n", - " ├─────────────┤ ├──────────┤ »\n", - "q_4: ┤ Rz(-1.7639) ├─┤ Ry(-π/2) ├──────────────────────────────────»\n", - " └─────────────┘ └──────────┘ »\n", - "« ┌──────────────┐┌─────────┐ »\n", - "«q_0: ────────────────■──┤ Ry(-0.41001) ├┤ Rz(π/2) ├────────────────────»\n", - "« ┌────────────┐┌─┴─┐├─────────────┬┘└┬────────┤ ┌─────────┐ »\n", - "«q_1: ┤ Rz(1.6768) ├┤ X ├┤ Rx(-0.0794) ├──┤ Rz(-π) ├──■────┤ Rz(π/2) ├──»\n", - "« └────────────┘└───┘└─────────────┘ └────────┘┌─┴─┐┌─┴─────────┴─┐»\n", - "«q_2: ──────────────────────────────────────────────┤ X ├┤ Rz(-1.7398) ├»\n", - "« └───┘└─────────────┘»\n", - "«q_3: ──────────────────────────────────────────────────────────────────»\n", - "« »\n", - "«q_4: ──────────────────────────────────────────────────────────────────»\n", - "« »\n", - "« »\n", - "«q_0: ────────────────────────────────────────────────────────────»\n", - "« ┌────────────┐ ┌─────────────┐┌──────────┐»\n", - "«q_1: ┤ Ry(3.0416) ├────────────────■──┤ Ry(-1.1119) ├┤ Rz(-π/2) ├»\n", - "« ├────────────┤┌────────────┐┌─┴─┐└┬───────────┬┘└──────────┘»\n", - "«q_2: ┤ Ry(1.5798) ├┤ Rz(1.6768) ├┤ X ├─┤ Rx(3.055) ├──────■──────»\n", - "« └────────────┘└────────────┘└───┘ └───────────┘ ┌─┴─┐ »\n", - "«q_3: ───────────────────────────────────────────────────┤ X ├────»\n", - "« └───┘ »\n", - "«q_4: ────────────────────────────────────────────────────────────»\n", - "« »\n", - "« ┌─────────┐ ┌────────────┐ »\n", - "«q_0: ───────■─────────┤ Rz(π/2) ├──┤ Ry(3.0416) ├─────────────────────■───────»\n", - "« ┌─┴─┐ ┌─┴─────────┴─┐├────────────┤┌────────────┐ ┌─┴─┐ »\n", - "«q_1: ─────┤ X ├─────┤ Rz(-1.7398) ├┤ Ry(1.5798) ├┤ Rz(1.6768) ├─────┤ X ├─────»\n", - "« ┌──┴───┴──┐ └┬────────────┤└────────────┘└────────────┘┌────┴───┴────┐»\n", - "«q_2: ──┤ Rz(π/2) ├───┤ Ry(3.0416) ├────────────────────■───────┤ Ry(0.28668) ├»\n", - "« ┌─┴─────────┴─┐ ├────────────┤┌────────────┐ ┌─┴─┐ └──┬────────┬─┘»\n", - "«q_3: ┤ Rz(-1.7398) ├─┤ Ry(1.5798) ├┤ Rz(1.6768) ├────┤ X ├────────┤ Rz(-π) ├──»\n", - "« └─────────────┘ └────────────┘└────────────┘ └───┘ └────────┘ »\n", - "«q_4: ─────────────────────────────────────────────────────────────────────────»\n", - "« »\n", - "« ┌─────────────┐┌─────────┐ »\n", - "«q_0: ┤ Ry(-2.6443) ├┤ Rz(π/2) ├───────────────────────────────────────────»\n", - "« └┬────────────┤└─────────┘ ┌─────────┐ ┌────────────┐ »\n", - "«q_1: ─┤ Rx(1.6156) ├─────■───────┤ Rz(π/2) ├──┤ Ry(3.0416) ├──────────────»\n", - "« └┬──────────┬┘ ┌─┴─┐ ┌─┴─────────┴─┐├────────────┤┌────────────┐»\n", - "«q_2: ──┤ Rz(-π/2) ├────┤ X ├───┤ Rz(-1.7398) ├┤ Ry(1.5798) ├┤ Rz(1.6768) ├»\n", - "« ┌─┴──────────┴┐ └───┘ └─┬─────────┬─┘├────────────┤└────────────┘»\n", - "«q_3: ┤ Rx(-1.2056) ├─────■───────┤ Rz(π/2) ├──┤ Ry(3.0416) ├──────────────»\n", - "« └─────────────┘ ┌─┴─┐ ┌─┴─────────┴─┐├────────────┤┌────────────┐»\n", - "«q_4: ──────────────────┤ X ├───┤ Rz(-1.7398) ├┤ Ry(1.5798) ├┤ Rz(1.6768) ├»\n", - "« └───┘ └─────────────┘└────────────┘└────────────┘»\n", - "« ┌─────────┐ ┌────────────┐»\n", - "«q_0: ─────────────────────────────────■────┤ Rz(π/2) ├──┤ Ry(3.0416) ├»\n", - "« ┌─────────────┐┌─────────┐┌─┴─┐┌─┴─────────┴─┐├────────────┤»\n", - "«q_1: ──■──┤ Ry(0.39406) ├┤ Rz(π/2) ├┤ X ├┤ Rz(-1.7398) ├┤ Ry(1.5798) ├»\n", - "« ┌─┴─┐└┬────────────┤└─────────┘└───┘└─┬─────────┬─┘├────────────┤»\n", - "«q_2: ┤ X ├─┤ Rx(2.2941) ├─────────────■────┤ Rz(π/2) ├──┤ Ry(3.0416) ├»\n", - "« └───┘ ├────────────┤┌─────────┐┌─┴─┐┌─┴─────────┴─┐├────────────┤»\n", - "«q_3: ──■───┤ Ry(1.1621) ├┤ Rz(π/2) ├┤ X ├┤ Rz(-1.7398) ├┤ Ry(1.5798) ├»\n", - "« ┌─┴─┐┌┴────────────┤└─────────┘└───┘└─────────────┘└────────────┘»\n", - "«q_4: ┤ X ├┤ Rx(-1.5872) ├─────────────────────────────────────────────»\n", - "« └───┘└─────────────┘ »\n", - "« ┌─────────┐ ┌──────────┐ »\n", - "«q_0: ────────────────■────┤ Rz(π/2) ├────┤ Ry(-π/2) ├─────────────────────»\n", - "« ┌────────────┐┌─┴─┐┌─┴─────────┴──┐ └┬────────┬┘ ┌─────────┐ »\n", - "«q_1: ┤ Rz(1.6768) ├┤ X ├┤ Rx(-0.27119) ├──┤ Rz(-π) ├────■────┤ Rz(π/2) ├──»\n", - "« └────────────┘└───┘├─────────────┬┘ ┌┴────────┴┐ ┌─┴─┐┌─┴─────────┴─┐»\n", - "«q_2: ────────────────■──┤ Ry(-2.9317) ├──┤ Rz(-π/2) ├─┤ X ├┤ Rz(-1.7398) ├»\n", - "« ┌────────────┐┌─┴─┐└──┬────────┬─┘ ┌┴──────────┴┐└───┘└─┬─────────┬─┘»\n", - "«q_3: ┤ Rz(1.6768) ├┤ X ├───┤ Rz(-π) ├───┤ Rx(-1.982) ├──■────┤ Rz(π/2) ├──»\n", - "« └────────────┘└───┘ └────────┘ └────────────┘┌─┴─┐┌─┴─────────┴─┐»\n", - "«q_4: ─────────────────────────────────────────────────┤ X ├┤ Rz(-1.7398) ├»\n", - "« └───┘└─────────────┘»\n", - "« »\n", - "«q_0: ────────────────────────────────────────────────────────────────»\n", - "« ┌────────────┐ ┌──────────┐ ┌─────────┐ »\n", - "«q_1: ┤ Ry(3.0416) ├────────────────■────┤ Rz(-π/2) ├─┤ Ry(π/2) ├─────»\n", - "« ├────────────┤┌────────────┐┌─┴─┐┌─┴──────────┴┐└─────────┘ »\n", - "«q_2: ┤ Ry(1.5798) ├┤ Rz(1.6768) ├┤ X ├┤ Rx(-0.3436) ├─────────────■──»\n", - "« ├────────────┤└────────────┘└───┘└┬────────────┤┌─────────┐┌─┴─┐»\n", - "«q_3: ┤ Ry(3.0416) ├────────────────■───┤ Ry(1.0461) ├┤ Rz(π/2) ├┤ X ├»\n", - "« ├────────────┤┌────────────┐┌─┴─┐┌┴────────────┤└─────────┘└───┘»\n", - "«q_4: ┤ Ry(1.5798) ├┤ Rz(1.6768) ├┤ X ├┤ Rx(-1.7353) ├────────────────»\n", - "« └────────────┘└────────────┘└───┘└─────────────┘ »\n", - "« »\n", - "«q_0: ────────────────────────────────────────────────────────────»\n", - "« »\n", - "«q_1: ────────────────────────────────────────────────────────────»\n", - "« ┌─────────┐ ┌────────────┐ ┌──────────┐»\n", - "«q_2: ──┤ Rz(π/2) ├──┤ Ry(3.0416) ├────────────────■──┤ Rz(-π/2) ├»\n", - "« ┌─┴─────────┴─┐├────────────┤┌────────────┐┌─┴─┐└┬────────┬┘»\n", - "«q_3: ┤ Rz(-1.7398) ├┤ Ry(1.5798) ├┤ Rz(1.6768) ├┤ X ├─┤ Rz(-π) ├─»\n", - "« └─────────────┘└────────────┘└────────────┘└───┘ └────────┘ »\n", - "«q_4: ────────────────────────────────────────────────────────────»\n", - "« »\n", - "« »\n", - "«q_0: ────────────────────────────────────────────────────────────────────»\n", - "« »\n", - "«q_1: ────────────────────────────────────────────────────────────────────»\n", - "« ┌──────────┐ »\n", - "«q_2: ──┤ Ry(-π/2) ├──────────────────────────────────────────────────────»\n", - "« ┌─┴──────────┴┐ ┌─────────┐ ┌────────────┐ »\n", - "«q_3: ┤ Rx(-1.8913) ├──■────┤ Rz(π/2) ├──┤ Ry(3.0416) ├────────────────■──»\n", - "« └─────────────┘┌─┴─┐┌─┴─────────┴─┐├────────────┤┌────────────┐┌─┴─┐»\n", - "«q_4: ───────────────┤ X ├┤ Rz(-1.7398) ├┤ Ry(1.5798) ├┤ Rz(1.6768) ├┤ X ├»\n", - "« └───┘└─────────────┘└────────────┘└────────────┘└───┘»\n", - "« \n", - "«q_0: ───────────────────────────\n", - "« \n", - "«q_1: ───────────────────────────\n", - "« \n", - "«q_2: ───────────────────────────\n", - "« ┌──────────┐ ┌──────────┐ \n", - "«q_3: ┤ Rz(-π/2) ├──┤ Ry(-π/2) ├─\n", - "« ├─────────┬┘┌─┴──────────┴┐\n", - "«q_4: ┤ Ry(π/2) ├─┤ Rz(-2.1322) ├\n", - "« └─────────┘ └─────────────┘\n", - "Time taken: 0.13929533958435059\n", - "OrderedDict({'rz': 59, 'ry': 42, 'cx': 24, 'rx': 11})\n", + "Time taken: 0.19528555870056152\n", + "OrderedDict({'rz': 63, 'ry': 42, 'cx': 24, 'rx': 11})\n", "Number of 2-qubit gates: 24\n", - "Number of 1-qubit gates: 112\n" + "Number of 1-qubit gates: 116\n" ] } ], @@ -310,7 +188,7 @@ "from ucc import compile\n", "\n", "t1 = time.time()\n", - "ucc_qc, gate_counts = compile(qc, mode=\"ucc\", draw=False, get_gate_counts = True)\n", + "ucc_qc, gate_counts = compile(qc, mode=\"ucc\", get_gate_counts = True)\n", "t2 = time.time()\n", "print(\"Time taken: \", t2-t1)\n", "\n", @@ -329,7 +207,7 @@ }, { "cell_type": "code", - "execution_count": 136, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -358,7 +236,7 @@ }, { "cell_type": "code", - "execution_count": 137, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ diff --git a/custom_compiler_experiments/custom_compile_qcnn.ipynb b/custom_compiler_experiments/custom_compile_qcnn.ipynb index 48c7eef9..10c7020b 100644 --- a/custom_compiler_experiments/custom_compile_qcnn.ipynb +++ b/custom_compiler_experiments/custom_compile_qcnn.ipynb @@ -16,7 +16,7 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": 23, "metadata": {}, "outputs": [], "source": [ @@ -35,7 +35,7 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": 24, "metadata": {}, "outputs": [], "source": [ @@ -64,53 +64,53 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 25, "metadata": {}, "outputs": [ { "data": { "text/html": [ - "
     ┌───────────────┐┌─────────────┐                                »\n",
-       "q_0: ┤0              ├┤ Ry(0.72996) ├────────────────────────────────»\n",
-       "     │  Rxx(0.67581) │├─────────────┤┌───────────────┐ ┌────────────┐»\n",
-       "q_1: ┤1              ├┤ Ry(0.68052) ├┤0              ├─┤ Ry(0.5245) ├»\n",
-       "     ├───────────────┤├─────────────┤│  Rxx(0.86189) │┌┴────────────┤»\n",
-       "q_2: ┤0              ├┤ Ry(0.60573) ├┤1              ├┤ Ry(0.98939) ├»\n",
-       "     │  Rxx(0.75475) │├─────────────┤└───────────────┘└─────────────┘»\n",
-       "q_3: ┤1              ├┤ Ry(0.22804) ├────────────────────────────────»\n",
-       "     └───────────────┘└─────────────┘                                »\n",
+       "
     ┌───────────────┐ ┌─────────────┐                                »\n",
+       "q_0: ┤0              ├─┤ Ry(0.33251) ├────────────────────────────────»\n",
+       "     │  Rxx(0.16964) │ ├─────────────┤┌───────────────┐┌─────────────┐»\n",
+       "q_1: ┤1              ├─┤ Ry(0.59386) ├┤0              ├┤ Ry(0.63625) ├»\n",
+       "     ├───────────────┴┐├─────────────┤│  Rxx(0.71598) │├─────────────┤»\n",
+       "q_2: ┤0               ├┤ Ry(0.10413) ├┤1              ├┤ Ry(0.80983) ├»\n",
+       "     │  Rxx(0.031875) │├─────────────┤└───────────────┘└─────────────┘»\n",
+       "q_3: ┤1               ├┤ Ry(0.81302) ├────────────────────────────────»\n",
+       "     └────────────────┘└─────────────┘                                »\n",
        "«     ┌───────────────┐┌─────────────┐\n",
-       "«q_0: ┤0              ├┤ Ry(0.15795) ├\n",
+       "«q_0: ┤0              ├┤ Ry(0.88238) ├\n",
        "«     │               │└─────────────┘\n",
-       "«q_1: ┤  Rxx(0.11414) ├───────────────\n",
+       "«q_1: ┤  Rxx(0.29288) ├───────────────\n",
        "«     │               │┌─────────────┐\n",
-       "«q_2: ┤1              ├┤ Ry(0.11914) ├\n",
+       "«q_2: ┤1              ├┤ Ry(0.15394) ├\n",
        "«     └───────────────┘└─────────────┘\n",
        "«q_3: ────────────────────────────────\n",
        "«                                     
" ], "text/plain": [ - " ┌───────────────┐┌─────────────┐ »\n", - "q_0: ┤0 ├┤ Ry(0.72996) ├────────────────────────────────»\n", - " │ Rxx(0.67581) │├─────────────┤┌───────────────┐ ┌────────────┐»\n", - "q_1: ┤1 ├┤ Ry(0.68052) ├┤0 ├─┤ Ry(0.5245) ├»\n", - " ├───────────────┤├─────────────┤│ Rxx(0.86189) │┌┴────────────┤»\n", - "q_2: ┤0 ├┤ Ry(0.60573) ├┤1 ├┤ Ry(0.98939) ├»\n", - " │ Rxx(0.75475) │├─────────────┤└───────────────┘└─────────────┘»\n", - "q_3: ┤1 ├┤ Ry(0.22804) ├────────────────────────────────»\n", - " └───────────────┘└─────────────┘ »\n", + " ┌───────────────┐ ┌─────────────┐ »\n", + "q_0: ┤0 ├─┤ Ry(0.33251) ├────────────────────────────────»\n", + " │ Rxx(0.16964) │ ├─────────────┤┌───────────────┐┌─────────────┐»\n", + "q_1: ┤1 ├─┤ Ry(0.59386) ├┤0 ├┤ Ry(0.63625) ├»\n", + " ├───────────────┴┐├─────────────┤│ Rxx(0.71598) │├─────────────┤»\n", + "q_2: ┤0 ├┤ Ry(0.10413) ├┤1 ├┤ Ry(0.80983) ├»\n", + " │ Rxx(0.031875) │├─────────────┤└───────────────┘└─────────────┘»\n", + "q_3: ┤1 ├┤ Ry(0.81302) ├────────────────────────────────»\n", + " └────────────────┘└─────────────┘ »\n", "« ┌───────────────┐┌─────────────┐\n", - "«q_0: ┤0 ├┤ Ry(0.15795) ├\n", + "«q_0: ┤0 ├┤ Ry(0.88238) ├\n", "« │ │└─────────────┘\n", - "«q_1: ┤ Rxx(0.11414) ├───────────────\n", + "«q_1: ┤ Rxx(0.29288) ├───────────────\n", "« │ │┌─────────────┐\n", - "«q_2: ┤1 ├┤ Ry(0.11914) ├\n", + "«q_2: ┤1 ├┤ Ry(0.15394) ├\n", "« └───────────────┘└─────────────┘\n", "«q_3: ────────────────────────────────\n", "« " ] }, - "execution_count": 3, + "execution_count": 25, "metadata": {}, "output_type": "execute_result" } @@ -128,7 +128,7 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": 26, "metadata": {}, "outputs": [], "source": [ @@ -146,17 +146,17 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": 27, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "Time taken: 0.05444645881652832\n", - "OrderedDict({'rz': 18, 'rx': 10, 'cx': 8, 'ry': 2})\n", + "Time taken: 0.10510921478271484\n", + "OrderedDict({'rz': 16, 'rx': 8, 'cx': 8, 'ry': 4})\n", "Number of 2-qubit gates: 8\n", - "Number of 1-qubit gates: 30\n" + "Number of 1-qubit gates: 28\n" ] } ], @@ -178,52 +178,9 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": 28, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - " ┌─────────┐ ┌─────────┐ ┌─────────┐ ┌───┐┌─────────────┐»\n", - "q_1 -> 0 ┤ Rz(π/2) ├─┤ Rx(π/2) ├─┤ Rz(π/2) ├───────────────┤ X ├┤ Rz(0.67581) ├»\n", - " ├─────────┴┐├─────────┴┐└─────────┘ └─┬─┘└─────────────┘»\n", - "q_2 -> 1 ┤ Rz(-π/2) ├┤ Rx(-π/2) ├─────■──────────────────────┼─────────■───────»\n", - " ├──────────┤└┬────────┬┘ ┌─┴─┐ ┌─────────────┐ │ ┌─┴─┐ »\n", - "q_3 -> 2 ┤ Ry(-π/2) ├─┤ Rz(-π) ├────┤ X ├───┤ Rz(0.75475) ├──┼───────┤ X ├─────»\n", - " ├──────────┤┌┴────────┴┐ └───┘ └─────────────┘ │ └───┘ »\n", - "q_0 -> 3 ┤ Rz(-π/2) ├┤ Rx(-π/2) ├────────────────────────────■─────────────────»\n", - " └──────────┘└──────────┘ »\n", - "« ┌───┐ ┌─────────┐ ┌─────────────┐ »\n", - "«q_1 -> 0 ───────────────┤ X ├──┤ Rz(π/2) ├──┤ Rx(0.68052) ├──■──»\n", - "« ┌─────────────┐└─┬─┘ ├─────────┴┐ └─────────────┘┌─┴─┐»\n", - "«q_2 -> 1 ┤ Rx(0.60573) ├──┼────┤ Rz(-π/2) ├────────────────┤ X ├»\n", - "« ├─────────────┤ │ └┬────────┬┘ └───┘»\n", - "«q_3 -> 2 ┤ Ry(-1.7988) ├──┼─────┤ Rz(-π) ├──────────────────────»\n", - "« └─────────────┘ │ ┌──┴────────┴─┐ »\n", - "«q_0 -> 3 ─────────────────■──┤ Rx(0.72996) ├────────────────────»\n", - "« └─────────────┘ »\n", - "« ┌────────────┐ ┌─────────┐ »\n", - "«q_1 -> 0 ─────────────────■──┤ Rx(2.0953) ├──┤ Rz(π/2) ├───────────────────»\n", - "« ┌─────────────┐┌─┴─┐└┬─────────┬─┘┌─┴─────────┴─┐┌──────────┐┌───┐»\n", - "«q_2 -> 1 ┤ Rz(0.86189) ├┤ X ├─┤ Rz(π/2) ├──┤ Rx(0.98939) ├┤ Rz(-π/2) ├┤ X ├»\n", - "« └─────────────┘└───┘ └─────────┘ └─────────────┘└──────────┘└─┬─┘»\n", - "«q_3 -> 2 ───────────────────────────────────────────────────────────────┼──»\n", - "« │ »\n", - "«q_0 -> 3 ───────────────────────────────────────────────────────────────■──»\n", - "« »\n", - "« \n", - "«q_1 -> 0 ───────────────────────────────────────────────────────────\n", - "« ┌─────────────┐┌───┐ ┌─────────┐ ┌────────────┐┌─────────┐\n", - "«q_2 -> 1 ┤ Rz(0.11414) ├┤ X ├─┤ Rz(π/2) ├──┤ Rx(1.6899) ├┤ Rz(π/2) ├\n", - "« └─────────────┘└─┬─┘ └─────────┘ └────────────┘└─────────┘\n", - "«q_3 -> 2 ─────────────────┼─────────────────────────────────────────\n", - "« │ ┌────────────┐ ┌─────────┐ \n", - "«q_0 -> 3 ─────────────────■──┤ Rx(1.7288) ├─┤ Rz(π/2) ├─────────────\n", - "« └────────────┘ └─────────┘ \n" - ] - } - ], + "outputs": [], "source": [ "# print(default_qc)" ] @@ -237,44 +194,17 @@ }, { "cell_type": "code", - "execution_count": 10, + "execution_count": 30, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - " ┌──────────┐┌────────┐ ┌──────────────┐ »\n", - "q_0: ┤ Ry(-π/2) ├┤ Rz(-π) ├──■───────────────────■──┤ Ry(-0.72996) ├──────────»\n", - " ├──────────┤├────────┤┌─┴─┐┌─────────────┐┌─┴─┐├──────────────┤ »\n", - "q_1: ┤ Ry(-π/2) ├┤ Rz(-π) ├┤ X ├┤ Rz(0.67581) ├┤ X ├┤ Ry(-0.68052) ├────■─────»\n", - " ├──────────┤├────────┤└───┘└─────────────┘└───┘├──────────────┤ ┌─┴─┐ »\n", - "q_2: ┤ Ry(-π/2) ├┤ Rz(-π) ├──■───────────────────■──┤ Ry(-0.60573) ├──┤ X ├───»\n", - " ├──────────┤├────────┤┌─┴─┐┌─────────────┐┌─┴─┐├─────────────┬┘┌─┴───┴──┐»\n", - "q_3: ┤ Ry(-π/2) ├┤ Rz(-π) ├┤ X ├┤ Rz(0.75475) ├┤ X ├┤ Ry(-1.7988) ├─┤ Rz(-π) ├»\n", - " └──────────┘└────────┘└───┘└─────────────┘└───┘└─────────────┘ └────────┘»\n", - "« »\n", - "«q_0: ────────────────────────────────────────────────■───────────────────■──»\n", - "« ┌─────────────┐ ┌────────┐ │ │ »\n", - "«q_1: ─────────────────■──┤ Ry(-2.0953) ├─┤ Rz(-π) ├──┼───────────────────┼──»\n", - "« ┌─────────────┐┌─┴─┐├─────────────┴┐└────────┘┌─┴─┐┌─────────────┐┌─┴─┐»\n", - "«q_2: ┤ Rz(0.86189) ├┤ X ├┤ Ry(-0.98939) ├──────────┤ X ├┤ Rz(0.11414) ├┤ X ├»\n", - "« └─────────────┘└───┘└──────────────┘ └───┘└─────────────┘└───┘»\n", - "«q_3: ───────────────────────────────────────────────────────────────────────»\n", - "« »\n", - "« ┌─────────────┐┌────────┐\n", - "«q_0: ┤ Ry(-1.7288) ├┤ Rz(-π) ├\n", - "« └─────────────┘└────────┘\n", - "«q_1: ─────────────────────────\n", - "« ┌─────────────┐┌────────┐\n", - "«q_2: ┤ Ry(-1.6899) ├┤ Rz(-π) ├\n", - "« └─────────────┘└────────┘\n", - "«q_3: ─────────────────────────\n", - "« \n", - "Time taken: 0.043344974517822266\n", - "OrderedDict({'ry': 12, 'rz': 12, 'cx': 8})\n", + "Time taken: 0.07597589492797852\n", + "OrderedDict({'rz': 31, 'ry': 23, 'cx': 8})\n", "Number of 2-qubit gates: 8\n", - "Number of 1-qubit gates: 24\n" + "Number of 1-qubit gates: 54\n" ] } ], @@ -286,7 +216,7 @@ "from ucc import compile\n", "\n", "t1 = time.time()\n", - "ucc_qc, gate_counts = compile(qc, mode=\"ucc\", draw=False, get_gate_counts = True)\n", + "ucc_qc, gate_counts = compile(qc, mode=\"ucc\", get_gate_counts = True)\n", "t2 = time.time()\n", "print(\"Time taken: \", t2-t1)\n", "\n", @@ -305,7 +235,7 @@ }, { "cell_type": "code", - "execution_count": 8, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -330,7 +260,7 @@ }, { "cell_type": "code", - "execution_count": 9, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ diff --git a/custom_compiler_experiments/custom_compile_qft.ipynb b/custom_compiler_experiments/custom_compile_qft.ipynb index 18bd6600..be06319a 100644 --- a/custom_compiler_experiments/custom_compile_qft.ipynb +++ b/custom_compiler_experiments/custom_compile_qft.ipynb @@ -2,7 +2,7 @@ "cells": [ { "cell_type": "code", - "execution_count": 1, + "execution_count": 44, "metadata": {}, "outputs": [], "source": [ @@ -15,7 +15,7 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": 45, "metadata": {}, "outputs": [], "source": [ @@ -42,16 +42,24 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 46, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[[0, 2], [1, 3], [0, 1], [2, 4], [3, 5], [2, 3], [4, 6], [5, 7], [4, 5], [6, 7]]\n" + ] + } + ], "source": [ "print(coupling_map)" ] }, { "cell_type": "code", - "execution_count": 4, + "execution_count": 47, "metadata": {}, "outputs": [], "source": [ @@ -66,7 +74,7 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": 48, "metadata": {}, "outputs": [], "source": [ @@ -82,9 +90,20 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 49, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Time taken: 0.5353250503540039\n", + "OrderedDict({'rz': 127, 'cx': 84, 'rx': 39, 'ry': 34, 'h': 27})\n", + "Number of 2-qubit gates: 84\n", + "Number of 1-qubit gates: 227\n" + ] + } + ], "source": [ "from qiskit.transpiler.preset_passmanagers import generate_preset_pass_manager\n", "default_pm = generate_preset_pass_manager(backend=line_backend, optimization_level=3)\n", @@ -112,7 +131,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 50, "metadata": {}, "outputs": [], "source": [ @@ -132,7 +151,7 @@ }, { "cell_type": "code", - "execution_count": 8, + "execution_count": 51, "metadata": {}, "outputs": [], "source": [ @@ -147,23 +166,17 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": 52, "metadata": {}, "outputs": [ { - "ename": "TypeError", - "evalue": "CommutationAnalysis.__init__() got an unexpected keyword argument 'standard_gates'", - "output_type": "error", - "traceback": [ - "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", - "\u001b[0;31mTypeError\u001b[0m Traceback (most recent call last)", - "Cell \u001b[0;32mIn[1], line 7\u001b[0m\n\u001b[1;32m 3\u001b[0m sys\u001b[38;5;241m.\u001b[39mpath\u001b[38;5;241m.\u001b[39mappend(\u001b[38;5;124m'\u001b[39m\u001b[38;5;124m../\u001b[39m\u001b[38;5;124m'\u001b[39m)\n\u001b[1;32m 5\u001b[0m \u001b[38;5;28;01mimport\u001b[39;00m \u001b[38;5;21;01mucc\u001b[39;00m\u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01mtranspilers\u001b[39;00m\u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01mucc_defaults\u001b[39;00m \u001b[38;5;28;01mas\u001b[39;00m \u001b[38;5;21;01mucc_defaults\u001b[39;00m\n\u001b[0;32m----> 7\u001b[0m ucc_transpiler \u001b[38;5;241m=\u001b[39m \u001b[43mucc_defaults\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mUCCDefault1\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 8\u001b[0m t1 \u001b[38;5;241m=\u001b[39m time\u001b[38;5;241m.\u001b[39mtime()\n\u001b[1;32m 9\u001b[0m ucc_qc \u001b[38;5;241m=\u001b[39m ucc_transpiler\u001b[38;5;241m.\u001b[39mrun(qc)\n", - "File \u001b[0;32m~/ucc/custom_compiler_experiments/../ucc/transpilers/ucc_defaults.py:21\u001b[0m, in \u001b[0;36mUCCDefault1.__init__\u001b[0;34m(self, local_iterations)\u001b[0m\n\u001b[1;32m 14\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mtarget_basis \u001b[38;5;241m=\u001b[39m [\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mrz\u001b[39m\u001b[38;5;124m'\u001b[39m, \u001b[38;5;124m'\u001b[39m\u001b[38;5;124mrx\u001b[39m\u001b[38;5;124m'\u001b[39m, \u001b[38;5;124m'\u001b[39m\u001b[38;5;124mry\u001b[39m\u001b[38;5;124m'\u001b[39m, \u001b[38;5;124m'\u001b[39m\u001b[38;5;124mh\u001b[39m\u001b[38;5;124m'\u001b[39m, \u001b[38;5;124m'\u001b[39m\u001b[38;5;124mcx\u001b[39m\u001b[38;5;124m'\u001b[39m]\n\u001b[1;32m 15\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mspecial_commutations \u001b[38;5;241m=\u001b[39m {\n\u001b[1;32m 16\u001b[0m (\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mrx\u001b[39m\u001b[38;5;124m\"\u001b[39m, \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mcx\u001b[39m\u001b[38;5;124m\"\u001b[39m): {\n\u001b[1;32m 17\u001b[0m (\u001b[38;5;241m0\u001b[39m,): \u001b[38;5;28;01mFalse\u001b[39;00m,\n\u001b[1;32m 18\u001b[0m (\u001b[38;5;241m1\u001b[39m,): \u001b[38;5;28;01mTrue\u001b[39;00m,\n\u001b[1;32m 19\u001b[0m },\n\u001b[1;32m 20\u001b[0m }\n\u001b[0;32m---> 21\u001b[0m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43madd_local_passes\u001b[49m\u001b[43m(\u001b[49m\u001b[43mlocal_iterations\u001b[49m\u001b[43m)\u001b[49m\n", - "File \u001b[0;32m~/ucc/custom_compiler_experiments/../ucc/transpilers/ucc_defaults.py:29\u001b[0m, in \u001b[0;36mUCCDefault1.add_local_passes\u001b[0;34m(self, local_iterations)\u001b[0m\n\u001b[1;32m 26\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mpass_manager\u001b[38;5;241m.\u001b[39mappend(BasisTranslator(sel, target_basis\u001b[38;5;241m=\u001b[39m\u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mtarget_basis)) \n\u001b[1;32m 27\u001b[0m \u001b[38;5;66;03m# self.pass_manager.append(Optimize1qGates())\u001b[39;00m\n\u001b[1;32m 28\u001b[0m \u001b[38;5;66;03m# self.pass_manager.append(CommutationAnalysis())\u001b[39;00m\n\u001b[0;32m---> 29\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mpass_manager\u001b[38;5;241m.\u001b[39mappend(\u001b[43mCommutativeCancellation\u001b[49m\u001b[43m(\u001b[49m\u001b[43mstandard_gates\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mtarget_basis\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mspecial_commutations\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mspecial_commutations\u001b[49m\u001b[43m)\u001b[49m)\n\u001b[1;32m 30\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mpass_manager\u001b[38;5;241m.\u001b[39mappend(Collect2qBlocks())\n\u001b[1;32m 31\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mpass_manager\u001b[38;5;241m.\u001b[39mappend(ConsolidateBlocks(force_consolidate\u001b[38;5;241m=\u001b[39m\u001b[38;5;28;01mTrue\u001b[39;00m))\n", - "File \u001b[0;32m~/qiskit/qiskit/transpiler/basepasses.py:51\u001b[0m, in \u001b[0;36mMetaPass.__call__\u001b[0;34m(cls, *args, **kwargs)\u001b[0m\n\u001b[1;32m 50\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21m__call__\u001b[39m(\u001b[38;5;28mcls\u001b[39m, \u001b[38;5;241m*\u001b[39margs, \u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39mkwargs):\n\u001b[0;32m---> 51\u001b[0m pass_instance \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;43mtype\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[38;5;21;43m__call__\u001b[39;49m\u001b[43m(\u001b[49m\u001b[38;5;28;43mcls\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43margs\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43mkwargs\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 52\u001b[0m pass_instance\u001b[38;5;241m.\u001b[39m_hash \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mhash\u001b[39m(MetaPass\u001b[38;5;241m.\u001b[39m_freeze_init_parameters(\u001b[38;5;28mcls\u001b[39m, args, kwargs))\n\u001b[1;32m 53\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m pass_instance\n", - "File \u001b[0;32m~/ucc/custom_compiler_experiments/../ucc/transpiler_passes/commutative_cancellation.py:65\u001b[0m, in \u001b[0;36mCommutativeCancellation.__init__\u001b[0;34m(self, basis_gates, target, standard_gates, special_commutations)\u001b[0m\n\u001b[1;32m 62\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mbasis \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mset\u001b[39m(target\u001b[38;5;241m.\u001b[39moperation_names)\n\u001b[1;32m 64\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_var_z_map \u001b[38;5;241m=\u001b[39m {\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mrz\u001b[39m\u001b[38;5;124m\"\u001b[39m: RZGate, \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mp\u001b[39m\u001b[38;5;124m\"\u001b[39m: PhaseGate, \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mu1\u001b[39m\u001b[38;5;124m\"\u001b[39m: U1Gate}\n\u001b[0;32m---> 65\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mrequires\u001b[38;5;241m.\u001b[39mappend(\u001b[43mCommutationAnalysis\u001b[49m\u001b[43m(\u001b[49m\u001b[43mstandard_gates\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mstandard_gates\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mspecial_commutations\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mspecial_commutations\u001b[49m\u001b[43m)\u001b[49m)\n", - "File \u001b[0;32m~/qiskit/qiskit/transpiler/basepasses.py:51\u001b[0m, in \u001b[0;36mMetaPass.__call__\u001b[0;34m(cls, *args, **kwargs)\u001b[0m\n\u001b[1;32m 50\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21m__call__\u001b[39m(\u001b[38;5;28mcls\u001b[39m, \u001b[38;5;241m*\u001b[39margs, \u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39mkwargs):\n\u001b[0;32m---> 51\u001b[0m pass_instance \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;43mtype\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[38;5;21;43m__call__\u001b[39;49m\u001b[43m(\u001b[49m\u001b[38;5;28;43mcls\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43margs\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43mkwargs\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 52\u001b[0m pass_instance\u001b[38;5;241m.\u001b[39m_hash \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mhash\u001b[39m(MetaPass\u001b[38;5;241m.\u001b[39m_freeze_init_parameters(\u001b[38;5;28mcls\u001b[39m, args, kwargs))\n\u001b[1;32m 53\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m pass_instance\n", - "\u001b[0;31mTypeError\u001b[0m: CommutationAnalysis.__init__() got an unexpected keyword argument 'standard_gates'" + "name": "stdout", + "output_type": "stream", + "text": [ + "Time taken: 0.14137697219848633\n", + "OrderedDict({'rz': 92, 'cx': 56, 'ry': 8})\n", + "Number of 2-qubit gates: 56\n", + "Number of 1-qubit gates: 100\n" ] } ], @@ -189,9 +202,187 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 53, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "global phase: 4.7185\n", + " ┌──────────┐┌────────┐┌───┐┌──────────┐┌───┐┌─────────┐ ┌───┐»\n", + "q_0: ─┤ Ry(-π/2) ├┤ Rz(-π) ├┤ X ├┤ Rz(-π/4) ├┤ X ├┤ Rz(π/4) ├───────────┤ X ├»\n", + " ├─────────┬┘└────────┘└─┬─┘└──────────┘└─┬─┘├─────────┴┐┌────────┐└─┬─┘»\n", + "q_1: ─┤ Rz(π/4) ├─────────────■────────────────■──┤ Ry(-π/2) ├┤ Rz(-π) ├──┼──»\n", + " ├─────────┤ └──────────┘└────────┘ │ »\n", + "q_2: ─┤ Rz(π/8) ├─────────────────────────────────────────────────────────■──»\n", + " ├─────────┴┐ »\n", + "q_3: ─┤ Rz(π/16) ├───────────────────────────────────────────────────────────»\n", + " ├──────────┤ »\n", + "q_4: ─┤ Rz(π/32) ├───────────────────────────────────────────────────────────»\n", + " ├──────────┤ »\n", + "q_5: ─┤ Rz(π/64) ├───────────────────────────────────────────────────────────»\n", + " ┌┴──────────┤ »\n", + "q_6: ┤ Rz(π/128) ├───────────────────────────────────────────────────────────»\n", + " ├───────────┤ »\n", + "q_7: ┤ Rz(π/256) ├───────────────────────────────────────────────────────────»\n", + " └───────────┘ »\n", + "« ┌──────────┐┌───┐┌─────────┐ ┌───┐┌───────────┐ ┌───┐┌──────────┐»\n", + "«q_0: ┤ Rz(-π/8) ├┤ X ├┤ Rz(π/8) ├─────┤ X ├┤ Rz(-π/16) ├─────┤ X ├┤ Rz(π/16) ├»\n", + "« └──────────┘└─┬─┘└─────────┘┌───┐└─┬─┘└┬──────────┤┌───┐└─┬─┘├─────────┬┘»\n", + "«q_1: ──────────────┼─────────────┤ X ├──┼───┤ Rz(-π/4) ├┤ X ├──┼──┤ Rz(π/4) ├─»\n", + "« │ ┌─────────┐└─┬─┘ │ └──────────┘└─┬─┘ │ ├─────────┴┐»\n", + "«q_2: ──────────────■──┤ Rz(π/4) ├──■────┼─────────────────■────┼──┤ Ry(-π/2) ├»\n", + "« └─────────┘ │ │ ├─────────┬┘»\n", + "«q_3: ───────────────────────────────────■──────────────────────■──┤ Rz(π/8) ├─»\n", + "« └─────────┘ »\n", + "«q_4: ─────────────────────────────────────────────────────────────────────────»\n", + "« »\n", + "«q_5: ─────────────────────────────────────────────────────────────────────────»\n", + "« »\n", + "«q_6: ─────────────────────────────────────────────────────────────────────────»\n", + "« »\n", + "«q_7: ─────────────────────────────────────────────────────────────────────────»\n", + "« »\n", + "« ┌───┐┌───────────┐ ┌───┐┌──────────┐ ┌───┐»\n", + "«q_0: ───────────────┤ X ├┤ Rz(-π/32) ├─────┤ X ├┤ Rz(π/32) ├──────────┤ X ├»\n", + "« ┌───┐└─┬─┘└┬──────────┤┌───┐└─┬─┘├─────────┬┘ ┌───┐└─┬─┘»\n", + "«q_1: ──────────┤ X ├──┼───┤ Rz(-π/8) ├┤ X ├──┼──┤ Rz(π/8) ├──────┤ X ├──┼──»\n", + "« ┌────────┐└─┬─┘ │ └──────────┘└─┬─┘ │ └─────────┘ ┌───┐└─┬─┘ │ »\n", + "«q_2: ┤ Rz(-π) ├──┼────┼─────────────────┼────┼──────────────┤ X ├──┼────┼──»\n", + "« └────────┘ │ │ │ │ ┌─────────┐ └─┬─┘ │ │ »\n", + "«q_3: ────────────■────┼─────────────────■────┼──┤ Rz(π/4) ├───■────┼────┼──»\n", + "« │ │ ├─────────┴┐ │ │ »\n", + "«q_4: ─────────────────■──────────────────────■──┤ Rz(π/16) ├───────■────┼──»\n", + "« └──────────┘ │ »\n", + "«q_5: ───────────────────────────────────────────────────────────────────■──»\n", + "« »\n", + "«q_6: ──────────────────────────────────────────────────────────────────────»\n", + "« »\n", + "«q_7: ──────────────────────────────────────────────────────────────────────»\n", + "« »\n", + "« ┌───────────┐ ┌───┐┌──────────┐ ┌───┐»\n", + "«q_0: ┤ Rz(-π/64) ├──────────┤ X ├┤ Rz(π/64) ├────────────────────┤ X ├»\n", + "« ├───────────┤ ┌───┐└─┬─┘├──────────┤ ┌───┐└─┬─┘»\n", + "«q_1: ┤ Rz(-π/16) ├─────┤ X ├──┼──┤ Rz(π/16) ├───────────────┤ X ├──┼──»\n", + "« └┬──────────┤┌───┐└─┬─┘ │ ├─────────┬┘ ┌───┐└─┬─┘ │ »\n", + "«q_2: ─┤ Rz(-π/4) ├┤ X ├──┼────┼──┤ Rz(π/4) ├───────────┤ X ├──┼────┼──»\n", + "« └──────────┘└─┬─┘ │ │ ├─────────┴┐┌────────┐└─┬─┘ │ │ »\n", + "«q_3: ───────────────■────┼────┼──┤ Ry(-π/2) ├┤ Rz(-π) ├──┼────┼────┼──»\n", + "« │ │ ├─────────┬┘└────────┘ │ │ │ »\n", + "«q_4: ────────────────────■────┼──┤ Rz(π/8) ├─────────────■────┼────┼──»\n", + "« │ ├─────────┴┐ │ │ »\n", + "«q_5: ─────────────────────────■──┤ Rz(π/32) ├─────────────────■────┼──»\n", + "« └──────────┘ │ »\n", + "«q_6: ──────────────────────────────────────────────────────────────■──»\n", + "« »\n", + "«q_7: ─────────────────────────────────────────────────────────────────»\n", + "« »\n", + "« ┌────────────┐ ┌───┐┌───────────┐ ┌───┐»\n", + "«q_0: ┤ Rz(-π/128) ├──────────┤ X ├┤ Rz(π/128) ├───────────────┤ X ├»\n", + "« ├───────────┬┘ ┌───┐└─┬─┘└┬──────────┤ ┌───┐└─┬─┘»\n", + "«q_1: ┤ Rz(-π/32) ├──────┤ X ├──┼───┤ Rz(π/32) ├──────────┤ X ├──┼──»\n", + "« └┬──────────┤ ┌───┐└─┬─┘ │ ├─────────┬┘ ┌───┐└─┬─┘ │ »\n", + "«q_2: ─┤ Rz(-π/8) ├─┤ X ├──┼────┼───┤ Rz(π/8) ├──────┤ X ├──┼────┼──»\n", + "« └──────────┘ └─┬─┘ │ │ └─────────┘ ┌───┐└─┬─┘ │ │ »\n", + "«q_3: ────────────────┼────┼────┼───────────────┤ X ├──┼────┼────┼──»\n", + "« │ │ │ ┌─────────┐ └─┬─┘ │ │ │ »\n", + "«q_4: ────────────────■────┼────┼───┤ Rz(π/4) ├───■────┼────┼────┼──»\n", + "« │ │ ├─────────┴┐ │ │ │ »\n", + "«q_5: ─────────────────────■────┼───┤ Rz(π/16) ├───────■────┼────┼──»\n", + "« │ ├──────────┤ │ │ »\n", + "«q_6: ──────────────────────────■───┤ Rz(π/64) ├────────────■────┼──»\n", + "« └──────────┘ │ »\n", + "«q_7: ───────────────────────────────────────────────────────────■──»\n", + "« »\n", + "« ┌────────────┐ ┌───┐┌───────────┐ »\n", + "«q_0: ┤ Rz(-π/256) ├───────────────┤ X ├┤ Rz(π/256) ├─────────────────────────»\n", + "« ├───────────┬┘ ┌───┐└─┬─┘└┬──────────┤ ┌───┐»\n", + "«q_1: ┤ Rz(-π/64) ├───────────┤ X ├──┼───┤ Rz(π/64) ├────────────────────┤ X ├»\n", + "« ├───────────┤ ┌───┐└─┬─┘ │ ├──────────┤ ┌───┐└─┬─┘»\n", + "«q_2: ┤ Rz(-π/16) ├──────┤ X ├──┼────┼───┤ Rz(π/16) ├───────────────┤ X ├──┼──»\n", + "« └┬──────────┤ ┌───┐└─┬─┘ │ │ ├─────────┬┘ ┌───┐└─┬─┘ │ »\n", + "«q_3: ─┤ Rz(-π/4) ├─┤ X ├──┼────┼────┼───┤ Rz(π/4) ├───────────┤ X ├──┼────┼──»\n", + "« └──────────┘ └─┬─┘ │ │ │ ├─────────┴┐┌────────┐└─┬─┘ │ │ »\n", + "«q_4: ────────────────■────┼────┼────┼───┤ Ry(-π/2) ├┤ Rz(-π) ├──┼────┼────┼──»\n", + "« │ │ │ ├─────────┬┘└────────┘ │ │ │ »\n", + "«q_5: ─────────────────────■────┼────┼───┤ Rz(π/8) ├─────────────■────┼────┼──»\n", + "« │ │ ├─────────┴┐ │ │ »\n", + "«q_6: ──────────────────────────■────┼───┤ Rz(π/32) ├─────────────────■────┼──»\n", + "« │ ┌┴──────────┤ │ »\n", + "«q_7: ───────────────────────────────■──┤ Rz(π/128) ├──────────────────────■──»\n", + "« └───────────┘ »\n", + "« »\n", + "«q_0: ──────────────────────────────────────────────────────────────────────»\n", + "« ┌────────────┐ ┌───┐┌───────────┐ »\n", + "«q_1: ┤ Rz(-π/128) ├──────────┤ X ├┤ Rz(π/128) ├────────────────────────────»\n", + "« ├───────────┬┘ ┌───┐└─┬─┘└┬──────────┤ ┌───┐┌───────────┐»\n", + "«q_2: ┤ Rz(-π/32) ├──────┤ X ├──┼───┤ Rz(π/32) ├──────────┤ X ├┤ Rz(-π/64) ├»\n", + "« └┬──────────┤ ┌───┐└─┬─┘ │ ├─────────┬┘ ┌───┐└─┬─┘├───────────┤»\n", + "«q_3: ─┤ Rz(-π/8) ├─┤ X ├──┼────┼───┤ Rz(π/8) ├──────┤ X ├──┼──┤ Rz(-π/16) ├»\n", + "« └──────────┘ └─┬─┘ │ │ └─────────┘ ┌───┐└─┬─┘ │ └┬──────────┤»\n", + "«q_4: ────────────────┼────┼────┼───────────────┤ X ├──┼────┼───┤ Rz(-π/4) ├»\n", + "« │ │ │ ┌─────────┐ └─┬─┘ │ │ └──────────┘»\n", + "«q_5: ────────────────■────┼────┼───┤ Rz(π/4) ├───■────┼────┼───────────────»\n", + "« │ │ ├─────────┴┐ │ │ »\n", + "«q_6: ─────────────────────■────┼───┤ Rz(π/16) ├───────■────┼───────────────»\n", + "« │ ├──────────┤ │ »\n", + "«q_7: ──────────────────────────■───┤ Rz(π/64) ├────────────■───────────────»\n", + "« └──────────┘ »\n", + "« »\n", + "«q_0: ──────────────────────────────────────────────────────────────────────»\n", + "« »\n", + "«q_1: ──────────────────────────────────────────────────────────────────────»\n", + "« ┌───┐┌──────────┐ »\n", + "«q_2: ──────────┤ X ├┤ Rz(π/64) ├───────────────────────────────────────────»\n", + "« ┌───┐└─┬─┘├──────────┤ ┌───┐┌───────────┐ ┌───┐»\n", + "«q_3: ─────┤ X ├──┼──┤ Rz(π/16) ├───────────────┤ X ├┤ Rz(-π/32) ├─────┤ X ├»\n", + "« ┌───┐└─┬─┘ │ ├─────────┬┘ ┌───┐└─┬─┘└┬──────────┤┌───┐└─┬─┘»\n", + "«q_4: ┤ X ├──┼────┼──┤ Rz(π/4) ├───────────┤ X ├──┼───┤ Rz(-π/8) ├┤ X ├──┼──»\n", + "« └─┬─┘ │ │ ├─────────┴┐┌────────┐└─┬─┘ │ └──────────┘└─┬─┘ │ »\n", + "«q_5: ──■────┼────┼──┤ Ry(-π/2) ├┤ Rz(-π) ├──┼────┼─────────────────┼────┼──»\n", + "« │ │ ├─────────┬┘└────────┘ │ │ │ │ »\n", + "«q_6: ───────■────┼──┤ Rz(π/8) ├─────────────■────┼─────────────────■────┼──»\n", + "« │ ├─────────┴┐ │ │ »\n", + "«q_7: ────────────■──┤ Rz(π/32) ├─────────────────■──────────────────────■──»\n", + "« └──────────┘ »\n", + "« »\n", + "«q_0: ────────────────────────────────────────────────────────────────────────»\n", + "« »\n", + "«q_1: ────────────────────────────────────────────────────────────────────────»\n", + "« »\n", + "«q_2: ────────────────────────────────────────────────────────────────────────»\n", + "« ┌──────────┐ »\n", + "«q_3: ┤ Rz(π/32) ├────────────────────────────────────────────────────────────»\n", + "« ├─────────┬┘ ┌───┐┌───────────┐ ┌───┐┌──────────┐ »\n", + "«q_4: ┤ Rz(π/8) ├──────┤ X ├┤ Rz(-π/16) ├─────┤ X ├┤ Rz(π/16) ├───────────────»\n", + "« └─────────┘ ┌───┐└─┬─┘└┬──────────┤┌───┐└─┬─┘├─────────┬┘ ┌───┐»\n", + "«q_5: ────────────┤ X ├──┼───┤ Rz(-π/4) ├┤ X ├──┼──┤ Rz(π/4) ├───────────┤ X ├»\n", + "« ┌─────────┐ └─┬─┘ │ └──────────┘└─┬─┘ │ ├─────────┴┐┌────────┐└─┬─┘»\n", + "«q_6: ┤ Rz(π/4) ├───■────┼─────────────────■────┼──┤ Ry(-π/2) ├┤ Rz(-π) ├──┼──»\n", + "« ├─────────┴┐ │ │ ├─────────┬┘└────────┘ │ »\n", + "«q_7: ┤ Rz(π/16) ├───────■──────────────────────■──┤ Rz(π/8) ├─────────────■──»\n", + "« └──────────┘ └─────────┘ »\n", + "« \n", + "«q_0: ────────────────────────────────────────────────────────────────────────\n", + "« \n", + "«q_1: ────────────────────────────────────────────────────────────────────────\n", + "« \n", + "«q_2: ────────────────────────────────────────────────────────────────────────\n", + "« \n", + "«q_3: ────────────────────────────────────────────────────────────────────────\n", + "« \n", + "«q_4: ────────────────────────────────────────────────────────────────────────\n", + "« ┌──────────┐┌───┐┌─────────┐ \n", + "«q_5: ┤ Rz(-π/8) ├┤ X ├┤ Rz(π/8) ├────────────────────────────────────────────\n", + "« └──────────┘└─┬─┘└─────────┘┌───┐┌──────────┐┌───┐┌─────────┐ \n", + "«q_6: ──────────────┼─────────────┤ X ├┤ Rz(-π/4) ├┤ X ├┤ Rz(π/4) ├───────────\n", + "« │ ┌─────────┐└─┬─┘└──────────┘└─┬─┘├─────────┴┐┌────────┐\n", + "«q_7: ──────────────■──┤ Rz(π/4) ├──■────────────────■──┤ Ry(-π/2) ├┤ Rz(-π) ├\n", + "« └─────────┘ └──────────┘└────────┘\n" + ] + } + ], "source": [ "print(ucc_qc)" ] From a664f45b8936b5802ce7b9b8ccd9b6762699f00c Mon Sep 17 00:00:00 2001 From: jordandsullivan Date: Wed, 25 Sep 2024 14:49:58 -0700 Subject: [PATCH 3/5] clearing notebook outputs --- .../check_parameterized.ipynb | 103 ++---------------- .../custom_compile_heisenberg_ring.ipynb | 50 ++------- .../custom_compile_qcnn.ipynb | 90 ++------------- 3 files changed, 32 insertions(+), 211 deletions(-) diff --git a/custom_compiler_experiments/check_parameterized.ipynb b/custom_compiler_experiments/check_parameterized.ipynb index c8b17c0a..947b8be8 100644 --- a/custom_compiler_experiments/check_parameterized.ipynb +++ b/custom_compiler_experiments/check_parameterized.ipynb @@ -2,7 +2,7 @@ "cells": [ { "cell_type": "code", - "execution_count": 24, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -16,23 +16,9 @@ }, { "cell_type": "code", - "execution_count": 25, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - " ┌─────────┐ ┌─────────┐\n", - "q_0: ──■──┤ Rz(0.1) ├──■──┤ Rz(0.2) ├\n", - " ┌─┴─┐└─────────┘┌─┴─┐└─────────┘\n", - "q_1: ┤ X ├───────────┤ X ├───────────\n", - " └───┘ └───┘ \n", - "c: 2/════════════════════════════════\n", - " \n" - ] - } - ], + "outputs": [], "source": [ "# Create a quantum circuit with no parameters\n", "qc = QuantumCircuit(2, 2)\n", @@ -46,27 +32,9 @@ }, { "cell_type": "code", - "execution_count": 26, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Time taken: 0.007478952407836914\n", - "OrderedDict({'rz': 1})\n", - "Number of 2-qubit gates: 0\n", - "Number of 1-qubit gates: 1\n", - " ┌─────────┐\n", - "q_0: ┤ Rz(0.3) ├\n", - " └─────────┘\n", - "q_1: ───────────\n", - " \n", - "c: 2/═══════════\n", - " \n" - ] - } - ], + "outputs": [], "source": [ "t1 = time.time()\n", "default_qc = pm.run(qc)\n", @@ -84,23 +52,9 @@ }, { "cell_type": "code", - "execution_count": 27, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - " ┌────────────┐ ┌────────────┐\n", - "q_0: ──■──┤ Rz(angle1) ├──■──┤ Rz(angle2) ├\n", - " ┌─┴─┐└────────────┘┌─┴─┐└────────────┘\n", - "q_1: ┤ X ├──────────────┤ X ├──────────────\n", - " └───┘ └───┘ \n", - "c: 2/══════════════════════════════════════\n", - " \n" - ] - } - ], + "outputs": [], "source": [ "#Create a quantum circuit with parameters\n", "from qiskit.circuit import Parameter\n", @@ -120,27 +74,9 @@ }, { "cell_type": "code", - "execution_count": 28, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Time taken: 0.014104127883911133\n", - "OrderedDict({'cx': 2, 'rz': 2})\n", - "Number of 2-qubit gates: 2\n", - "Number of 1-qubit gates: 2\n", - " ┌────────────┐ ┌────────────┐\n", - "q_0: ──■──┤ Rz(angle1) ├──■──┤ Rz(angle2) ├\n", - " ┌─┴─┐└────────────┘┌─┴─┐└────────────┘\n", - "q_1: ┤ X ├──────────────┤ X ├──────────────\n", - " └───┘ └───┘ \n", - "c: 2/══════════════════════════════════════\n", - " \n" - ] - } - ], + "outputs": [], "source": [ "t1 = time.time()\n", "default_pqc = pm.run(pqc)\n", @@ -165,24 +101,9 @@ }, { "cell_type": "code", - "execution_count": 32, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Time taken: 0.002134084701538086\n", - " ┌────────────┐┌────────────┐\n", - "q_0: ┤ Rz(angle1) ├┤ Rz(angle2) ├\n", - " └────────────┘└────────────┘\n", - "q_1: ────────────────────────────\n", - " \n", - "c: 2/════════════════════════════\n", - " \n" - ] - } - ], + "outputs": [], "source": [ "import sys\n", "sys.path.append('../')\n", @@ -200,7 +121,7 @@ }, { "cell_type": "code", - "execution_count": 30, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ diff --git a/custom_compiler_experiments/custom_compile_heisenberg_ring.ipynb b/custom_compiler_experiments/custom_compile_heisenberg_ring.ipynb index 84d05d67..17c50953 100644 --- a/custom_compiler_experiments/custom_compile_heisenberg_ring.ipynb +++ b/custom_compiler_experiments/custom_compile_heisenberg_ring.ipynb @@ -16,7 +16,7 @@ }, { "cell_type": "code", - "execution_count": 17, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -35,17 +35,9 @@ }, { "cell_type": "code", - "execution_count": 18, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "OrderedDict({'cx': 72, 'rz': 60, 'h': 48, 'ry': 48})\n" - ] - } - ], + "outputs": [], "source": [ "num_qubits = 5\n", "num_layers = 3\n", @@ -90,7 +82,7 @@ }, { "cell_type": "code", - "execution_count": 19, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -108,7 +100,7 @@ }, { "cell_type": "code", - "execution_count": 20, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -124,20 +116,9 @@ }, { "cell_type": "code", - "execution_count": 21, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Time taken: 0.5280048847198486\n", - "OrderedDict({'rz': 54, 'rx': 40, 'cx': 24, 'ry': 13})\n", - "Number of 2-qubit gates: 24\n", - "Number of 1-qubit gates: 107\n" - ] - } - ], + "outputs": [], "source": [ "from qiskit.transpiler.preset_passmanagers import generate_preset_pass_manager\n", "default_pm = generate_preset_pass_manager(backend=backend, optimization_level=3)\n", @@ -156,7 +137,7 @@ }, { "cell_type": "code", - "execution_count": 22, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -165,20 +146,9 @@ }, { "cell_type": "code", - "execution_count": 24, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Time taken: 0.19528555870056152\n", - "OrderedDict({'rz': 63, 'ry': 42, 'cx': 24, 'rx': 11})\n", - "Number of 2-qubit gates: 24\n", - "Number of 1-qubit gates: 116\n" - ] - } - ], + "outputs": [], "source": [ "#Test with UCC transpiler\n", "\n", diff --git a/custom_compiler_experiments/custom_compile_qcnn.ipynb b/custom_compiler_experiments/custom_compile_qcnn.ipynb index 10c7020b..10a8ff34 100644 --- a/custom_compiler_experiments/custom_compile_qcnn.ipynb +++ b/custom_compiler_experiments/custom_compile_qcnn.ipynb @@ -16,7 +16,7 @@ }, { "cell_type": "code", - "execution_count": 23, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -35,7 +35,7 @@ }, { "cell_type": "code", - "execution_count": 24, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -64,57 +64,9 @@ }, { "cell_type": "code", - "execution_count": 25, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "data": { - "text/html": [ - "
     ┌───────────────┐ ┌─────────────┐                                »\n",
-       "q_0: ┤0              ├─┤ Ry(0.33251) ├────────────────────────────────»\n",
-       "     │  Rxx(0.16964) │ ├─────────────┤┌───────────────┐┌─────────────┐»\n",
-       "q_1: ┤1              ├─┤ Ry(0.59386) ├┤0              ├┤ Ry(0.63625) ├»\n",
-       "     ├───────────────┴┐├─────────────┤│  Rxx(0.71598) │├─────────────┤»\n",
-       "q_2: ┤0               ├┤ Ry(0.10413) ├┤1              ├┤ Ry(0.80983) ├»\n",
-       "     │  Rxx(0.031875) │├─────────────┤└───────────────┘└─────────────┘»\n",
-       "q_3: ┤1               ├┤ Ry(0.81302) ├────────────────────────────────»\n",
-       "     └────────────────┘└─────────────┘                                »\n",
-       "«     ┌───────────────┐┌─────────────┐\n",
-       "«q_0: ┤0              ├┤ Ry(0.88238) ├\n",
-       "«     │               │└─────────────┘\n",
-       "«q_1: ┤  Rxx(0.29288) ├───────────────\n",
-       "«     │               │┌─────────────┐\n",
-       "«q_2: ┤1              ├┤ Ry(0.15394) ├\n",
-       "«     └───────────────┘└─────────────┘\n",
-       "«q_3: ────────────────────────────────\n",
-       "«                                     
" - ], - "text/plain": [ - " ┌───────────────┐ ┌─────────────┐ »\n", - "q_0: ┤0 ├─┤ Ry(0.33251) ├────────────────────────────────»\n", - " │ Rxx(0.16964) │ ├─────────────┤┌───────────────┐┌─────────────┐»\n", - "q_1: ┤1 ├─┤ Ry(0.59386) ├┤0 ├┤ Ry(0.63625) ├»\n", - " ├───────────────┴┐├─────────────┤│ Rxx(0.71598) │├─────────────┤»\n", - "q_2: ┤0 ├┤ Ry(0.10413) ├┤1 ├┤ Ry(0.80983) ├»\n", - " │ Rxx(0.031875) │├─────────────┤└───────────────┘└─────────────┘»\n", - "q_3: ┤1 ├┤ Ry(0.81302) ├────────────────────────────────»\n", - " └────────────────┘└─────────────┘ »\n", - "« ┌───────────────┐┌─────────────┐\n", - "«q_0: ┤0 ├┤ Ry(0.88238) ├\n", - "« │ │└─────────────┘\n", - "«q_1: ┤ Rxx(0.29288) ├───────────────\n", - "« │ │┌─────────────┐\n", - "«q_2: ┤1 ├┤ Ry(0.15394) ├\n", - "« └───────────────┘└─────────────┘\n", - "«q_3: ────────────────────────────────\n", - "« " - ] - }, - "execution_count": 25, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ "qc.draw()" ] @@ -128,7 +80,7 @@ }, { "cell_type": "code", - "execution_count": 26, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -146,20 +98,9 @@ }, { "cell_type": "code", - "execution_count": 27, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Time taken: 0.10510921478271484\n", - "OrderedDict({'rz': 16, 'rx': 8, 'cx': 8, 'ry': 4})\n", - "Number of 2-qubit gates: 8\n", - "Number of 1-qubit gates: 28\n" - ] - } - ], + "outputs": [], "source": [ "from qiskit.transpiler.preset_passmanagers import generate_preset_pass_manager\n", "default_pm = generate_preset_pass_manager(backend=backend, optimization_level=3)\n", @@ -178,7 +119,7 @@ }, { "cell_type": "code", - "execution_count": 28, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -194,20 +135,9 @@ }, { "cell_type": "code", - "execution_count": 30, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Time taken: 0.07597589492797852\n", - "OrderedDict({'rz': 31, 'ry': 23, 'cx': 8})\n", - "Number of 2-qubit gates: 8\n", - "Number of 1-qubit gates: 54\n" - ] - } - ], + "outputs": [], "source": [ "#Test with UCC transpiler\n", "import sys\n", From 99a669f8b8ec4bf9865a62aaa134f275f67d2b94 Mon Sep 17 00:00:00 2001 From: jordandsullivan Date: Wed, 25 Sep 2024 15:03:36 -0700 Subject: [PATCH 4/5] clearing outputs for qft notebook --- .../custom_compile_qft.ipynb | 236 ++---------------- 1 file changed, 14 insertions(+), 222 deletions(-) diff --git a/custom_compiler_experiments/custom_compile_qft.ipynb b/custom_compiler_experiments/custom_compile_qft.ipynb index be06319a..da09a02b 100644 --- a/custom_compiler_experiments/custom_compile_qft.ipynb +++ b/custom_compiler_experiments/custom_compile_qft.ipynb @@ -2,7 +2,7 @@ "cells": [ { "cell_type": "code", - "execution_count": 44, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -15,7 +15,7 @@ }, { "cell_type": "code", - "execution_count": 45, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -42,24 +42,16 @@ }, { "cell_type": "code", - "execution_count": 46, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "[[0, 2], [1, 3], [0, 1], [2, 4], [3, 5], [2, 3], [4, 6], [5, 7], [4, 5], [6, 7]]\n" - ] - } - ], + "outputs": [], "source": [ "print(coupling_map)" ] }, { "cell_type": "code", - "execution_count": 47, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -74,7 +66,7 @@ }, { "cell_type": "code", - "execution_count": 48, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -90,20 +82,9 @@ }, { "cell_type": "code", - "execution_count": 49, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Time taken: 0.5353250503540039\n", - "OrderedDict({'rz': 127, 'cx': 84, 'rx': 39, 'ry': 34, 'h': 27})\n", - "Number of 2-qubit gates: 84\n", - "Number of 1-qubit gates: 227\n" - ] - } - ], + "outputs": [], "source": [ "from qiskit.transpiler.preset_passmanagers import generate_preset_pass_manager\n", "default_pm = generate_preset_pass_manager(backend=line_backend, optimization_level=3)\n", @@ -131,7 +112,7 @@ }, { "cell_type": "code", - "execution_count": 50, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -151,7 +132,7 @@ }, { "cell_type": "code", - "execution_count": 51, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -166,20 +147,9 @@ }, { "cell_type": "code", - "execution_count": 52, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Time taken: 0.14137697219848633\n", - "OrderedDict({'rz': 92, 'cx': 56, 'ry': 8})\n", - "Number of 2-qubit gates: 56\n", - "Number of 1-qubit gates: 100\n" - ] - } - ], + "outputs": [], "source": [ "#Test with UCC transpiler\n", "import sys\n", @@ -202,187 +172,9 @@ }, { "cell_type": "code", - "execution_count": 53, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "global phase: 4.7185\n", - " ┌──────────┐┌────────┐┌───┐┌──────────┐┌───┐┌─────────┐ ┌───┐»\n", - "q_0: ─┤ Ry(-π/2) ├┤ Rz(-π) ├┤ X ├┤ Rz(-π/4) ├┤ X ├┤ Rz(π/4) ├───────────┤ X ├»\n", - " ├─────────┬┘└────────┘└─┬─┘└──────────┘└─┬─┘├─────────┴┐┌────────┐└─┬─┘»\n", - "q_1: ─┤ Rz(π/4) ├─────────────■────────────────■──┤ Ry(-π/2) ├┤ Rz(-π) ├──┼──»\n", - " ├─────────┤ └──────────┘└────────┘ │ »\n", - "q_2: ─┤ Rz(π/8) ├─────────────────────────────────────────────────────────■──»\n", - " ├─────────┴┐ »\n", - "q_3: ─┤ Rz(π/16) ├───────────────────────────────────────────────────────────»\n", - " ├──────────┤ »\n", - "q_4: ─┤ Rz(π/32) ├───────────────────────────────────────────────────────────»\n", - " ├──────────┤ »\n", - "q_5: ─┤ Rz(π/64) ├───────────────────────────────────────────────────────────»\n", - " ┌┴──────────┤ »\n", - "q_6: ┤ Rz(π/128) ├───────────────────────────────────────────────────────────»\n", - " ├───────────┤ »\n", - "q_7: ┤ Rz(π/256) ├───────────────────────────────────────────────────────────»\n", - " └───────────┘ »\n", - "« ┌──────────┐┌───┐┌─────────┐ ┌───┐┌───────────┐ ┌───┐┌──────────┐»\n", - "«q_0: ┤ Rz(-π/8) ├┤ X ├┤ Rz(π/8) ├─────┤ X ├┤ Rz(-π/16) ├─────┤ X ├┤ Rz(π/16) ├»\n", - "« └──────────┘└─┬─┘└─────────┘┌───┐└─┬─┘└┬──────────┤┌───┐└─┬─┘├─────────┬┘»\n", - "«q_1: ──────────────┼─────────────┤ X ├──┼───┤ Rz(-π/4) ├┤ X ├──┼──┤ Rz(π/4) ├─»\n", - "« │ ┌─────────┐└─┬─┘ │ └──────────┘└─┬─┘ │ ├─────────┴┐»\n", - "«q_2: ──────────────■──┤ Rz(π/4) ├──■────┼─────────────────■────┼──┤ Ry(-π/2) ├»\n", - "« └─────────┘ │ │ ├─────────┬┘»\n", - "«q_3: ───────────────────────────────────■──────────────────────■──┤ Rz(π/8) ├─»\n", - "« └─────────┘ »\n", - "«q_4: ─────────────────────────────────────────────────────────────────────────»\n", - "« »\n", - "«q_5: ─────────────────────────────────────────────────────────────────────────»\n", - "« »\n", - "«q_6: ─────────────────────────────────────────────────────────────────────────»\n", - "« »\n", - "«q_7: ─────────────────────────────────────────────────────────────────────────»\n", - "« »\n", - "« ┌───┐┌───────────┐ ┌───┐┌──────────┐ ┌───┐»\n", - "«q_0: ───────────────┤ X ├┤ Rz(-π/32) ├─────┤ X ├┤ Rz(π/32) ├──────────┤ X ├»\n", - "« ┌───┐└─┬─┘└┬──────────┤┌───┐└─┬─┘├─────────┬┘ ┌───┐└─┬─┘»\n", - "«q_1: ──────────┤ X ├──┼───┤ Rz(-π/8) ├┤ X ├──┼──┤ Rz(π/8) ├──────┤ X ├──┼──»\n", - "« ┌────────┐└─┬─┘ │ └──────────┘└─┬─┘ │ └─────────┘ ┌───┐└─┬─┘ │ »\n", - "«q_2: ┤ Rz(-π) ├──┼────┼─────────────────┼────┼──────────────┤ X ├──┼────┼──»\n", - "« └────────┘ │ │ │ │ ┌─────────┐ └─┬─┘ │ │ »\n", - "«q_3: ────────────■────┼─────────────────■────┼──┤ Rz(π/4) ├───■────┼────┼──»\n", - "« │ │ ├─────────┴┐ │ │ »\n", - "«q_4: ─────────────────■──────────────────────■──┤ Rz(π/16) ├───────■────┼──»\n", - "« └──────────┘ │ »\n", - "«q_5: ───────────────────────────────────────────────────────────────────■──»\n", - "« »\n", - "«q_6: ──────────────────────────────────────────────────────────────────────»\n", - "« »\n", - "«q_7: ──────────────────────────────────────────────────────────────────────»\n", - "« »\n", - "« ┌───────────┐ ┌───┐┌──────────┐ ┌───┐»\n", - "«q_0: ┤ Rz(-π/64) ├──────────┤ X ├┤ Rz(π/64) ├────────────────────┤ X ├»\n", - "« ├───────────┤ ┌───┐└─┬─┘├──────────┤ ┌───┐└─┬─┘»\n", - "«q_1: ┤ Rz(-π/16) ├─────┤ X ├──┼──┤ Rz(π/16) ├───────────────┤ X ├──┼──»\n", - "« └┬──────────┤┌───┐└─┬─┘ │ ├─────────┬┘ ┌───┐└─┬─┘ │ »\n", - "«q_2: ─┤ Rz(-π/4) ├┤ X ├──┼────┼──┤ Rz(π/4) ├───────────┤ X ├──┼────┼──»\n", - "« └──────────┘└─┬─┘ │ │ ├─────────┴┐┌────────┐└─┬─┘ │ │ »\n", - "«q_3: ───────────────■────┼────┼──┤ Ry(-π/2) ├┤ Rz(-π) ├──┼────┼────┼──»\n", - "« │ │ ├─────────┬┘└────────┘ │ │ │ »\n", - "«q_4: ────────────────────■────┼──┤ Rz(π/8) ├─────────────■────┼────┼──»\n", - "« │ ├─────────┴┐ │ │ »\n", - "«q_5: ─────────────────────────■──┤ Rz(π/32) ├─────────────────■────┼──»\n", - "« └──────────┘ │ »\n", - "«q_6: ──────────────────────────────────────────────────────────────■──»\n", - "« »\n", - "«q_7: ─────────────────────────────────────────────────────────────────»\n", - "« »\n", - "« ┌────────────┐ ┌───┐┌───────────┐ ┌───┐»\n", - "«q_0: ┤ Rz(-π/128) ├──────────┤ X ├┤ Rz(π/128) ├───────────────┤ X ├»\n", - "« ├───────────┬┘ ┌───┐└─┬─┘└┬──────────┤ ┌───┐└─┬─┘»\n", - "«q_1: ┤ Rz(-π/32) ├──────┤ X ├──┼───┤ Rz(π/32) ├──────────┤ X ├──┼──»\n", - "« └┬──────────┤ ┌───┐└─┬─┘ │ ├─────────┬┘ ┌───┐└─┬─┘ │ »\n", - "«q_2: ─┤ Rz(-π/8) ├─┤ X ├──┼────┼───┤ Rz(π/8) ├──────┤ X ├──┼────┼──»\n", - "« └──────────┘ └─┬─┘ │ │ └─────────┘ ┌───┐└─┬─┘ │ │ »\n", - "«q_3: ────────────────┼────┼────┼───────────────┤ X ├──┼────┼────┼──»\n", - "« │ │ │ ┌─────────┐ └─┬─┘ │ │ │ »\n", - "«q_4: ────────────────■────┼────┼───┤ Rz(π/4) ├───■────┼────┼────┼──»\n", - "« │ │ ├─────────┴┐ │ │ │ »\n", - "«q_5: ─────────────────────■────┼───┤ Rz(π/16) ├───────■────┼────┼──»\n", - "« │ ├──────────┤ │ │ »\n", - "«q_6: ──────────────────────────■───┤ Rz(π/64) ├────────────■────┼──»\n", - "« └──────────┘ │ »\n", - "«q_7: ───────────────────────────────────────────────────────────■──»\n", - "« »\n", - "« ┌────────────┐ ┌───┐┌───────────┐ »\n", - "«q_0: ┤ Rz(-π/256) ├───────────────┤ X ├┤ Rz(π/256) ├─────────────────────────»\n", - "« ├───────────┬┘ ┌───┐└─┬─┘└┬──────────┤ ┌───┐»\n", - "«q_1: ┤ Rz(-π/64) ├───────────┤ X ├──┼───┤ Rz(π/64) ├────────────────────┤ X ├»\n", - "« ├───────────┤ ┌───┐└─┬─┘ │ ├──────────┤ ┌───┐└─┬─┘»\n", - "«q_2: ┤ Rz(-π/16) ├──────┤ X ├──┼────┼───┤ Rz(π/16) ├───────────────┤ X ├──┼──»\n", - "« └┬──────────┤ ┌───┐└─┬─┘ │ │ ├─────────┬┘ ┌───┐└─┬─┘ │ »\n", - "«q_3: ─┤ Rz(-π/4) ├─┤ X ├──┼────┼────┼───┤ Rz(π/4) ├───────────┤ X ├──┼────┼──»\n", - "« └──────────┘ └─┬─┘ │ │ │ ├─────────┴┐┌────────┐└─┬─┘ │ │ »\n", - "«q_4: ────────────────■────┼────┼────┼───┤ Ry(-π/2) ├┤ Rz(-π) ├──┼────┼────┼──»\n", - "« │ │ │ ├─────────┬┘└────────┘ │ │ │ »\n", - "«q_5: ─────────────────────■────┼────┼───┤ Rz(π/8) ├─────────────■────┼────┼──»\n", - "« │ │ ├─────────┴┐ │ │ »\n", - "«q_6: ──────────────────────────■────┼───┤ Rz(π/32) ├─────────────────■────┼──»\n", - "« │ ┌┴──────────┤ │ »\n", - "«q_7: ───────────────────────────────■──┤ Rz(π/128) ├──────────────────────■──»\n", - "« └───────────┘ »\n", - "« »\n", - "«q_0: ──────────────────────────────────────────────────────────────────────»\n", - "« ┌────────────┐ ┌───┐┌───────────┐ »\n", - "«q_1: ┤ Rz(-π/128) ├──────────┤ X ├┤ Rz(π/128) ├────────────────────────────»\n", - "« ├───────────┬┘ ┌───┐└─┬─┘└┬──────────┤ ┌───┐┌───────────┐»\n", - "«q_2: ┤ Rz(-π/32) ├──────┤ X ├──┼───┤ Rz(π/32) ├──────────┤ X ├┤ Rz(-π/64) ├»\n", - "« └┬──────────┤ ┌───┐└─┬─┘ │ ├─────────┬┘ ┌───┐└─┬─┘├───────────┤»\n", - "«q_3: ─┤ Rz(-π/8) ├─┤ X ├──┼────┼───┤ Rz(π/8) ├──────┤ X ├──┼──┤ Rz(-π/16) ├»\n", - "« └──────────┘ └─┬─┘ │ │ └─────────┘ ┌───┐└─┬─┘ │ └┬──────────┤»\n", - "«q_4: ────────────────┼────┼────┼───────────────┤ X ├──┼────┼───┤ Rz(-π/4) ├»\n", - "« │ │ │ ┌─────────┐ └─┬─┘ │ │ └──────────┘»\n", - "«q_5: ────────────────■────┼────┼───┤ Rz(π/4) ├───■────┼────┼───────────────»\n", - "« │ │ ├─────────┴┐ │ │ »\n", - "«q_6: ─────────────────────■────┼───┤ Rz(π/16) ├───────■────┼───────────────»\n", - "« │ ├──────────┤ │ »\n", - "«q_7: ──────────────────────────■───┤ Rz(π/64) ├────────────■───────────────»\n", - "« └──────────┘ »\n", - "« »\n", - "«q_0: ──────────────────────────────────────────────────────────────────────»\n", - "« »\n", - "«q_1: ──────────────────────────────────────────────────────────────────────»\n", - "« ┌───┐┌──────────┐ »\n", - "«q_2: ──────────┤ X ├┤ Rz(π/64) ├───────────────────────────────────────────»\n", - "« ┌───┐└─┬─┘├──────────┤ ┌───┐┌───────────┐ ┌───┐»\n", - "«q_3: ─────┤ X ├──┼──┤ Rz(π/16) ├───────────────┤ X ├┤ Rz(-π/32) ├─────┤ X ├»\n", - "« ┌───┐└─┬─┘ │ ├─────────┬┘ ┌───┐└─┬─┘└┬──────────┤┌───┐└─┬─┘»\n", - "«q_4: ┤ X ├──┼────┼──┤ Rz(π/4) ├───────────┤ X ├──┼───┤ Rz(-π/8) ├┤ X ├──┼──»\n", - "« └─┬─┘ │ │ ├─────────┴┐┌────────┐└─┬─┘ │ └──────────┘└─┬─┘ │ »\n", - "«q_5: ──■────┼────┼──┤ Ry(-π/2) ├┤ Rz(-π) ├──┼────┼─────────────────┼────┼──»\n", - "« │ │ ├─────────┬┘└────────┘ │ │ │ │ »\n", - "«q_6: ───────■────┼──┤ Rz(π/8) ├─────────────■────┼─────────────────■────┼──»\n", - "« │ ├─────────┴┐ │ │ »\n", - "«q_7: ────────────■──┤ Rz(π/32) ├─────────────────■──────────────────────■──»\n", - "« └──────────┘ »\n", - "« »\n", - "«q_0: ────────────────────────────────────────────────────────────────────────»\n", - "« »\n", - "«q_1: ────────────────────────────────────────────────────────────────────────»\n", - "« »\n", - "«q_2: ────────────────────────────────────────────────────────────────────────»\n", - "« ┌──────────┐ »\n", - "«q_3: ┤ Rz(π/32) ├────────────────────────────────────────────────────────────»\n", - "« ├─────────┬┘ ┌───┐┌───────────┐ ┌───┐┌──────────┐ »\n", - "«q_4: ┤ Rz(π/8) ├──────┤ X ├┤ Rz(-π/16) ├─────┤ X ├┤ Rz(π/16) ├───────────────»\n", - "« └─────────┘ ┌───┐└─┬─┘└┬──────────┤┌───┐└─┬─┘├─────────┬┘ ┌───┐»\n", - "«q_5: ────────────┤ X ├──┼───┤ Rz(-π/4) ├┤ X ├──┼──┤ Rz(π/4) ├───────────┤ X ├»\n", - "« ┌─────────┐ └─┬─┘ │ └──────────┘└─┬─┘ │ ├─────────┴┐┌────────┐└─┬─┘»\n", - "«q_6: ┤ Rz(π/4) ├───■────┼─────────────────■────┼──┤ Ry(-π/2) ├┤ Rz(-π) ├──┼──»\n", - "« ├─────────┴┐ │ │ ├─────────┬┘└────────┘ │ »\n", - "«q_7: ┤ Rz(π/16) ├───────■──────────────────────■──┤ Rz(π/8) ├─────────────■──»\n", - "« └──────────┘ └─────────┘ »\n", - "« \n", - "«q_0: ────────────────────────────────────────────────────────────────────────\n", - "« \n", - "«q_1: ────────────────────────────────────────────────────────────────────────\n", - "« \n", - "«q_2: ────────────────────────────────────────────────────────────────────────\n", - "« \n", - "«q_3: ────────────────────────────────────────────────────────────────────────\n", - "« \n", - "«q_4: ────────────────────────────────────────────────────────────────────────\n", - "« ┌──────────┐┌───┐┌─────────┐ \n", - "«q_5: ┤ Rz(-π/8) ├┤ X ├┤ Rz(π/8) ├────────────────────────────────────────────\n", - "« └──────────┘└─┬─┘└─────────┘┌───┐┌──────────┐┌───┐┌─────────┐ \n", - "«q_6: ──────────────┼─────────────┤ X ├┤ Rz(-π/4) ├┤ X ├┤ Rz(π/4) ├───────────\n", - "« │ ┌─────────┐└─┬─┘└──────────┘└─┬─┘├─────────┴┐┌────────┐\n", - "«q_7: ──────────────■──┤ Rz(π/4) ├──■────────────────■──┤ Ry(-π/2) ├┤ Rz(-π) ├\n", - "« └─────────┘ └──────────┘└────────┘\n" - ] - } - ], + "outputs": [], "source": [ "print(ucc_qc)" ] From cee94710e2fc3d7e538cb5a99fef85094ef403c6 Mon Sep 17 00:00:00 2001 From: jordandsullivan Date: Fri, 27 Sep 2024 15:28:51 -0700 Subject: [PATCH 5/5] Remove dupulicate notebooks --- .../custom_compile_heisenberg_ring.ipynb | 242 ------------------ .../custom_compile_qcnn.ipynb | 226 ---------------- .../custom_compile_qft.ipynb | 204 --------------- 3 files changed, 672 deletions(-) delete mode 100644 custom_compiler_experiments/custom_compile_heisenberg_ring.ipynb delete mode 100644 custom_compiler_experiments/custom_compile_qcnn.ipynb delete mode 100644 custom_compiler_experiments/custom_compile_qft.ipynb diff --git a/custom_compiler_experiments/custom_compile_heisenberg_ring.ipynb b/custom_compiler_experiments/custom_compile_heisenberg_ring.ipynb deleted file mode 100644 index 17c50953..00000000 --- a/custom_compiler_experiments/custom_compile_heisenberg_ring.ipynb +++ /dev/null @@ -1,242 +0,0 @@ -{ - "cells": [ - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Evolution under Hamiltonian of Heisenberg interaction in an external field, nearest neighbor line" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "We are choosing a circuit that has a linear connectivity map which is the simplest possible. The implemented circuit uses a lot of single qubit gates to implement spin interaction along the different axes and the goal is to see whether a custom compiler does better at reducing these gates than the default one." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "from qiskit import QuantumCircuit\n", - "\n", - "import time\n", - "import numpy as np" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Define circuit" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "num_qubits = 5\n", - "num_layers = 3\n", - "qc=QuantumCircuit(num_qubits)\n", - "for i_layer in range(num_layers):\n", - " for i in range(num_qubits-1): \n", - " j = (i + 1)\n", - " \n", - " qc.rz(np.random.rand(), i)\n", - " qc.rz(np.random.rand(), j)\n", - " \n", - " qc.cx(i, j)\n", - " qc.rz(0.1, j)\n", - " qc.cx(i, j)\n", - " \n", - " qc.h(i)\n", - " qc.h(j)\n", - " qc.cx(i, j)\n", - " qc.rz(0.1, j)\n", - " qc.cx(i, j)\n", - " qc.h(i)\n", - " qc.h(j)\n", - " \n", - " qc.ry(np.pi/2, i)\n", - " qc.ry(np.pi/2, j)\n", - " qc.cx(i, j)\n", - " qc.rz(0.1, j)\n", - " qc.cx(i, j)\n", - " qc.ry(-np.pi/2, i)\n", - " qc.ry(-np.pi/2, j)\n", - "# Get gate counts\n", - "gate_counts = qc.count_ops()\n", - "print(gate_counts)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Define backend" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "from qiskit.providers.fake_provider import GenericBackendV2\n", - "\n", - "backend = GenericBackendV2(num_qubits=num_qubits, basis_gates = ['rz', 'rx', 'ry', 'cx'])" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Optionally print out the circuit" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# qc.draw()" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Compile with default passes" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "from qiskit.transpiler.preset_passmanagers import generate_preset_pass_manager\n", - "default_pm = generate_preset_pass_manager(backend=backend, optimization_level=3)\n", - "\n", - "t1 = time.time()\n", - "default_qc = default_pm.run(qc)\n", - "t2 = time.time()\n", - "print(\"Time taken: \", t2-t1)\n", - "\n", - "# Get gate counts\n", - "gate_counts = default_qc.count_ops()\n", - "print(gate_counts)\n", - "print(\"Number of 2-qubit gates: \", gate_counts.get(\"cx\", 0)) \n", - "print(\"Number of 1-qubit gates: \", gate_counts.get(\"rx\", 0) + gate_counts.get(\"rz\", 0) + gate_counts.get(\"ry\", 0) + gate_counts.get(\"h\", 0))" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# default_qc.draw()" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "#Test with UCC transpiler\n", - "\n", - "import sys\n", - "sys.path.append('../')\n", - "\n", - "from ucc import compile\n", - "\n", - "t1 = time.time()\n", - "ucc_qc, gate_counts = compile(qc, mode=\"ucc\", get_gate_counts = True)\n", - "t2 = time.time()\n", - "print(\"Time taken: \", t2-t1)\n", - "\n", - "# # Get gate counts\n", - "print(gate_counts)\n", - "print(\"Number of 2-qubit gates: \", gate_counts.get(\"cx\", 0))\n", - "print(\"Number of 1-qubit gates: \", gate_counts.get(\"rz\", 0) + gate_counts.get(\"rx\", 0) + gate_counts.get(\"ry\", 0) + gate_counts.get(\"h\", 0))" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Create custom compiler" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# from qiskit.transpiler import PassManager\n", - "# import qiskit.transpiler.passes as passes \n", - "\n", - "\n", - "# custom_pm = PassManager()\n", - "\n", - "# custom_pm.append(passes.Optimize1qGatesDecomposition())\n", - "\n", - "# custom_pm.append(passes.Collect2qBlocks())\n", - "# custom_pm.append(passes.ConsolidateBlocks())\n", - "\n", - "# # custom_pm.append(passes.Decompose())\n", - "# # custom_pm.append(passes.Optimize1qGates())\n", - "\n", - "# custom_qc = custom_pm.run(qc)\n", - "\n", - "# # Get gate counts\n", - "# gate_counts = custom_qc.count_ops()\n", - "# print(gate_counts)\n", - "\n", - "# # custom_qc.draw()" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# # Get gate counts\n", - "# gate_counts = custom_qc.count_ops()\n", - "# print(gate_counts)\n", - "# print(\"Number of 2-qubit gates: \", gate_counts.get(\"cz\", 0) + gate_counts.get(\"cx\", 0))\n", - "# print(\"Number of 1-qubit gates: \", gate_counts.get(\"sx\", 0) + gate_counts.get(\"rz\", 0) + gate_counts.get(\"x\", 0))\n" - ] - } - ], - "metadata": { - "kernelspec": { - "display_name": "qml", - "language": "python", - "name": "python3" - }, - "language_info": { - "codemirror_mode": { - "name": "ipython", - "version": 3 - }, - "file_extension": ".py", - "mimetype": "text/x-python", - "name": "python", - "nbconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": "3.12.4" - } - }, - "nbformat": 4, - "nbformat_minor": 2 -} diff --git a/custom_compiler_experiments/custom_compile_qcnn.ipynb b/custom_compiler_experiments/custom_compile_qcnn.ipynb deleted file mode 100644 index 10a8ff34..00000000 --- a/custom_compiler_experiments/custom_compile_qcnn.ipynb +++ /dev/null @@ -1,226 +0,0 @@ -{ - "cells": [ - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Quantum Convolutional Neural Network" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "This is a circuit that requires a connectivity map where the distance between the qubits increases exponentially with depth" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "from qiskit import QuantumCircuit\n", - "\n", - "import time\n", - "import numpy as np" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Define QCNN circuit" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "num_qubits = 4\n", - "num_layers = int(np.ceil(np.log2(num_qubits)))\n", - "\n", - "qc=QuantumCircuit(num_qubits)\n", - "i_conv=0\n", - "for i_layer in range(num_layers):\n", - " for i_sub_layer in [0 , 2**i_layer]: \n", - " for i_q1 in range(i_sub_layer, num_qubits, 2**(i_layer+1)):\n", - " i_q2=2**i_layer+i_q1\n", - " if i_q2