Skip to content

Commit

Permalink
tmp: add debug script for #121
Browse files Browse the repository at this point in the history
  • Loading branch information
airwoodix committed Jan 24, 2024
1 parent aaf3bc3 commit ea17708
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .github/workflows/poetry.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ jobs:
if: startsWith(matrix.os, 'ubuntu')
- name: Run examples (windows)
run: |
poetry run python examples/quickstart-sampler.py
poetry run python examples/debug_121.py
if: startsWith(matrix.os, 'windows')
continue-on-error: true
- name: Install all dependencies
Expand Down
53 changes: 53 additions & 0 deletions examples/debug_121.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
from typing import Any, Union

from qiskit import QuantumCircuit
from qiskit.circuit.library import Measure, RGate, RXXGate
from qiskit.circuit.parameter import Parameter
from qiskit.primitives import BackendSampler
from qiskit.providers import BackendV2, Options
from qiskit.transpiler import Target
from qiskit_aer import AerJob, AerProvider


class Backend(BackendV2):
def __init__(self) -> None:
super().__init__(name="dummy")

@property
def target(self) -> Target:
theta = Parameter("theta")
phi = Parameter("phi")

target = Target(num_qubits=10)
target.add_instruction(RGate(theta, phi))
target.add_instruction(RXXGate(theta))
target.add_instruction(Measure())
return target

@property
def max_circuits(self) -> int:
return 100

@classmethod
def _default_options(cls) -> Options:
return Options()

def run(self, circuits: Union[QuantumCircuit, list[QuantumCircuit]], **options: Any) -> AerJob:
circuit, *_ = circuits
print("RXX", circuit.get_instructions("rxx"))
print("CX", circuit.get_instructions("cx"))
sim = AerProvider().get_backend("aer_simulator")
return sim.run(circuits, **options)


if __name__ == "__main__":
qc = QuantumCircuit(2)
qc.h(0)
qc.cx(0, 1)
qc.measure_all()

backend = Backend()
sampler = BackendSampler(backend)

result = sampler.run(qc).result()
print(result.quasi_dists[0])

0 comments on commit ea17708

Please sign in to comment.