예제 #1
0
import numpy as np
import pytest
from c3.c3objs import Quantity
from c3.libraries.envelopes import envelopes
from c3.signal.gates import Instruction
from c3.signal.pulse import Envelope, Carrier
from c3.system.model import Model
from c3.generator.generator import Generator
from c3.parametermap import ParameterMap
from c3.experiment import Experiment as Exp

model = Model()
model.read_config("test/test_model.cfg")
gen = Generator()
gen.read_config("test/generator.cfg")
pmap = ParameterMap(model=model, generator=gen)
pmap.read_config("test/instructions.cfg")


@pytest.mark.unit
def test_subsystems() -> None:
    assert list(
        model.subsystems.keys()) == ['Q1', 'Q2', 'Q3', 'Q4', 'Q5', 'Q6']


@pytest.mark.unit
def test_couplings() -> None:
    assert list(model.couplings.keys()) == ['Q1-Q2', 'Q4-Q6', 'd1', 'd2']


@pytest.mark.unit
예제 #2
0
    def quick_setup(self, filepath: str) -> None:
        """
        Load a quick setup file and create all necessary components.

        Parameters
        ----------
        filepath : str
            Location of the configuration file

        """
        with open(filepath, "r") as cfg_file:
            cfg = hjson.loads(cfg_file.read())

        model = Model()
        model.read_config(cfg["model"])
        gen = Generator()
        gen.read_config(cfg["generator"])

        single_gate_time = cfg["single_qubit_gate_time"]
        v2hz = cfg["v2hz"]
        instructions = []
        sideband = cfg.pop("sideband", None)
        for gate_name, props in cfg["single_qubit_gates"].items():
            target_qubit = model.subsystems[props["target_qubit"]]
            instr = Instruction(
                name=gate_name,
                t_start=0.0,
                t_end=single_gate_time,
                channels=[target_qubit.drive_line],
            )
            instr.quick_setup(
                target_qubit.drive_line,
                target_qubit.params["freq"].get_value() / 2 / np.pi,
                single_gate_time,
                v2hz,
                sideband,
            )
            instructions.append(instr)

        for gate_name, props in cfg["two_qubit_gates"].items():
            qubit_1 = model.subsystems[props["qubit_1"]]
            qubit_2 = model.subsystems[props["qubit_2"]]
            instr = Instruction(
                name=gate_name,
                t_start=0.0,
                t_end=props["gate_time"],
                channels=[qubit_1.drive_line, qubit_2.drive_line],
            )
            instr.quick_setup(
                qubit_1.drive_line,
                qubit_1.params["freq"].get_value() / 2 / np.pi,
                props["gate_time"],
                v2hz,
                sideband,
            )
            instr.quick_setup(
                qubit_2.drive_line,
                qubit_2.params["freq"].get_value() / 2 / np.pi,
                props["gate_time"],
                v2hz,
                sideband,
            )
            instructions.append(instr)

        self.pmap = ParameterMap(instructions, generator=gen, model=model)
예제 #3
0
파일: main.py 프로젝트: superplay1/c3
    opt_config = args.master_config
    with open(opt_config, "r") as cfg_file:
        try:
            cfg = hjson.loads(cfg_file.read())
        except hjson.decoder.HjsonDecodeError:
            raise Exception(f"Config {opt_config} is invalid.")

    optim_type = cfg["optim_type"]

    tf_utils.tf_setup()
    with tf.device("/CPU:0"):
        model = None
        gen = None
        if "model" in cfg:
            model = Model()
            model.read_config(cfg["model"])
        if "generator" in cfg:
            gen = Generator()
            gen.read_config(cfg["generator"])
        if "instructions" in cfg:
            pmap = ParameterMap(model=model, generator=gen)
            pmap.read_config(cfg["instructions"])
            exp = Experiment(pmap)
        else:
            print(
                "C3:STATUS: No instructions specified. Performing quick setup."
            )
            exp = Experiment()
            exp.quick_setup(opt_config)

        if optim_type == "C1":