Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Now testing for appropriate context when configuring beambeam #17

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions tests/test_hllhc14.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from pathlib import Path
from itertools import product

import pytest
import numpy as np
import pandas as pd
from scipy.constants import c as clight
Expand All @@ -12,7 +13,7 @@
import xtrack as xt
import xfields as xf
import xpart as xp

import xobjects as xo
import xmask as xm
import xmask.lhc as xmlhc

Expand Down Expand Up @@ -278,12 +279,20 @@ def test_hllhc14_3_level_ip2_ip8():
def test_hllhc14_4_bb_config():

collider = xt.Multiline.from_json('collider_hllhc14_03.json')
collider.build_trackers()


# Ensure that a non-CPU context raise a ValueError when configuring beam-beam
with pytest.raises(ValueError) as error_info:
collider.build_trackers(_context = xo.ContextPyopencl())
collider.configure_beambeam_interactions(
num_particles=2.2e11,
nemitt_x=2e-6, nemitt_y=3e-6)
assert "The trackers need to be built on CPU" in str(error_info)
collider.discard_trackers()

collider.build_trackers(_context = xo.ContextCpu())
collider.configure_beambeam_interactions(
num_particles=2.2e11,
nemitt_x=2e-6, nemitt_y=3e-6)

collider.to_json('collider_hllhc14_04.json')

ip_bb_config= {
Expand Down
14 changes: 12 additions & 2 deletions tests/test_hllhc14_b1_only.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import yaml
from pathlib import Path
from itertools import product
import pytest

import numpy as np
import pandas as pd

from cpymad.madx import Madx
import xtrack as xt
import xfields as xf

import xobjects as xo
import xmask as xm
import xmask.lhc as xmlhc

Expand Down Expand Up @@ -176,8 +177,17 @@ def test_hllhc14_b1_only_2_tuning():
def test_hllhc14_b1_only_3_bb_config():

collider = xt.Multiline.from_json('collider_hllhc14_b1_only_02.json')
collider.build_trackers()

# Ensure that a non-CPU context raise a ValueError when configuring beam-beam
with pytest.raises(ValueError) as error_info:
collider.build_trackers(_context = xo.ContextPyopencl())
collider.configure_beambeam_interactions(
num_particles=2.2e11,
nemitt_x=2e-6, nemitt_y=3e-6)
assert "The trackers need to be built on CPU" in str(error_info)
collider.discard_trackers()

collider.build_trackers(_context = xo.ContextCpu())
collider.configure_beambeam_interactions(
num_particles=2.2e11,
nemitt_x=2e-6, nemitt_y=3e-6,
Expand Down