-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #20 from yasuhito/feature/ouqu-tp-support
add ouqu-tp support
- Loading branch information
Showing
24 changed files
with
693 additions
and
135 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
name: Setup Staq | ||
description: Install Staq quantum compiler | ||
|
||
runs: | ||
using: composite | ||
steps: | ||
- name: Install dependencies | ||
run: | | ||
sudo apt-get update && sudo apt-get install -y --no-install-recommends \ | ||
build-essential \ | ||
cmake \ | ||
git \ | ||
bison \ | ||
flex \ | ||
libboost-all-dev | ||
shell: bash | ||
|
||
- name: Build and install Staq | ||
run: | | ||
cd /tmp | ||
git clone https://github.com/softwareQinc/staq.git | ||
cd staq | ||
mkdir build | ||
cd build | ||
cmake .. | ||
make -j8 | ||
sudo make install | ||
shell: bash |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
src/tranqu/device_converter/oqtopus_to_ouqu_tp_device_converter.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import json | ||
from typing import Any | ||
|
||
from .device_converter import DeviceConverter | ||
|
||
|
||
class OqtopusToOuquTpDeviceConverter(DeviceConverter): | ||
"""Device converter for converting from Oqtopus to ouqu-tp format.""" | ||
|
||
@staticmethod | ||
def convert(device: dict[str, Any]) -> str: | ||
"""Convert a Oqtopus device to ouqu-tp format. | ||
Args: | ||
device (dict[str, Any]): The Oqtopus device to be converted. | ||
Returns: | ||
str: The converted ouqu-tp format device. | ||
""" | ||
return json.dumps(device) |
89 changes: 89 additions & 0 deletions
89
src/tranqu/device_converter/qiskit_to_ouqu_tp_device_converter.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
import json | ||
from typing import Any, ClassVar | ||
|
||
from qiskit.providers import BackendV2 # type: ignore[import-untyped] | ||
from qiskit.transpiler import InstructionProperties # type: ignore[import-untyped] | ||
|
||
from .device_converter import DeviceConverter | ||
|
||
|
||
class QiskitToOuquTpDeviceConverter(DeviceConverter): | ||
"""Device converter for converting from Qiskit to ouqu-tp format.""" | ||
|
||
_SINGLE_QUBIT_GATES: ClassVar[list[str]] = ["x", "sx", "rz"] | ||
_TWO_QUBIT_GATE = "cx" | ||
_NANO_SECONDS = 1e9 | ||
|
||
def convert(self, device: BackendV2) -> str: | ||
"""Convert a Qiskit device to ouqu-tp format. | ||
Args: | ||
device (BackendV2): The Qiskit device to be converted. | ||
Returns: | ||
str: The converted ouqu-tp format device. | ||
""" | ||
ouqu_tp_device = { | ||
"name": device.name, | ||
"qubits": self._convert_qubits(device), | ||
"couplings": self._convert_couplings(device), | ||
} | ||
|
||
return json.dumps(ouqu_tp_device) | ||
|
||
def _convert_qubits(self, device: BackendV2) -> list[dict[str, Any]]: | ||
qubits = [] | ||
target = device.target | ||
|
||
for qubit in range(device.num_qubits): | ||
qubit_info = {"id": qubit, "gate_duration": {}, "fidelity": None} | ||
|
||
for gate_name in self._SINGLE_QUBIT_GATES: | ||
if target.instruction_supported(gate_name, (qubit,)): | ||
props = target[gate_name][qubit,] | ||
if props: | ||
self._update_properties(qubit_info, props, gate_name) | ||
|
||
qubits.append(qubit_info) | ||
|
||
return qubits | ||
|
||
def _convert_couplings(self, device: BackendV2) -> list[dict[str, Any]]: | ||
couplings = [] | ||
target = device.target | ||
coupling_map = device.coupling_map | ||
|
||
if coupling_map: | ||
for control, target_qubit in coupling_map: | ||
coupling_info = { | ||
"control": control, | ||
"target": target_qubit, | ||
"gate_duration": {}, | ||
"fidelity": None, | ||
} | ||
|
||
qargs = (control, target_qubit) | ||
if target.instruction_supported(self._TWO_QUBIT_GATE, qargs): | ||
props = target[self._TWO_QUBIT_GATE][qargs] | ||
if props: | ||
self._update_properties( | ||
coupling_info, | ||
props, | ||
self._TWO_QUBIT_GATE, | ||
) | ||
|
||
couplings.append(coupling_info) | ||
|
||
return couplings | ||
|
||
def _update_properties( | ||
self, | ||
info: dict[str, Any], | ||
props: InstructionProperties, | ||
gate_name: str, | ||
) -> None: | ||
if props.duration is not None: | ||
info["gate_duration"][gate_name] = props.duration * self._NANO_SECONDS | ||
if props.error is not None: | ||
info["fidelity"] = 1 - props.error |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
src/tranqu/program_converter/openqasm3_to_ouqu_tp_program_converter.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from .pass_through_program_converter import PassThroughProgramConverter | ||
|
||
Openqasm3ToOuquTpProgramConverter = PassThroughProgramConverter |
3 changes: 3 additions & 0 deletions
3
src/tranqu/program_converter/ouqu_tp_to_openqasm3_program_converter.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from .pass_through_program_converter import PassThroughProgramConverter | ||
|
||
OuquTpToOpenqasm3ProgramConverter = PassThroughProgramConverter |
3 changes: 3 additions & 0 deletions
3
src/tranqu/program_converter/ouqu_tp_to_qiskit_program_converter.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from .openqasm3_to_qiskit_program_converter import Openqasm3ToQiskitProgramConverter | ||
|
||
OuquTpToQiskitProgramConverter = Openqasm3ToQiskitProgramConverter |
3 changes: 3 additions & 0 deletions
3
src/tranqu/program_converter/qiskit_to_ouqu_tp_program_converter.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from .qiskit_to_openqasm3_program_converter import QiskitToOpenqasm3ProgramConverter | ||
|
||
QiskitToOuquTpProgramConverter = QiskitToOpenqasm3ProgramConverter |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.