This commit is contained in:
Jonathan Daniel 2021-11-02 13:35:05 +02:00
Родитель 66b0d3494a
Коммит 47276b6102
5 изменённых файлов: 203 добавлений и 0 удалений

Просмотреть файл

@ -0,0 +1,35 @@
from pathlib import Path
import pytest
import qiskit
from qiskit import QuantumCircuit, QuantumRegister, ClassicalRegister, AncillaRegister
from quantum_viz.qiskit_parser import qiskit2json
from quantum_viz.utils import display
def qc_to_path(qc: QuantumCircuit) -> Path:
return Path(__file__).parent / f"resources/{qc.name}.json"
def empty_qc(name="empty_circ") -> QuantumCircuit:
return QuantumCircuit(name=name)
def no_ops_qc(name="no_ops_qc") -> QuantumCircuit:
return QuantumCircuit(4, 3, name=name)
def no_ops_regs_qc(name="no_ops_regs_qc") -> QuantumCircuit:
qreg1 = QuantumRegister(6, "q1")
qreg2 = QuantumRegister(6, "q2")
creg = ClassicalRegister(2, "c")
areg = AncillaRegister(4, "aux")
return QuantumCircuit(qreg1, qreg2, creg, areg, name=name)
def test_generate_results() -> None:
for qc in [empty_qc(), no_ops_qc(), no_ops_regs_qc()]:
display(qc)
qc_to_path(qc).write_text(qiskit2json(qc))

Просмотреть файл

@ -0,0 +1,9 @@
{
"qubits": [],
"operations": [
{
"gate": "empty_circ",
"targets": []
}
]
}

Просмотреть файл

@ -0,0 +1,35 @@
{
"qubits": [
{
"id": 0
},
{
"id": 1
},
{
"id": 2
},
{
"id": 3
}
],
"operations": [
{
"gate": "no_ops_qc",
"targets": [
{
"qId": 0
},
{
"qId": 1
},
{
"qId": 2
},
{
"qId": 3
}
]
}
]
}

Просмотреть файл

@ -0,0 +1,107 @@
{
"qubits": [
{
"id": 0
},
{
"id": 1
},
{
"id": 2
},
{
"id": 3
},
{
"id": 4
},
{
"id": 5
},
{
"id": 6
},
{
"id": 7
},
{
"id": 8
},
{
"id": 9
},
{
"id": 10
},
{
"id": 11
},
{
"id": 12
},
{
"id": 13
},
{
"id": 14
},
{
"id": 15
}
],
"operations": [
{
"gate": "no_ops_regs_qc",
"targets": [
{
"qId": 0
},
{
"qId": 1
},
{
"qId": 2
},
{
"qId": 3
},
{
"qId": 4
},
{
"qId": 5
},
{
"qId": 6
},
{
"qId": 7
},
{
"qId": 8
},
{
"qId": 9
},
{
"qId": 10
},
{
"qId": 11
},
{
"qId": 12
},
{
"qId": 13
},
{
"qId": 14
},
{
"qId": 15
}
]
}
]
}

Просмотреть файл

@ -0,0 +1,17 @@
from pathlib import Path
import json
import pytest
from conftest import * # noqa: F403
from quantum_viz.qiskit_parser import qiskit2dict
def _get_saved_dict(qc) -> str:
with open(qc_to_path(qc)) as fp:
return json.load(fp)
@pytest.mark.parametrize("qc", [empty_qc(), no_ops_qc(), no_ops_regs_qc()])
def test_qviz_dict(qc):
assert qiskit2dict(qc) == _get_saved_dict(qc)