예제 #1
0
파일: test_ceres.py 프로젝트: BQSKit/bqskit
def test_minimize_ceres() -> None:
    circ = Circuit(1)
    circ.append_gate(RXGate(), location=[0], params=[0.0])
    xgate = XGate()
    xutry = xgate.get_unitary()
    cost = HilbertSchmidtResidualsGenerator().gen_cost(
        circ, UnitaryMatrix(-1j * xutry.get_numpy()),
    )
    minimizer = CeresMinimizer()
    x = minimizer.minimize(cost, np.array([np.pi / 2]))
    assert cost.get_cost(x) < 1e-6, x
예제 #2
0
from __future__ import annotations

from bqskit.compiler.passes.greedypartitioner import GreedyPartitioner
from bqskit.ir import Circuit
from bqskit.ir.gates.constant.cx import CNOTGate

num_q = 5
coup_map = {(0, 1), (1, 2), (2, 3), (3, 4)}
circ = Circuit(num_q)
circ.append_gate(CNOTGate(), [0, 1])
circ.append_gate(CNOTGate(), [3, 4])
circ.append_gate(CNOTGate(), [1, 2])
circ.append_gate(CNOTGate(), [0, 1])
circ.append_gate(CNOTGate(), [2, 3])
circ.append_gate(CNOTGate(), [1, 2])
circ.append_gate(CNOTGate(), [2, 3])
circ.append_gate(CNOTGate(), [3, 2])
circ.append_gate(CNOTGate(), [2, 1])
part = GreedyPartitioner()

print('Num Cycles Before:', circ.get_num_cycles())
print('Num Ops Before:', circ.get_num_operations())

data = {'multi_gate_score': 1, 'single_gate_score': 1}
part.run(circ, data)

# for point, op in circ.operations_with_points():
#     print(op, point)

print('Num Cycles After:', circ.get_num_cycles())
print('Num Ops After:', circ.get_num_operations())
예제 #3
0
 def test_one_gate_4(self) -> None:
     circuit = Circuit(3)
     circuit.append_gate(CNOTGate(), (1, 2))
     ops = [op for op in CircuitIterator(circuit)]
     assert len(ops) == 1
     assert ops[0].gate == CNOTGate()  # type: ignore
예제 #4
0
 def test_one_gate_1(self) -> None:
     circuit = Circuit(1)
     circuit.append_gate(HGate(), 0)
     ops = [op for op in CircuitIterator(circuit)]
     assert len(ops) == 1
     assert ops[0].gate == HGate()  # type: ignore
예제 #5
0
 def test_empty(self) -> None:
     circuit = Circuit(1)
     ops = [op for op in CircuitIterator(circuit)]
     assert len(ops) == 0
예제 #6
0
from numpy import pi

from bqskit.compiler.passes.partitioning.scan import ScanPartitioner
from bqskit.compiler.passes.synthesis import LEAPSynthesisPass
from bqskit.compiler.passes.util.variabletou3 import VariableToU3Pass
from bqskit.compiler.search.generators.simple import SimpleLayerGenerator
from bqskit.ir import Circuit
from bqskit.ir.gates import CNOTGate
from bqskit.ir.gates.parameterized.u3 import U3Gate
from bqskit.ir.gates.parameterized.unitary import VariableUnitaryGate

# Enable logging
logging.getLogger('bqskit.compiler').setLevel(logging.DEBUG)

circuit = Circuit(3)
circuit.append_gate(U3Gate(), [0], [pi, pi / 2, pi / 2])
circuit.append_gate(U3Gate(), [1], [pi, pi / 2, pi / 2])
circuit.append_gate(CNOTGate(), [0, 1])
circuit.append_gate(U3Gate(), [2], [pi, pi / 2, pi / 2])
circuit.append_gate(U3Gate(), [0], [pi, pi / 2, pi / 2])
instantiate_options = {
    'min_iters': 0,
    'diff_tol_r': 1e-5,
    'dist_tol': 1e-11,
    'max_iters': 2500,
}
layer_generator = SimpleLayerGenerator(
    single_qudit_gate_1=VariableUnitaryGate(1),
)
synthesizer = LEAPSynthesisPass(