-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
54 additions
and
1 deletion.
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
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]) |