Skip to content

Commit

Permalink
Merge pull request #97 from qiboteam/black
Browse files Browse the repository at this point in the history
Change Black maxline
  • Loading branch information
rodolfocarobene authored Dec 21, 2023
2 parents 5d8d246 + e900c74 commit e064f42
Show file tree
Hide file tree
Showing 13 changed files with 191 additions and 44 deletions.
2 changes: 0 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ repos:
rev: 23.12.0
hooks:
- id: black
args:
- --line-length=120
- repo: https://github.com/pycqa/isort
rev: 5.13.2
hooks:
Expand Down
4 changes: 3 additions & 1 deletion src/qibosoq/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ def convert_commands(obj_dictionary: dict) -> dict:
"qubits": [asdict(qubit) for qubit in obj_dictionary["qubits"]],
}
if "sweepers" in obj_dictionary:
dict_dictionary["sweepers"] = [sweep.serialized for sweep in obj_dictionary["sweepers"]]
dict_dictionary["sweepers"] = [
sweep.serialized for sweep in obj_dictionary["sweepers"]
]
return dict_dictionary


Expand Down
13 changes: 10 additions & 3 deletions src/qibosoq/components/pulses.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,10 @@ class Drag(Pulse):
@property
def waveform_name(self) -> Optional[str]:
"""Return waveform name from parameters."""
return f"{self.dac}_drag_{round(self.rel_sigma, 2)}_{round(self.duration, 2)}_{round(self.beta, 2)}"
rel_sigma = round(self.rel_sigma, 2)
duration = round(self.duration, 2)
beta = round(self.beta, 2)
return f"{self.dac}_drag_{rel_sigma}_{duration}_{beta}"


@dataclass
Expand All @@ -97,7 +100,9 @@ class FlatTop(Pulse):
@property
def waveform_name(self) -> Optional[str]:
"""Return waveform name from parameters."""
return f"{self.dac}_flattop_{round(self.rel_sigma, 2)}_{round(self.duration), 2}"
return (
f"{self.dac}_flattop_{round(self.rel_sigma, 2)}_{round(self.duration), 2}"
)

@property
def style(self) -> Optional[str]:
Expand All @@ -118,7 +123,9 @@ def i_values(self, duration: int, max_gain: int):
"""Compute the waveform i values."""
amp = int(self.amplitude * max_gain)
time = np.arange(duration)
i_vals = (np.ones(duration) * np.exp(-time / self.upsilon)) + self.weight * np.exp(-time / self.tau)
i_vals = (
np.ones(duration) * np.exp(-time / self.upsilon)
) + self.weight * np.exp(-time / self.tau)
return amp * i_vals / (1 + self.weight)


Expand Down
4 changes: 3 additions & 1 deletion src/qibosoq/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ def from_env(name, default=None):
PROGRAM_LOGGER_NAME = from_env("PROGRAM_LOGGER_NAME", "qick_program")
"""Program logger name."""

QICKSOC_LOCATION = from_env("BITSTREAM", "/home/xilinx/jupyter_notebooks/qick_111_rfbv1_mux.bit")
QICKSOC_LOCATION = from_env(
"BITSTREAM", "/home/xilinx/jupyter_notebooks/qick_111_rfbv1_mux.bit"
)
"""Path of the qick bitstream to load."""

IS_MULTIPLEXED = from_env("IS_MULTIPLEXED", "True") == "True"
Expand Down
8 changes: 6 additions & 2 deletions src/qibosoq/log.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,13 @@ def configure_logger(name: str, filename: str, backup_count: int):
else:
new_logger = logging
new_logger.setLevel(logging.DEBUG)
formatter = logging.Formatter("%(levelname)s :: %(asctime)s :: %(message)s", "%Y-%m-%d %H:%M:%S")
formatter = logging.Formatter(
"%(levelname)s :: %(asctime)s :: %(message)s", "%Y-%m-%d %H:%M:%S"
)

handler = logging.handlers.RotatingFileHandler(filename, mode="w", backupCount=backup_count, delay=True)
handler = logging.handlers.RotatingFileHandler(
filename, mode="w", backupCount=backup_count, delay=True
)
if os.path.isfile(filename):
handler.doRollover()
handler.setFormatter(formatter)
Expand Down
27 changes: 21 additions & 6 deletions src/qibosoq/programs/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@
class BaseProgram(ABC, QickProgram):
"""Abstract class for QickPrograms."""

def __init__(self, soc: QickSoc, qpcfg: Config, sequence: List[Pulse], qubits: List[Qubit]):
def __init__(
self, soc: QickSoc, qpcfg: Config, sequence: List[Pulse], qubits: List[Qubit]
):
"""In this function we define the most important settings.
In detail:
Expand All @@ -48,7 +50,9 @@ def __init__(self, soc: QickSoc, qpcfg: Config, sequence: List[Pulse], qubits: L

# mux settings
self.is_mux = qibosoq_cfg.IS_MULTIPLEXED
self.readouts_per_experiment = len([pulse for pulse in self.sequence if pulse.type == "readout"])
self.readouts_per_experiment = len(
[pulse for pulse in self.sequence if pulse.type == "readout"]
)

self.relax_delay = self.us2cycles(qpcfg.repetition_duration)
self.syncdelay = self.us2cycles(0)
Expand Down Expand Up @@ -87,7 +91,9 @@ def declare_nqz_zones(self, sequence: List[Pulse]):
def declare_readout_freq(self):
"""Declare ADCs downconversion frequencies."""
adc_ch_already_declared = []
for readout_pulse in (pulse for pulse in self.sequence if pulse.type == "readout"):
for readout_pulse in (
pulse for pulse in self.sequence if pulse.type == "readout"
):
adc_ch = readout_pulse.adc
ro_ch = readout_pulse.dac
if adc_ch not in adc_ch_already_declared:
Expand Down Expand Up @@ -130,7 +136,11 @@ def add_pulse_to_register(self, pulse: Pulse):
sigma = (soc_length / pulse.rel_sigma) * np.sqrt(2)
self.add_gauss(ch=gen_ch, name=name, sigma=sigma, length=soc_length)
elif isinstance(pulse, Drag):
delta = -self.soccfg["gens"][gen_ch]["samps_per_clk"] * self.soccfg["gens"][gen_ch]["f_fabric"] / 2
delta = (
-self.soccfg["gens"][gen_ch]["samps_per_clk"]
* self.soccfg["gens"][gen_ch]["f_fabric"]
/ 2
)
sigma = (soc_length / pulse.rel_sigma) * np.sqrt(2)
self.add_DRAG(
ch=gen_ch,
Expand Down Expand Up @@ -167,7 +177,8 @@ def execute_drive_pulse(self, pulse: Pulse, last_pulse_registered: Dict):
"""
if not self.pulses_registered and (
pulse.dac not in last_pulse_registered or pulse != last_pulse_registered[pulse.dac]
pulse.dac not in last_pulse_registered
or pulse != last_pulse_registered[pulse.dac]
):
self.add_pulse_to_register(pulse)
last_pulse_registered[pulse.dac] = pulse
Expand All @@ -184,7 +195,11 @@ def execute_readout_pulse(
if self.is_mux:
if pulse in muxed_pulses_executed:
return
idx_mux = next(idx for idx, mux_time in enumerate(self.multi_ro_pulses) if pulse in mux_time)
idx_mux = next(
idx
for idx, mux_time in enumerate(self.multi_ro_pulses)
if pulse in mux_time
)
self.add_muxed_readout_to_register(self.multi_ro_pulses[idx_mux])
muxed_ro_executed_indexes.append(idx_mux)
for ro_pulse in self.multi_ro_pulses[idx_mux]:
Expand Down
16 changes: 12 additions & 4 deletions src/qibosoq/programs/flux.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@
class FluxProgram(BaseProgram):
"""Abstract class for flux-tunable qubits programs."""

def __init__(self, soc: QickSoc, qpcfg: Config, sequence: List[Pulse], qubits: List[Qubit]):
def __init__(
self, soc: QickSoc, qpcfg: Config, sequence: List[Pulse], qubits: List[Qubit]
):
"""Define an empty dictionary for bias sweepers and call super().__init__."""
self.bias_sweep_registers: Dict[int, Tuple[QickRegister, QickRegister]] = {}
super().__init__(soc, qpcfg, sequence, qubits)
Expand Down Expand Up @@ -98,7 +100,9 @@ def execute_flux_pulse(self, pulse: Pulse):
i_vals = np.array(pulse.i_values)
logger.info("Arbitrary shaped flux pulse. q_vals will be ignored.")
else:
raise NotImplementedError("Only Rectangular, FluxExponential and Arbitrary are supported for flux pulses")
raise NotImplementedError(
"Only Rectangular, FluxExponential and Arbitrary are supported for flux pulses"
)

# add a clock cycle of sweetspot values
i_vals = np.append(i_vals + sweetspot, np.full(samples_per_clk, sweetspot))
Expand Down Expand Up @@ -155,7 +159,9 @@ def body(self):
elif pulse.type == "flux":
self.execute_flux_pulse(pulse)
elif pulse.type == "readout":
self.execute_readout_pulse(pulse, muxed_pulses_executed, muxed_ro_executed_indexes)
self.execute_readout_pulse(
pulse, muxed_pulses_executed, muxed_ro_executed_indexes
)

self.wait_all()
self.set_bias("zero")
Expand All @@ -171,5 +177,7 @@ def declare_zones_and_ro(self, sequence: List[Pulse]):
if self.is_mux:
self.declare_gen_mux_ro()
else:
self.declare_nqz_zones([pulse for pulse in sequence if pulse.type == "readout"])
self.declare_nqz_zones(
[pulse for pulse in sequence if pulse.type == "readout"]
)
self.declare_readout_freq()
12 changes: 9 additions & 3 deletions src/qibosoq/programs/sweepers.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,17 +52,23 @@ def validate(self, sweeper: Sweeper):
for idx, par in enumerate(sweeper.parameters):
if par is Parameter.BIAS:
if any(pulse.type == "flux" for pulse in self.sequence):
raise NotImplementedError("Sweepers on bias are not compatible with flux pulses.")
raise NotImplementedError(
"Sweepers on bias are not compatible with flux pulses."
)
if any(par is not Parameter.BIAS for par in sweeper.parameters):
raise NotImplementedError("Sweepers on bias cannot be swept at the same time with other sweepers.")
raise NotImplementedError(
"Sweepers on bias cannot be swept at the same time with other sweepers."
)
qubit = self.qubits[sweeper.indexes[idx]]
if qubit.dac is None or qubit.bias is None:
raise ValueError(f"Bias swept qubit had incomplete values: {qubit}")
elif par is Parameter.DURATION:
raise NotImplementedError("Sweepers on duration are not implemented.")
else:
if self.sequence[sweeper.indexes[idx]].type == "flux":
raise NotImplementedError("Sweepers on flux pulses are not implemented.")
raise NotImplementedError(
"Sweepers on flux pulses are not implemented."
)

def add_sweep_info(self, sweeper: Sweeper):
"""Register RfsocSweep objects.
Expand Down
7 changes: 5 additions & 2 deletions src/qibosoq/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,9 @@ def execute_program(data: dict, qick_soc: QickSoc) -> dict:
programcls = ExecuteSweeps
args = load_sweeps(data["sweepers"])
else:
raise NotImplementedError(f"Operation code {data['operation_code']} not supported")
raise NotImplementedError(
f"Operation code {data['operation_code']} not supported"
)

program = programcls(
qick_soc,
Expand All @@ -82,7 +84,8 @@ def execute_program(data: dict, qick_soc: QickSoc) -> dict:
max_mem = qick_soc["tprocs"][0]["pmem_size"]
if num_instructions > max_mem:
raise MemoryError(
f"The tproc has a max memory size of {max_mem}, but the program had {num_instructions} instructions"
f"The tproc has a max memory size of {max_mem}, "
f"but the program had {num_instructions} instructions"
)

if opcode is OperationCode.EXECUTE_PULSE_SEQUENCE_RAW:
Expand Down
4 changes: 3 additions & 1 deletion tests/test_configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,7 @@ def test_configuration_default():
assert cfg.MAIN_LOGGER_NAME == "qibosoq_logger"
assert cfg.PROGRAM_LOGGER_FILE == "/home/xilinx/logs/program.log"
assert cfg.PROGRAM_LOGGER_NAME == "qick_program"
assert cfg.QICKSOC_LOCATION == "/home/xilinx/jupyter_notebooks/qick_111_rfbv1_mux.bit"
assert (
cfg.QICKSOC_LOCATION == "/home/xilinx/jupyter_notebooks/qick_111_rfbv1_mux.bit"
)
assert cfg.IS_MULTIPLEXED is True
12 changes: 9 additions & 3 deletions tests/test_programs_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,15 +282,21 @@ def test_execute_readout_pulse(soc):
muxed_pulse_executed = []
muxed_ro_executed_indexes = []

program.execute_readout_pulse(sequence[0], muxed_pulse_executed, muxed_ro_executed_indexes)
program.execute_readout_pulse(
sequence[0], muxed_pulse_executed, muxed_ro_executed_indexes
)
if program.is_mux:
assert len(muxed_pulse_executed) == 2
assert muxed_ro_executed_indexes == [0]
program.execute_readout_pulse(sequence[1], muxed_pulse_executed, muxed_ro_executed_indexes)
program.execute_readout_pulse(
sequence[1], muxed_pulse_executed, muxed_ro_executed_indexes
)
if program.is_mux:
assert len(muxed_pulse_executed) == 2
assert muxed_ro_executed_indexes == [0]
program.execute_readout_pulse(sequence[2], muxed_pulse_executed, muxed_ro_executed_indexes)
program.execute_readout_pulse(
sequence[2], muxed_pulse_executed, muxed_ro_executed_indexes
)
if program.is_mux:
assert len(muxed_pulse_executed) == 3
assert muxed_ro_executed_indexes == [0, 1]
Expand Down
Loading

0 comments on commit e064f42

Please sign in to comment.